Snai3i-MarketPlace / backend / src / controllers / meeting.controller.ts
meeting.controller.ts
Raw
import { Response } from 'express';
import { MyRequest } from '../types/Express';
import { ErrorResponse, SuccessResponse } from '../utils/Response';
import { MeetingServices } from '../services/meeting/meeting.service';
import {
  ErrorResponseC,
  SuccessResponseC,
} from '../services/services.response';

export const GetMeetingById = async (req: MyRequest<UserI>, res: Response) => {
  const { meeting_id } = req.params;
  const result = await MeetingServices.getMeeting(parseInt(meeting_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 GetMeetings = async (req: MyRequest<UserI>, res: Response) => {
  const result = await MeetingServices.getMeetings();
  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 GetMeetingsByStatus = async (
  req: MyRequest<UserI>,
  res: Response
) => {
  const { status } = req.params;
  const result = await MeetingServices.getMeetingsByStatus(status);
  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 CreateMeeting = async (req: MyRequest<UserI>, res: Response) => {
  const { fullName, phone, email, cause, course_id, pack_id } = req.body;
  const result = await MeetingServices.createMeeting(
    fullName,
    phone,
    email,
    cause,
    'pending',
    course_id,
    pack_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 DeleteMeeting = async (req: MyRequest<UserI>, res: Response) => {
  const { meeting_id } = req.params;
  const result = await MeetingServices.deleteMeeting(parseInt(meeting_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 UpdateMeetingStatus = async (
  req: MyRequest<UserI>,
  res: Response
) => {
  const { meeting_id } = req.params;
  const { status } = req.body;
  const result = await MeetingServices.updateMeetingStatus(
    parseInt(meeting_id),
    status
  );
  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);
};