@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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @7365admin1/module-hygiene
2
2
 
3
+ ## 4.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added `createdBy` field to the schedule task model and cleaning schedule area checklist model, and included it in the projected fields in the area checklist repository.
8
+
9
+ ## 4.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - Change import logic to expect AREA instead of NAME in area import, and UNIT instead of NAME in unit import (breaking change to Excel import format).
14
+
3
15
  ## 3.0.0
4
16
 
5
17
  ### Major Changes
package/dist/index.d.ts CHANGED
@@ -205,6 +205,7 @@ type TCleaningScheduleArea = {
205
205
  type: (typeof allowedTypes)[number];
206
206
  checklist: TAreaChecklist[];
207
207
  status?: (typeof allowedStatus)[number];
208
+ createdBy?: string | ObjectId;
208
209
  createdAt?: Date | string;
209
210
  completedAt?: Date | string;
210
211
  updatedAt?: Date | string;
@@ -224,7 +225,7 @@ type TAreaChecklistUnits = {
224
225
  type TAreaChecklistCreate = Pick<TCleaningScheduleArea, "schedule" | "area"> & {
225
226
  site: string | ObjectId;
226
227
  };
227
- type TAreaChecklistBatchCreate = Pick<TCleaningScheduleArea, "schedule"> & {
228
+ type TAreaChecklistBatchCreate = Pick<TCleaningScheduleArea, "schedule" | "createdBy"> & {
228
229
  site: string | ObjectId;
229
230
  };
230
231
  type TCleaningScheduleAreaGetQuery = {
@@ -244,6 +245,7 @@ declare function MAreaChecklist(value: TCleaningScheduleArea): {
244
245
  type: string;
245
246
  checklist: TAreaChecklist[];
246
247
  status: string;
248
+ createdBy: string | ObjectId | undefined;
247
249
  createdAt: Date;
248
250
  completedAt: string;
249
251
  updatedAt: string;
@@ -475,17 +477,18 @@ type TScheduleTask = {
475
477
  value: ObjectId;
476
478
  }[];
477
479
  status?: "active" | "deleted";
480
+ createdBy: string | ObjectId;
478
481
  createdAt?: string | Date;
479
482
  updatedAt?: string | Date;
480
483
  deletedAt?: string | Date;
481
484
  };
482
- type TScheduleTaskCreate = Pick<TScheduleTask, "site" | "title" | "time" | "startDate" | "endDate" | "description" | "areas">;
485
+ type TScheduleTaskCreate = Pick<TScheduleTask, "site" | "title" | "time" | "startDate" | "endDate" | "description" | "areas" | "createdBy">;
483
486
  type TScheduleTaskGetQuery = {
484
487
  page?: number;
485
488
  limit?: number;
486
489
  search?: string;
487
490
  } & Pick<TScheduleTask, "site">;
488
- type TScheduleTaskGetById = Pick<TScheduleTask, "title" | "time" | "startDate" | "endDate" | "description" | "areas" | "status" | "createdAt">;
491
+ type TScheduleTaskGetById = Pick<TScheduleTask, "title" | "time" | "startDate" | "endDate" | "description" | "areas" | "status" | "createdBy" | "createdAt">;
489
492
  type TScheduleTaskUpdate = Partial<Pick<TScheduleTask, "title" | "time" | "startDate" | "endDate" | "description" | "areas">>;
490
493
  declare const scheduleTaskSchema: Joi.ObjectSchema<any>;
491
494
  declare function MScheduleTask(value: TScheduleTaskCreate): {
@@ -500,6 +503,7 @@ declare function MScheduleTask(value: TScheduleTaskCreate): {
500
503
  value: ObjectId;
501
504
  }[];
502
505
  status: string;
506
+ createdBy: string | ObjectId;
503
507
  createdAt: Date;
504
508
  updatedAt: string;
505
509
  deletedAt: string;
package/dist/index.js CHANGED
@@ -1111,12 +1111,12 @@ function useAreaService() {
1111
1111
  skippedRows.push(i + 1);
1112
1112
  continue;
1113
1113
  }
1114
- if (!row?.NAME) {
1115
- import_node_server_utils5.logger.warn(`Skipping row ${i + 1} with missing NAME:`, row);
1114
+ if (!row?.AREA) {
1115
+ import_node_server_utils5.logger.warn(`Skipping row ${i + 1} with missing AREA:`, row);
1116
1116
  skippedRows.push(i + 1);
1117
1117
  continue;
1118
1118
  }
1119
- const areaName = String(row.NAME).trim();
1119
+ const areaName = String(row.AREA).trim();
1120
1120
  if (!areaName) {
1121
1121
  import_node_server_utils5.logger.warn(`Skipping row ${i + 1} with empty ${areaType} area name`);
1122
1122
  skippedRows.push(i + 1);
@@ -1642,12 +1642,12 @@ function useUnitService() {
1642
1642
  try {
1643
1643
  for (let i = 0; i < dataArray.length; i++) {
1644
1644
  const row = dataArray[i];
1645
- if (!row?.NAME) {
1646
- import_node_server_utils9.logger.warn(`Skipping row ${i + 1} with missing NAME:`, row);
1645
+ if (!row?.UNIT) {
1646
+ import_node_server_utils9.logger.warn(`Skipping row ${i + 1} with missing UNIT:`, row);
1647
1647
  skippedRows.push(i + 1);
1648
1648
  continue;
1649
1649
  }
1650
- const unitName = String(row.NAME).trim();
1650
+ const unitName = String(row.UNIT).trim();
1651
1651
  if (!unitName) {
1652
1652
  import_node_server_utils9.logger.warn(`Skipping row ${i + 1} with empty unit name`);
1653
1653
  skippedRows.push(i + 1);
@@ -2312,7 +2312,8 @@ var areaChecklistSchema = import_joi8.default.object({
2312
2312
  }).required()
2313
2313
  ).min(1).required()
2314
2314
  }).required()
2315
- ).optional().default([])
2315
+ ).optional().default([]),
2316
+ createdBy: import_joi8.default.string().hex().required()
2316
2317
  });
2317
2318
  function MAreaChecklist(value) {
2318
2319
  const { error } = areaChecklistSchema.validate(value);
@@ -2349,6 +2350,13 @@ function MAreaChecklist(value) {
2349
2350
  };
2350
2351
  });
2351
2352
  }
2353
+ if (value.createdBy) {
2354
+ try {
2355
+ value.createdBy = new import_mongodb8.ObjectId(value.createdBy);
2356
+ } catch (error2) {
2357
+ throw new import_node_server_utils14.BadRequestError("Invalid createdBy ID format.");
2358
+ }
2359
+ }
2352
2360
  return {
2353
2361
  schedule: value.schedule,
2354
2362
  area: value.area,
@@ -2356,6 +2364,7 @@ function MAreaChecklist(value) {
2356
2364
  type: value.type,
2357
2365
  checklist: value.checklist || [],
2358
2366
  status: "ready",
2367
+ createdBy: value.createdBy,
2359
2368
  createdAt: /* @__PURE__ */ new Date(),
2360
2369
  completedAt: "",
2361
2370
  updatedAt: ""
@@ -2486,6 +2495,32 @@ function useAreaChecklistRepo() {
2486
2495
  try {
2487
2496
  const pipeline = [
2488
2497
  { $match: query },
2498
+ {
2499
+ $lookup: {
2500
+ from: "users",
2501
+ let: { createdById: "$createdBy" },
2502
+ pipeline: [
2503
+ {
2504
+ $match: {
2505
+ $expr: {
2506
+ $and: [
2507
+ { $ne: ["$$createdById", ""] },
2508
+ { $eq: ["$_id", "$$createdById"] }
2509
+ ]
2510
+ }
2511
+ }
2512
+ },
2513
+ { $project: { name: 1 } }
2514
+ ],
2515
+ as: "createdByDoc"
2516
+ }
2517
+ },
2518
+ {
2519
+ $unwind: {
2520
+ path: "$createdByDoc",
2521
+ preserveNullAndEmptyArrays: true
2522
+ }
2523
+ },
2489
2524
  {
2490
2525
  $project: {
2491
2526
  name: 1,
@@ -2517,7 +2552,8 @@ function useAreaChecklistRepo() {
2517
2552
  },
2518
2553
  else: 0
2519
2554
  }
2520
- }
2555
+ },
2556
+ createdByName: "$createdByDoc.name"
2521
2557
  }
2522
2558
  },
2523
2559
  { $sort: { _id: -1 } },
@@ -3150,7 +3186,8 @@ function useAreaChecklistService() {
3150
3186
  unit: unit.unit.toString(),
3151
3187
  name: unit.name
3152
3188
  }))
3153
- }))
3189
+ })),
3190
+ createdBy: value.createdBy
3154
3191
  };
3155
3192
  const insertedId = await _createAreaChecklist(
3156
3193
  checklistData,
@@ -3285,13 +3322,20 @@ function useAreaChecklistController() {
3285
3322
  completeAreaChecklistUnits: _completeAreaChecklistUnits
3286
3323
  } = useAreaChecklistService();
3287
3324
  async function createAreaChecklist(req, res, next) {
3325
+ const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
3326
+ (acc, [key, value2]) => ({ ...acc, [key]: value2 }),
3327
+ {}
3328
+ ) : {};
3329
+ const createdBy = cookies["user"] || "";
3288
3330
  const payload = {
3289
3331
  site: req.params.site,
3290
- schedule: req.params.schedule
3332
+ schedule: req.params.schedule,
3333
+ createdBy
3291
3334
  };
3292
3335
  const validation = import_joi9.default.object({
3293
3336
  site: import_joi9.default.string().hex().required(),
3294
- schedule: import_joi9.default.string().hex().required()
3337
+ schedule: import_joi9.default.string().hex().required(),
3338
+ createdBy: import_joi9.default.string().hex().required()
3295
3339
  });
3296
3340
  const { error, value } = validation.validate(payload);
3297
3341
  if (error) {
@@ -4806,7 +4850,8 @@ var scheduleTaskSchema = import_joi16.default.object({
4806
4850
  name: import_joi16.default.string().required(),
4807
4851
  value: import_joi16.default.any().required()
4808
4852
  })
4809
- ).required()
4853
+ ).required(),
4854
+ createdBy: import_joi16.default.string().hex().required()
4810
4855
  });
4811
4856
  function MScheduleTask(value) {
4812
4857
  const { error } = scheduleTaskSchema.validate(value);
@@ -4833,6 +4878,13 @@ function MScheduleTask(value) {
4833
4878
  }
4834
4879
  });
4835
4880
  }
4881
+ if (value.createdBy) {
4882
+ try {
4883
+ value.createdBy = new import_mongodb16.ObjectId(value.createdBy);
4884
+ } catch (error2) {
4885
+ throw new import_node_server_utils29.BadRequestError("Invalid createdBy ID format.");
4886
+ }
4887
+ }
4836
4888
  return {
4837
4889
  site: value.site,
4838
4890
  title: value.title,
@@ -4842,6 +4894,7 @@ function MScheduleTask(value) {
4842
4894
  description: value.description,
4843
4895
  areas: value.areas,
4844
4896
  status: "active",
4897
+ createdBy: value.createdBy,
4845
4898
  createdAt: /* @__PURE__ */ new Date(),
4846
4899
  updatedAt: "",
4847
4900
  deletedAt: ""
@@ -5131,7 +5184,7 @@ function useScheduleTaskRepository() {
5131
5184
  var import_node_server_utils31 = require("@7365admin1/node-server-utils");
5132
5185
  function useScheduleTaskService() {
5133
5186
  const { createParentChecklist } = useParentChecklistRepo();
5134
- const { getAllScheduleTask, getScheduleTaskById } = useScheduleTaskRepository();
5187
+ const { getAllScheduleTask } = useScheduleTaskRepository();
5135
5188
  const {
5136
5189
  createAreaChecklist,
5137
5190
  getAreaChecklistByAreaAndSchedule,
@@ -5329,7 +5382,8 @@ function useScheduleTaskService() {
5329
5382
  set: 1,
5330
5383
  units
5331
5384
  }
5332
- ]
5385
+ ],
5386
+ createdBy: scheduleTask.createdBy
5333
5387
  };
5334
5388
  import_node_server_utils31.logger.info(
5335
5389
  `Area ${area.name} (${areaId}): Creating new area checklist with data: ${JSON.stringify(
@@ -5402,7 +5456,12 @@ function useScheduleTaskController() {
5402
5456
  updateScheduleTask: _updateScheduleTask
5403
5457
  } = useScheduleTaskRepository();
5404
5458
  async function createScheduleTask(req, res, next) {
5405
- const payload = { ...req.body, ...req.params };
5459
+ const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
5460
+ (acc, [key, value]) => ({ ...acc, [key]: value }),
5461
+ {}
5462
+ ) : {};
5463
+ const createdBy = cookies["user"] || "";
5464
+ const payload = { ...req.body, ...req.params, createdBy };
5406
5465
  const { error } = scheduleTaskSchema.validate(payload);
5407
5466
  if (error) {
5408
5467
  import_node_server_utils32.logger.log({ level: "error", message: error.message });