"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResultsController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const prisma_service_1 = require("../prisma/prisma.service");
const envelope_1 = require("../../common/envelope");
const roles_decorator_1 = require("../../common/decorators/roles.decorator");
const roles_1 = require("../../common/roles");
let ResultsController = class ResultsController {
    constructor(prisma) {
        this.prisma = prisma;
    }
    async my(req) {
        const userId = req.user.userId;
        const quizzes = await this.prisma.quizAttempt.findMany({ where: { userId, status: { in: ['SUBMITTED', 'GRADED'] } }, include: { quiz: true }, orderBy: { createdAt: 'desc' } });
        const exams = await this.prisma.examAttempt.findMany({ where: { userId, status: { in: ['SUBMITTED', 'GRADED'] } }, include: { exam: true }, orderBy: { createdAt: 'desc' } });
        return (0, envelope_1.ok)({ quizzes, exams });
    }
    async staffView(courseId) {
        const whereQuiz = {};
        const whereExam = {};
        if (courseId) {
            whereQuiz.quiz = { module: { courseId } };
            whereExam.exam = { courseId };
        }
        const quizzes = await this.prisma.quizAttempt.findMany({ where: whereQuiz, include: { user: { select: { id: true, fullName: true, matricNumber: true } }, quiz: true } });
        const exams = await this.prisma.examAttempt.findMany({ where: whereExam, include: { user: { select: { id: true, fullName: true, matricNumber: true } }, exam: true } });
        return (0, envelope_1.ok)({ quizzes, exams });
    }
};
exports.ResultsController = ResultsController;
__decorate([
    (0, common_1.Get)('results/my'),
    __param(0, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], ResultsController.prototype, "my", null);
__decorate([
    (0, roles_decorator_1.Roles)(roles_1.UserRole.ADMIN, roles_1.UserRole.STAFF),
    (0, common_1.Get)('staff/results'),
    __param(0, (0, common_1.Query)('courseId')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], ResultsController.prototype, "staffView", null);
exports.ResultsController = ResultsController = __decorate([
    (0, swagger_1.ApiTags)('Results'),
    (0, swagger_1.ApiBearerAuth)(),
    (0, common_1.Controller)(),
    __metadata("design:paramtypes", [prisma_service_1.PrismaService])
], ResultsController);
//# sourceMappingURL=results.controller.js.map