import { ApiValidationError } from "../../Models/Server.Error.model"; import { Body, Controller, Middlewares, Post, Response, Route, SuccessResponse } from "tsoa"; import { authenticateMiddleware } from "../../middleware/authentication"; import { AppointmentAdminByClientView, AppointmentAdminByDateView, CreateAppointmentParams, CreateImmediateAppointmentNotificationJobsParams, AppointmentNotificationPreviewParams, AppointmentNotificationPreviewResult, DeleteAppointmentParams, FindAppointmentsParams, FindAppointmentSchedulesParams, IAppointment, UpdateAppointmentParams, MoveAppointmentParams, ChangeServiceParams, FindAppointmentsByUserParams, FindAppointmentsByCollaboratorParams, SendAppointmentNotificationParams, GetAppointmentEventParams, AppointmentEventByClient, ApplyAppointmentDiscountParams, DeleteAppointmentDiscountParams, SendWapSystemNotificationParams, GetAvailableDatesParams, GetAvailableDatesResult, FindAppointmentsByUserPaginatedParams, FindAppointmentsByCollaboratorPaginatedParams, PaginatedAppointmentEventByClientResult, } from "../../Models/Appointments/Appointments.Interface"; import { AppointmentService } from "./Appointments.Service"; import { ApiVoidResult } from "../../Models/Api.VoidResult.type"; import { TextObjectFilterResult } from "../../Models/TextObjectFilter.model"; import { rateLimiter } from "../../middleware/ratelimiter"; import { systemTokenMiddleware } from "../../middleware/systemToken"; @Route("appointments/create") @Middlewares(authenticateMiddleware) export class CreateAppointmentController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "El empleado fue creado con exito") @Post() public async createAppointment( @Body() requestBody: CreateAppointmentParams ): Promise { try { const client = await new AppointmentService().createAppointment(requestBody); this.setStatus(200); return client; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/update") @Middlewares(authenticateMiddleware) export class UpdateAppointmentController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "El empleado fue creado con exito") @Post() public async updateAppointment( @Body() requestBody: UpdateAppointmentParams ): Promise { try { await new AppointmentService().updateAppointment(requestBody); this.setStatus(200); return { message: "Done", success: true, }; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/delete") @Middlewares(authenticateMiddleware) export class DeleteAppointmentController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "El turno fue cancelado con exito") @Post() public async deleteAppointment( @Body() requestBody: DeleteAppointmentParams ): Promise { try { await new AppointmentService().deleteAppointment(requestBody); this.setStatus(200); return { message: "Done", success: true, }; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/find-admin-by-date") @Middlewares(authenticateMiddleware) export class FindAppointmentAdminByDateController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "El empleado fue creado con exito") @Post() public async findAppointmentAdminByDate( @Body() requestBody: FindAppointmentsParams ): Promise { try { const appointments = await new AppointmentService().findAppointmentsAdminByDate( requestBody ); this.setStatus(200); return appointments; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/get-event") @Middlewares(authenticateMiddleware) export class GetAppointmentEventController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "Done") @Post() public async getAppointmentEvent( @Body() requestBody: GetAppointmentEventParams ): Promise { try { const appointment = await new AppointmentService().getAppointmentEvent(requestBody); this.setStatus(200); return appointment; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/find-admin-by-client") @Middlewares(authenticateMiddleware) export class FindAppointmentAdminByClientController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "El empleado fue creado con exito") @Post() public async findAppointmentAdminByClient( @Body() requestBody: FindAppointmentsParams ): Promise { try { const appointments = await new AppointmentService().findAppointmentsAdminByClient( requestBody ); this.setStatus(200); return appointments; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/find-by-user") @Middlewares(authenticateMiddleware) export class FindAppointmentByUserController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "El empleado fue creado con exito") @Post() public async findAppointmentByUser( @Body() requestBody: FindAppointmentsByUserParams ): Promise { try { const appointments = await new AppointmentService().findAppointmentsByUser(requestBody); this.setStatus(200); return appointments; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/find-by-collaborator") @Middlewares(authenticateMiddleware) export class FindAppointmentByCollaboratorController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "Busqueda completada con exito") @Post() public async findAppointmentByCollaborator( @Body() requestBody: FindAppointmentsByCollaboratorParams ): Promise { try { const appointments = await new AppointmentService().findAppointmentsByCollaborator(requestBody); this.setStatus(200); return appointments; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/find-by-user-paginated") @Middlewares(authenticateMiddleware) export class FindAppointmentByUserPaginatedController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "Busqueda completada con exito") @Post() public async findAppointmentByUserPaginated( @Body() requestBody: FindAppointmentsByUserPaginatedParams ): Promise { try { const appointments = await new AppointmentService().findAppointmentsByUserPaginated(requestBody); this.setStatus(200); return appointments; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/find-by-collaborator-paginated") @Middlewares(authenticateMiddleware) export class FindAppointmentByCollaboratorPaginatedController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "Busqueda completada con exito") @Post() public async findAppointmentByCollaboratorPaginated( @Body() requestBody: FindAppointmentsByCollaboratorPaginatedParams ): Promise { try { const appointments = await new AppointmentService().findAppointmentsByCollaboratorPaginated(requestBody); this.setStatus(200); return appointments; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/get-schedules") export class GetSchedulesController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "Done") @Post() public async findSchedules( @Body() requestBody: FindAppointmentSchedulesParams ): Promise { try { const schedules = await new AppointmentService().getSchedules(requestBody); this.setStatus(200); return schedules; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/send-wap-notification") @Middlewares(rateLimiter) export class SendWapNotificationContrnoller extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "Done") @Post() public async findSchedules( @Body() requestBody: SendAppointmentNotificationParams ): Promise { try { await new AppointmentService().sendWapNotification(requestBody); this.setStatus(200); return { message: "Done", success: true, }; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/send-wap-sys-notification") @Middlewares(systemTokenMiddleware) export class SendWapSystemNotificationContrnoller extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "Done") @Post() public async sendWapSystemNtofication( @Body() requestBody: SendWapSystemNotificationParams ): Promise { try { await new AppointmentService().sendWapSystemNotification(requestBody); this.setStatus(200); return { message: "Done", success: true, }; } catch (e) { return { message: `${e}`, success: false, }; } } } @Route("appointments/send-email-notification") @Middlewares([rateLimiter, systemTokenMiddleware]) export class SendEmailNotificationContrnoller extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "Done") @Post() public async findSchedules( @Body() requestBody: SendAppointmentNotificationParams ): Promise { try { await new AppointmentService().sendEmailNotification(requestBody); this.setStatus(200); return { message: "Done", success: true, }; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/create-immediate-notification-jobs") @Middlewares(authenticateMiddleware) export class CreateImmediateAppointmentNotificationJobsController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "Done") @Post() public async createImmediateNotificationJobs( @Body() requestBody: CreateImmediateAppointmentNotificationJobsParams ): Promise { try { await new AppointmentService().createImmediateNotificationJobs(requestBody); this.setStatus(200); return { message: "Done", success: true, }; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/notification-preview") @Middlewares(authenticateMiddleware) export class AppointmentNotificationPreviewController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "Done") @Post() public async getAppointmentNotificationPreview( @Body() requestBody: AppointmentNotificationPreviewParams ): Promise { try { const preview = await new AppointmentService().getAppointmentNotificationPreview(requestBody); this.setStatus(200); return preview; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/apply-discount") @Middlewares(authenticateMiddleware) export class ApplyAppointmentDiscountContrnoller extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "Done") @Post() public async applyAppointmentDiscount( @Body() requestBody: ApplyAppointmentDiscountParams ): Promise { try { await new AppointmentService().applyDiscount(requestBody); this.setStatus(200); return { message: "Done", success: true, }; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/delete-discount") @Middlewares(authenticateMiddleware) export class DeleteAppointmentDiscountContrnoller extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "Done") @Post() public async deleteAppointmentDiscount( @Body() requestBody: DeleteAppointmentDiscountParams ): Promise { try { await new AppointmentService().deleteDiscount(requestBody); this.setStatus(200); return { message: "Done", success: true, }; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/get-available-dates") export class GetAvailableDatesController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "Done") @Post() public async getAvailableDates( @Body() requestBody: GetAvailableDatesParams ): Promise { try { const schedules = await new AppointmentService().getAvailableDates(requestBody); this.setStatus(200); return schedules; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/move-appointment-force") @Middlewares(authenticateMiddleware) export class MoveAppointmentForceController extends Controller { @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "El turno fue movido con exito") @Post() public async moveAppointmentForce( @Body() requestBody: MoveAppointmentParams ): Promise { try { await new AppointmentService().moveAppointmentForce(requestBody); this.setStatus(200); return { message: "Done", success: true, }; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } } @Route("appointments/change-service-force") @Middlewares(authenticateMiddleware) export class ChangeServiceForceController extends Controller { /** * @summary Permite cambiar el servicio de un turno sin validar horarios (force). */ @Response(500, "Ha ocurrido un error") @SuccessResponse(200, "El servicio del turno fue cambiado con exito") @Post() public async changeServiceForce( @Body() requestBody: ChangeServiceParams ): Promise { try { await new AppointmentService().changeServiceForce(requestBody); this.setStatus(200); return { message: "Done", success: true, }; } catch (e) { const errorOccurred: Error = e as Error; console.error("GET EVENT ERROR:", errorOccurred); this.setStatus(500); return new ApiValidationError(500, errorOccurred.message); } } }