util.ts 424 B

12345678910111213141516171819
  1. const responseBody = {
  2. message: '',
  3. timestamp: 0,
  4. result: null as unknown,
  5. code: 0,
  6. }
  7. export function builder(data: unknown, message = 'success', code = 0) {
  8. responseBody.result = data
  9. if (message !== undefined && message !== null)
  10. responseBody.message = message
  11. if (code !== undefined && code !== 0)
  12. responseBody.code = code
  13. responseBody.timestamp = new Date().getTime()
  14. return responseBody
  15. }