Manual Reference Source

app/modules/utils/web.js

  1. // @flow
  2. const ODM = require('../entities/crud/odm');
  3.  
  4. /**
  5. * Forge a standard response when returning HTTP 200 for any request
  6. * @param model - Model of an entity with access to CRUD messages
  7. * @param name - Name of the entity
  8. * @param method - HTTP method (POST, PUT, GET, DELETE)
  9. * @returns JSON
  10. */
  11. function forge_ok_response(object: Object, method: string): Object {
  12. switch (method) {
  13. default:
  14. case 'post':
  15. return {
  16. message: object.messages.set,
  17. change: `${method.toUpperCase()}_${object.name}`,
  18. entity: object,
  19. };
  20. case 'put':
  21. return {
  22. message: object.messages.modify,
  23. change: `${method.toUpperCase()}_${object.name}`,
  24. entity: object,
  25. };
  26. case 'delete':
  27. return {
  28. message: object.messages.remove,
  29. change: `${method.toUpperCase()}_${object.name}`,
  30. };
  31. }
  32. }
  33.  
  34. exports.forge_ok_response = forge_ok_response;