@7365admin1/module-hygiene 3.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1051,12 +1051,12 @@ function useAreaService() {
1051
1051
  skippedRows.push(i + 1);
1052
1052
  continue;
1053
1053
  }
1054
- if (!row?.NAME) {
1055
- logger5.warn(`Skipping row ${i + 1} with missing NAME:`, row);
1054
+ if (!row?.AREA) {
1055
+ logger5.warn(`Skipping row ${i + 1} with missing AREA:`, row);
1056
1056
  skippedRows.push(i + 1);
1057
1057
  continue;
1058
1058
  }
1059
- const areaName = String(row.NAME).trim();
1059
+ const areaName = String(row.AREA).trim();
1060
1060
  if (!areaName) {
1061
1061
  logger5.warn(`Skipping row ${i + 1} with empty ${areaType} area name`);
1062
1062
  skippedRows.push(i + 1);
@@ -1595,12 +1595,12 @@ function useUnitService() {
1595
1595
  try {
1596
1596
  for (let i = 0; i < dataArray.length; i++) {
1597
1597
  const row = dataArray[i];
1598
- if (!row?.NAME) {
1599
- logger9.warn(`Skipping row ${i + 1} with missing NAME:`, row);
1598
+ if (!row?.UNIT) {
1599
+ logger9.warn(`Skipping row ${i + 1} with missing UNIT:`, row);
1600
1600
  skippedRows.push(i + 1);
1601
1601
  continue;
1602
1602
  }
1603
- const unitName = String(row.NAME).trim();
1603
+ const unitName = String(row.UNIT).trim();
1604
1604
  if (!unitName) {
1605
1605
  logger9.warn(`Skipping row ${i + 1} with empty unit name`);
1606
1606
  skippedRows.push(i + 1);
@@ -2273,7 +2273,8 @@ var areaChecklistSchema = Joi8.object({
2273
2273
  }).required()
2274
2274
  ).min(1).required()
2275
2275
  }).required()
2276
- ).optional().default([])
2276
+ ).optional().default([]),
2277
+ createdBy: Joi8.string().hex().required()
2277
2278
  });
2278
2279
  function MAreaChecklist(value) {
2279
2280
  const { error } = areaChecklistSchema.validate(value);
@@ -2310,6 +2311,13 @@ function MAreaChecklist(value) {
2310
2311
  };
2311
2312
  });
2312
2313
  }
2314
+ if (value.createdBy) {
2315
+ try {
2316
+ value.createdBy = new ObjectId8(value.createdBy);
2317
+ } catch (error2) {
2318
+ throw new BadRequestError14("Invalid createdBy ID format.");
2319
+ }
2320
+ }
2313
2321
  return {
2314
2322
  schedule: value.schedule,
2315
2323
  area: value.area,
@@ -2317,6 +2325,7 @@ function MAreaChecklist(value) {
2317
2325
  type: value.type,
2318
2326
  checklist: value.checklist || [],
2319
2327
  status: "ready",
2328
+ createdBy: value.createdBy,
2320
2329
  createdAt: /* @__PURE__ */ new Date(),
2321
2330
  completedAt: "",
2322
2331
  updatedAt: ""
@@ -2455,6 +2464,32 @@ function useAreaChecklistRepo() {
2455
2464
  try {
2456
2465
  const pipeline = [
2457
2466
  { $match: query },
2467
+ {
2468
+ $lookup: {
2469
+ from: "users",
2470
+ let: { createdById: "$createdBy" },
2471
+ pipeline: [
2472
+ {
2473
+ $match: {
2474
+ $expr: {
2475
+ $and: [
2476
+ { $ne: ["$$createdById", ""] },
2477
+ { $eq: ["$_id", "$$createdById"] }
2478
+ ]
2479
+ }
2480
+ }
2481
+ },
2482
+ { $project: { name: 1 } }
2483
+ ],
2484
+ as: "createdByDoc"
2485
+ }
2486
+ },
2487
+ {
2488
+ $unwind: {
2489
+ path: "$createdByDoc",
2490
+ preserveNullAndEmptyArrays: true
2491
+ }
2492
+ },
2458
2493
  {
2459
2494
  $project: {
2460
2495
  name: 1,
@@ -2486,7 +2521,8 @@ function useAreaChecklistRepo() {
2486
2521
  },
2487
2522
  else: 0
2488
2523
  }
2489
- }
2524
+ },
2525
+ createdByName: "$createdByDoc.name"
2490
2526
  }
2491
2527
  },
2492
2528
  { $sort: { _id: -1 } },
@@ -3119,7 +3155,8 @@ function useAreaChecklistService() {
3119
3155
  unit: unit.unit.toString(),
3120
3156
  name: unit.name
3121
3157
  }))
3122
- }))
3158
+ })),
3159
+ createdBy: value.createdBy
3123
3160
  };
3124
3161
  const insertedId = await _createAreaChecklist(
3125
3162
  checklistData,
@@ -3254,13 +3291,20 @@ function useAreaChecklistController() {
3254
3291
  completeAreaChecklistUnits: _completeAreaChecklistUnits
3255
3292
  } = useAreaChecklistService();
3256
3293
  async function createAreaChecklist(req, res, next) {
3294
+ const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
3295
+ (acc, [key, value2]) => ({ ...acc, [key]: value2 }),
3296
+ {}
3297
+ ) : {};
3298
+ const createdBy = cookies["user"] || "";
3257
3299
  const payload = {
3258
3300
  site: req.params.site,
3259
- schedule: req.params.schedule
3301
+ schedule: req.params.schedule,
3302
+ createdBy
3260
3303
  };
3261
3304
  const validation = Joi9.object({
3262
3305
  site: Joi9.string().hex().required(),
3263
- schedule: Joi9.string().hex().required()
3306
+ schedule: Joi9.string().hex().required(),
3307
+ createdBy: Joi9.string().hex().required()
3264
3308
  });
3265
3309
  const { error, value } = validation.validate(payload);
3266
3310
  if (error) {
@@ -4805,7 +4849,8 @@ var scheduleTaskSchema = Joi16.object({
4805
4849
  name: Joi16.string().required(),
4806
4850
  value: Joi16.any().required()
4807
4851
  })
4808
- ).required()
4852
+ ).required(),
4853
+ createdBy: Joi16.string().hex().required()
4809
4854
  });
4810
4855
  function MScheduleTask(value) {
4811
4856
  const { error } = scheduleTaskSchema.validate(value);
@@ -4832,6 +4877,13 @@ function MScheduleTask(value) {
4832
4877
  }
4833
4878
  });
4834
4879
  }
4880
+ if (value.createdBy) {
4881
+ try {
4882
+ value.createdBy = new ObjectId16(value.createdBy);
4883
+ } catch (error2) {
4884
+ throw new BadRequestError28("Invalid createdBy ID format.");
4885
+ }
4886
+ }
4835
4887
  return {
4836
4888
  site: value.site,
4837
4889
  title: value.title,
@@ -4841,6 +4893,7 @@ function MScheduleTask(value) {
4841
4893
  description: value.description,
4842
4894
  areas: value.areas,
4843
4895
  status: "active",
4896
+ createdBy: value.createdBy,
4844
4897
  createdAt: /* @__PURE__ */ new Date(),
4845
4898
  updatedAt: "",
4846
4899
  deletedAt: ""
@@ -5139,7 +5192,7 @@ function useScheduleTaskRepository() {
5139
5192
  import { logger as logger29 } from "@7365admin1/node-server-utils";
5140
5193
  function useScheduleTaskService() {
5141
5194
  const { createParentChecklist } = useParentChecklistRepo();
5142
- const { getAllScheduleTask, getScheduleTaskById } = useScheduleTaskRepository();
5195
+ const { getAllScheduleTask } = useScheduleTaskRepository();
5143
5196
  const {
5144
5197
  createAreaChecklist,
5145
5198
  getAreaChecklistByAreaAndSchedule,
@@ -5337,7 +5390,8 @@ function useScheduleTaskService() {
5337
5390
  set: 1,
5338
5391
  units
5339
5392
  }
5340
- ]
5393
+ ],
5394
+ createdBy: scheduleTask.createdBy
5341
5395
  };
5342
5396
  logger29.info(
5343
5397
  `Area ${area.name} (${areaId}): Creating new area checklist with data: ${JSON.stringify(
@@ -5410,7 +5464,12 @@ function useScheduleTaskController() {
5410
5464
  updateScheduleTask: _updateScheduleTask
5411
5465
  } = useScheduleTaskRepository();
5412
5466
  async function createScheduleTask(req, res, next) {
5413
- const payload = { ...req.body, ...req.params };
5467
+ const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
5468
+ (acc, [key, value]) => ({ ...acc, [key]: value }),
5469
+ {}
5470
+ ) : {};
5471
+ const createdBy = cookies["user"] || "";
5472
+ const payload = { ...req.body, ...req.params, createdBy };
5414
5473
  const { error } = scheduleTaskSchema.validate(payload);
5415
5474
  if (error) {
5416
5475
  logger30.log({ level: "error", message: error.message });