@7365admin1/core 3.27.0 → 3.28.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
@@ -48017,7 +48017,8 @@ function UseAccessManagementRepo() {
48017
48017
  remarks: 1,
48018
48018
  requestDate: 1,
48019
48019
  createdAt: 1,
48020
- updatedAt: 1
48020
+ updatedAt: 1,
48021
+ userCred: 1
48021
48022
  }
48022
48023
  }
48023
48024
  );
@@ -48313,7 +48314,7 @@ function UseAccessManagementRepo() {
48313
48314
  const unitId = new ObjectId97(params.unitId);
48314
48315
  const quantity = params.quantity;
48315
48316
  const type = params.type;
48316
- const visitorId = new ObjectId97(params.visitorId);
48317
+ const visitorId = new ObjectId97(params.user?.visitorId);
48317
48318
  const nfcCards = params.nfcCards;
48318
48319
  const acm_url = params.acm_url;
48319
48320
  let cards = [];
@@ -48360,7 +48361,10 @@ function UseAccessManagementRepo() {
48360
48361
  const updateFields = {
48361
48362
  staffNo: `STAFF-${cardId.toString().slice(-10)}`,
48362
48363
  updatedAt: /* @__PURE__ */ new Date(),
48363
- userId: updatedVisitor
48364
+ userId: updatedVisitor,
48365
+ userCred: {
48366
+ ...params.user
48367
+ }
48364
48368
  };
48365
48369
  if (type === "QRCODE" /* QR */) {
48366
48370
  updateFields.one_time = true;
@@ -50366,7 +50370,7 @@ function useAccessManagementController() {
50366
50370
  quantity = 1,
50367
50371
  type,
50368
50372
  nfcCards,
50369
- visitorId,
50373
+ user,
50370
50374
  acm_url
50371
50375
  } = req.body;
50372
50376
  const schema2 = Joi87.object({
@@ -50381,7 +50385,7 @@ function useAccessManagementController() {
50381
50385
  })
50382
50386
  ).required(),
50383
50387
  acm_url: Joi87.string().required(),
50384
- visitorId: Joi87.string().hex().length(24).required()
50388
+ user: Joi87.object().optional().allow("", null)
50385
50389
  });
50386
50390
  const { error } = schema2.validate({
50387
50391
  site,
@@ -50389,7 +50393,7 @@ function useAccessManagementController() {
50389
50393
  quantity,
50390
50394
  type,
50391
50395
  nfcCards,
50392
- visitorId,
50396
+ user,
50393
50397
  acm_url
50394
50398
  });
50395
50399
  if (error) {
@@ -50401,7 +50405,7 @@ function useAccessManagementController() {
50401
50405
  quantity,
50402
50406
  type,
50403
50407
  nfcCards,
50404
- visitorId,
50408
+ user,
50405
50409
  acm_url
50406
50410
  });
50407
50411
  return res.status(200).json({ message: "Success", data: result });
@@ -51123,7 +51127,7 @@ import { BadRequestError as BadRequestError149, logger as logger127 } from "@736
51123
51127
  import Joi89 from "joi";
51124
51128
  function useNfcPatrolTagController() {
51125
51129
  const { add: _add, updateNfcPatrolTagBySite: _updateNfcPatrolTagBySite } = useNfcPatrolTagService();
51126
- const { getAll: _getAll } = useNfcPatrolTagRepo();
51130
+ const { getAll: _getAll, getById: _getById } = useNfcPatrolTagRepo();
51127
51131
  async function add(req, res, next) {
51128
51132
  const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
51129
51133
  (acc, [key, value2]) => ({ ...acc, [key]: value2 }),
@@ -51213,10 +51217,34 @@ function useNfcPatrolTagController() {
51213
51217
  return;
51214
51218
  }
51215
51219
  }
51220
+ async function getById(req, res, next) {
51221
+ const validation = Joi89.object({
51222
+ id: Joi89.string().length(24).hex().required()
51223
+ });
51224
+ const { error } = validation.validate(req.params, {
51225
+ abortEarly: false
51226
+ });
51227
+ if (error) {
51228
+ const messages = error.details.map((d) => d.message).join(", ");
51229
+ logger127.log({ level: "error", message: messages });
51230
+ next(new BadRequestError149(messages));
51231
+ return;
51232
+ }
51233
+ try {
51234
+ const tag = await _getById(req.params.id);
51235
+ res.status(200).json(tag);
51236
+ return;
51237
+ } catch (error2) {
51238
+ logger127.log({ level: "error", message: error2.message });
51239
+ next(error2);
51240
+ return;
51241
+ }
51242
+ }
51216
51243
  return {
51217
51244
  add,
51218
51245
  getAll,
51219
- updateNfcPatrolTagBySite
51246
+ updateNfcPatrolTagBySite,
51247
+ getById
51220
51248
  };
51221
51249
  }
51222
51250
 
@@ -58024,14 +58052,6 @@ function useNfcPatrolLogService() {
58024
58052
  if (!log) {
58025
58053
  throw new BadRequestError180("Patrol Log not found.");
58026
58054
  }
58027
- const route = await routeRepo.getById(log.route._id);
58028
- if (!route) {
58029
- throw new BadRequestError180("Route not found.");
58030
- }
58031
- const checkpoint = route.checkPoints[payload.checkpointIndex];
58032
- if (!checkpoint) {
58033
- throw new BadRequestError180("Checkpoint not found.");
58034
- }
58035
58055
  const logCheckpoint = log.checkPoints[payload.checkpointIndex];
58036
58056
  if (!logCheckpoint) {
58037
58057
  throw new BadRequestError180("Checkpoint log not found.");
@@ -58043,11 +58063,14 @@ function useNfcPatrolLogService() {
58043
58063
  throw new BadRequestError180("Skipped remarks are required.");
58044
58064
  }
58045
58065
  if (payload.action === "complete") {
58046
- const tag = await tagRepo.getById(checkpoint.nfcTag_id, session);
58047
- if (!tag.tagUID) {
58066
+ const tag = await tagRepo.getById(logCheckpoint.nfcTag_id);
58067
+ if (!tag) {
58068
+ throw new BadRequestError180("NFC Tag not found.");
58069
+ }
58070
+ if (!tag.tagID) {
58048
58071
  throw new BadRequestError180("NFC Tag has not been configured.");
58049
58072
  }
58050
- if (tag.tagUID !== payload.uid) {
58073
+ if (tag.tagID !== payload.uid) {
58051
58074
  throw new BadRequestError180("Invalid NFC Tag.");
58052
58075
  }
58053
58076
  }
@@ -58063,7 +58086,7 @@ function useNfcPatrolLogService() {
58063
58086
  await session?.abortTransaction();
58064
58087
  throw error;
58065
58088
  } finally {
58066
- session?.endSession();
58089
+ await session?.endSession();
58067
58090
  }
58068
58091
  }
58069
58092
  return {
@@ -58080,7 +58103,7 @@ import {
58080
58103
  import Joi111 from "joi";
58081
58104
  function useNfcPatrolLogController() {
58082
58105
  const { add: _add, completeCheckpoint: _completeCheckpoint } = useNfcPatrolLogService();
58083
- const { getAllBySite: _getAllBySite } = useNfcPatrolLogRepo();
58106
+ const { getAllBySite: _getAllBySite, getById: _getById } = useNfcPatrolLogRepo();
58084
58107
  async function add(req, res, next) {
58085
58108
  const payload = { ...req.body };
58086
58109
  try {
@@ -58159,10 +58182,19 @@ function useNfcPatrolLogController() {
58159
58182
  next(error);
58160
58183
  }
58161
58184
  }
58185
+ async function getLog(req, res, next) {
58186
+ try {
58187
+ const log = await _getById(req.params.id);
58188
+ res.json(log);
58189
+ } catch (error) {
58190
+ next(error);
58191
+ }
58192
+ }
58162
58193
  return {
58163
58194
  add,
58164
58195
  getAllBySite,
58165
- completeCheckpoint
58196
+ completeCheckpoint,
58197
+ getLog
58166
58198
  };
58167
58199
  }
58168
58200