Snai3i-LandingPage-FormBuilder / backend / src / routes / formRoutes.ts
formRoutes.ts
Raw
import { Router } from 'express';
import {
  createForm,
  deleteForm,
  deleteForms,
  getAllForms,
  getForm,
  updateForm,
} from '../controllers/formController';
import {
  createResponse,
  exportFormResponses,
  getAllResponses,
} from '../controllers/formResponseController';
import { protect } from '../middlewares/authMiddleware';
import {
  Schemas,
  ValidateBodySchema,
  ValidateQuerySchema,
} from '../middlewares/validateSchemaMiddleware';
import {
  createRegisterFormId,
  getAllRegisterFormIds,
  getRegisterForm,
  updateRegisterFormId,
} from '../controllers/registerFormIdsController';

const formRouter = Router();

formRouter
  .route('/')
  .get(protect, ValidateQuerySchema(Schemas.form.getAll), getAllForms)
  .post(protect, ValidateBodySchema(Schemas.form.create), createForm);

formRouter.patch(
  '/bulk-delete',
  ValidateBodySchema(Schemas.form.bulk_delete),
  protect,
  deleteForms
);

formRouter
  .route('/register-fid')
  .post(protect, createRegisterFormId)
  .get(protect, getAllRegisterFormIds)
  .patch(protect, updateRegisterFormId);

formRouter.route('/register-form/:name').get(getRegisterForm);

formRouter
  .route('/:id')
  .get(getForm)
  .patch(protect, ValidateBodySchema(Schemas.form.update), updateForm)
  .delete(protect, deleteForm);

formRouter
  .route('/:id/response')
  .get(protect, getAllResponses)
  .post(ValidateBodySchema(Schemas.formResponse.create), createResponse);

formRouter.post('/:id/export', protect, exportFormResponses);

export default formRouter;