import {Controller} from "@/core/controller/main.controller"; import OnlineCaseService from "../service/online-case.service"; import {ServerResponse} from "@/common/types"; import {NextFunction} from "express"; import { createOnlineCaseValidationSchema, createOnlineCaseWithFormValidationSchema, } from "../validation"; class OnlineCaseControllerClass extends Controller { #service; constructor() { super(); this.#service = OnlineCaseService; } async getAllOnlineCases(req: any, res: ServerResponse, next: NextFunction) { try { const data = await this.#service.getAllOnlineCases(req,res); return res.status(200).json({ status: 200, data: {...data}, message: "Ok", }); } catch (error) { next(error); } } async getSingleOnlineCase(req: any, res: ServerResponse, next: NextFunction) { try { const data = await this.#service.getSingleOnlineCase(req); return res.status(200).json({ status: 200, data: {...data}, message: "Ok", }); } catch (error) { next(error); } } async createOnlineCaseWithForm( req: any, res: ServerResponse, next: NextFunction ) { try { const userId = req.params?.id await createOnlineCaseWithFormValidationSchema.validateAsync( req.body || {}, { abortEarly: true, stripUnknown: true, } ); await this.#service.createOnlineCaseWithForm(req.body || {},userId); return res.status(200).json({ status: 200, data: {}, message: "با موفقیت ایجاد شد", }); } catch (error) { next(error); } } async createOnlineCase(req: any, res: ServerResponse, next: NextFunction) { try { const patientId = req?.params?.id; await createOnlineCaseValidationSchema.validateAsync(req.body || {}, { abortEarly: true, stripUnknown: true, }); await this.#service.createOnlineCase(req.body, patientId); return res.status(200).json({ status: 200, data: {}, message: "با موفقیت ایجاد شد", }); } catch (error) { next(error); } } async updateOnlineCase(req: any, res: ServerResponse, next: NextFunction) { try { const caseId = req?.params?.id; await createOnlineCaseValidationSchema.validateAsync(req.body || {}, { abortEarly: true, stripUnknown: true, }); await this.#service.updateOnlineCase(req.body, caseId); return res.status(200).json({ status: 200, data: {}, message: "با موفقیت ویرایش شد", }); } catch (error) { next(error); } } } const OnlineCaseController = new OnlineCaseControllerClass(); export default OnlineCaseController;