HospitalCollection.js 1003 B

123456789101112131415161718192021222324252627
  1. const { ListResponse } = require("../../../utils/ListResponse");
  2. const { formatISOWithoutTimezone } = require("../../../utils/FormatDate.js");
  3. const { getUserNameById } = require("../../../utils/CheckUserKeycloak.js");
  4. // Fungsi transform per item
  5. const transformHospitalList = async (data = []) => {
  6. return Promise.all(data.map(async ({ created_by, ...rest }) => {
  7. const name = await getUserNameById(created_by);
  8. return {
  9. ...rest,
  10. user: {
  11. id: created_by,
  12. name: name
  13. },
  14. createdAt: formatISOWithoutTimezone(rest.createdAt),
  15. updatedAt: formatISOWithoutTimezone(rest.updatedAt)
  16. };
  17. }));
  18. };
  19. // Collection yang async
  20. exports.HospitalCollection = async ({ req, res, data = [], total = 0, page = 1, limit = 10, message = 'Success' }) => {
  21. const formatted = await transformHospitalList(data);
  22. return ListResponse({ req, res, data: formatted, total, page, limit, message });
  23. };