Auspicious14's picture
Upload 94 files
77610ec verified
Raw
History Blame Contribute Delete
2.86 kB
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSubmissionReview = exports.analyzeCode = void 0;
const client_1 = __importDefault(require("../../prisma/client"));
const gemini_1 = require("../../utils/gemini");
const axios_1 = __importDefault(require("axios"));
const analyzeCode = async (req, res) => {
var _a;
const userId = (_a = req.user) === null || _a === void 0 ? void 0 : _a.id;
const { repoUrl, projectId } = req.body;
try {
// 1. Fetch code from GitHub (simplified: fetch README or a few files for demo)
// In a real app, you'd use a GitHub App or User Token to clone or fetch via API
const repoPath = repoUrl.replace("https://github.com/", "");
const [owner, repo] = repoPath.split("/");
// Fetch repo info as a placeholder for analysis
const githubApiUrl = `https://api.github.com/repos/${owner}/${repo}`;
const repoInfo = await axios_1.default.get(githubApiUrl);
// 2. Automated analysis (simulated)
const metrics = {
complexity: "Medium",
securityIssues: 0,
lintErrors: 0
};
// 3. AI-powered feedback
const prompt = `Please review this GitHub repository: ${repoUrl}.
Owner: ${owner}
Repo: ${repo}
Description: ${repoInfo.data.description}
Provide constructive feedback on the project structure and suggest improvements for a student.`;
const feedback = await (0, gemini_1.getGeminiResponse)(prompt);
// 4. Store review results
const submission = await client_1.default.submission.create({
data: {
userId,
projectId,
repoUrl,
feedback,
score: 85 // Simulated score
}
});
res.json({ success: true, data: submission });
}
catch (error) {
res.status(500).json({ success: false, message: error.message });
}
};
exports.analyzeCode = analyzeCode;
const getSubmissionReview = async (req, res) => {
const { id } = req.params;
try {
const submission = await client_1.default.submission.findUnique({
where: { id },
include: {
project: { select: { title: true } },
user: { select: { firstName: true, lastName: true } }
}
});
if (!submission)
return res.status(404).json({ success: false, message: "Submission not found" });
res.json({ success: true, data: submission });
}
catch (error) {
res.status(500).json({ success: false, message: error.message });
}
};
exports.getSubmissionReview = getSubmissionReview;