import { Response } from 'express';
import { MyRequest } from '../types/Express';
import { ErrorResponse, SuccessResponse } from '../utils/Response';
import { EnrollmentServices } from '../services/enrollment/enrollment.service';
import {
ErrorResponseC,
SuccessResponseC,
} from '../services/services.response';
export const AssignTeacherToCourse = async (
req: MyRequest<UserI>,
res: Response
) => {
const { course_id, teacher_id, school_id } = req.body;
const result = await EnrollmentServices.assignTeacherToCourse(
course_id,
teacher_id,
school_id
);
if (result instanceof SuccessResponseC)
return SuccessResponse(
res,
result.code,
result.data,
result.message,
result.status
);
if (result instanceof ErrorResponseC)
return ErrorResponse(res, result.code, result.message, result.error);
};
export const DeleteEnrollment = async (
req: MyRequest<UserI>,
res: Response
) => {
const { course_id, teacher_id } = req.body;
const result = await EnrollmentServices.deleteEnrollment(
teacher_id,
course_id
);
if (result instanceof SuccessResponseC)
return SuccessResponse(
res,
result.code,
result.data,
result.message,
result.status
);
if (result instanceof ErrorResponseC)
return ErrorResponse(res, result.code, result.message, result.error);
};
export const DeleteEnrollmentById = async (
req: MyRequest<UserI>,
res: Response
) => {
const { enrollment_id } = req.params;
const result = await EnrollmentServices.deleteEnrollmentById(
Number(enrollment_id)
);
if (result instanceof SuccessResponseC)
return SuccessResponse(
res,
result.code,
result.data,
result.message,
result.status
);
if (result instanceof ErrorResponseC)
return ErrorResponse(res, result.code, result.message, result.error);
};
export const GetEnrollments = async (req: MyRequest<UserI>, res: Response) => {
const result = await EnrollmentServices.getEnrollments();
if (result instanceof SuccessResponseC)
return SuccessResponse(
res,
result.code,
result.data,
result.message,
result.status
);
if (result instanceof ErrorResponseC)
return ErrorResponse(res, result.code, result.message, result.error);
};
export const getAssignedTeachersByCourseAndSchool = async (
req: MyRequest<UserI>,
res: Response
) => {
const { course_id, school_id } = req.params;
const result = await EnrollmentServices.getAssignedTeachersByCourseAndSchool(
parseInt(course_id),
parseInt(school_id)
);
if (result instanceof SuccessResponseC)
return SuccessResponse(
res,
result.code,
result.data,
result.message,
result.status
);
if (result instanceof ErrorResponseC)
return ErrorResponse(res, result.code, result.message, result.error);
};