ExecutivesHistoryController.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const executivesHistoryService = require('../../services/admin/ExecutivesHistoryService.js');
  2. const { ListResponse } = require('../../utils/ListResponse.js');
  3. const { PaginationParam } = require('../../utils/PaginationParams.js');
  4. const { errorResponse, successResponse, messageSuccessResponse } = require('../../utils/Response.js');
  5. const { validateStoreExecutivesHistoryRequest } = require('../../validators/sales/executives_history/ExecutivesHistoriValidators.js');
  6. exports.getAllExecutivesHistory = async (req, res) => {
  7. try {
  8. const { page, limit, search, sortBy, orderBy } = PaginationParam(req);
  9. const { vendor_histories, total } = await executivesHistoryService.getAllExecutivesHistoryService({
  10. page, limit, search, sortBy, orderBy
  11. }, req);
  12. return ListResponse({ req, res, data: vendor_histories, page, limit, total, message: 'Executives history successfully retrieved' });
  13. } catch (err) {
  14. return errorResponse(res, err);
  15. }
  16. };
  17. exports.showExecutivesHistory = async (req, res) => {
  18. try {
  19. const data = await executivesHistoryService.showExecutivesHistoryService(req);
  20. return successResponse(res, data, 'Success show executives history');
  21. } catch (err) {
  22. return errorResponse(res, err);
  23. }
  24. };
  25. exports.storeExecutivesHistory = async (req, res) => {
  26. try {
  27. const validatedData = validateStoreExecutivesHistoryRequest(req.body);
  28. await executivesHistoryService.storeExecutivesHistoryService(validatedData, req);
  29. return messageSuccessResponse(res, 'Success added executives history', 201);
  30. } catch (err) {
  31. return errorResponse(res, err);
  32. }
  33. }
  34. exports.updateExecutivesHistory = async (req, res) => {
  35. try {
  36. const validatedData = validateStoreExecutivesHistoryRequest(req.body);
  37. await executivesHistoryService.updateExecutivesHistoryService(validatedData, req);
  38. return messageSuccessResponse(res, 'Success update executives history');
  39. } catch (err) {
  40. return errorResponse(res, err);
  41. }
  42. }
  43. exports.deleteExecutivesHistory = async (req, res) => {
  44. try {
  45. await executivesHistoryService.deleteExecutivesHistoryService(req);
  46. return messageSuccessResponse(res, 'Success delete executives history');
  47. } catch (err) {
  48. return errorResponse(res, err);
  49. }
  50. };