@7365admin1/core 3.32.2-staging.3 → 3.32.2-staging.4

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.d.ts CHANGED
@@ -2965,7 +2965,7 @@ declare function useVisitorTransactionRepo(): {
2965
2965
  pageRange: string;
2966
2966
  }>;
2967
2967
  getOpenByPlateNumber: (plateNumber: string, site: string | ObjectId) => Promise<TVisitorTransaction | null | undefined>;
2968
- updateById: (_id: string | ObjectId, value: Partial<TVisitorTransaction>, session?: ClientSession, isManualCheckOut?: boolean) => Promise<mongodb.UpdateResult<bson.Document>>;
2968
+ updateById: (_id: string | ObjectId, value: Partial<TVisitorTransaction>, session?: ClientSession, isManualCheckOut?: boolean) => Promise<mongodb.UpdateResult<bson.Document> | undefined>;
2969
2969
  deleteVisitorTransaction: (_id: string | ObjectId) => Promise<number>;
2970
2970
  createTextIndex: () => Promise<void>;
2971
2971
  getDeliveryPickupTransactions: () => Promise<mongodb.WithId<bson.Document>[]>;
package/dist/index.js CHANGED
@@ -22137,7 +22137,14 @@ function useVisitorTransactionRepo() {
22137
22137
  }
22138
22138
  });
22139
22139
  if (Array.isArray(value.visitorPass)) {
22140
- value.visitorPass.forEach((item, index) => {
22140
+ const visitorPassMap = /* @__PURE__ */ new Map();
22141
+ value.visitorPass.forEach((item) => {
22142
+ if (item.keyId) {
22143
+ visitorPassMap.set(item.keyId.toString(), item);
22144
+ }
22145
+ });
22146
+ const uniqueVisitorPass = Array.from(visitorPassMap.values());
22147
+ uniqueVisitorPass.forEach((item, index) => {
22141
22148
  if (item.add === true) {
22142
22149
  const { add: add2, ...cleanItem } = item;
22143
22150
  cleanItem.keyId = convertObjectIdUtilNonAsync(cleanItem.keyId, "Pass Id");
@@ -22150,8 +22157,7 @@ function useVisitorTransactionRepo() {
22150
22157
  Object.keys(item).forEach((itemKey) => {
22151
22158
  if (itemKey !== "keyId") {
22152
22159
  const typedItemKey = itemKey;
22153
- let itemValue = item[typedItemKey];
22154
- updateFields[`visitorPass.$[${elementKey}].${itemKey}`] = itemValue;
22160
+ updateFields[`visitorPass.$[${elementKey}].${itemKey}`] = item[typedItemKey];
22155
22161
  }
22156
22162
  });
22157
22163
  arrayFilters.push({ [`${elementKey}.keyId`]: new import_mongodb41.ObjectId(item.keyId) });
@@ -22159,7 +22165,14 @@ function useVisitorTransactionRepo() {
22159
22165
  });
22160
22166
  }
22161
22167
  if (Array.isArray(value.passKeys)) {
22162
- value.passKeys.forEach((item, index) => {
22168
+ const passKeysMap = /* @__PURE__ */ new Map();
22169
+ value.passKeys.forEach((item) => {
22170
+ if (item.keyId) {
22171
+ passKeysMap.set(item.keyId.toString(), item);
22172
+ }
22173
+ });
22174
+ const uniquePassKeys = Array.from(passKeysMap.values());
22175
+ uniquePassKeys.forEach((item, index) => {
22163
22176
  if (item.add === true) {
22164
22177
  const { add: add2, ...cleanItem } = item;
22165
22178
  cleanItem.keyId = convertObjectIdUtilNonAsync(cleanItem.keyId, "Key Id");
@@ -22172,32 +22185,34 @@ function useVisitorTransactionRepo() {
22172
22185
  Object.keys(item).forEach((itemKey) => {
22173
22186
  if (itemKey !== "keyId") {
22174
22187
  const typedItemKey = itemKey;
22175
- let itemValue = item[typedItemKey];
22176
- updateFields[`passKeys.$[${elementKey}].${itemKey}`] = itemValue;
22188
+ updateFields[`passKeys.$[${elementKey}].${itemKey}`] = item[typedItemKey];
22177
22189
  }
22178
22190
  });
22179
22191
  arrayFilters.push({ [`${elementKey}.keyId`]: new import_mongodb41.ObjectId(item.keyId) });
22180
22192
  }
22181
22193
  });
22182
22194
  }
22183
- const updatePayload = {};
22195
+ let result;
22184
22196
  if (Object.keys(updateFields).length > 0) {
22185
- updatePayload.$set = updateFields;
22197
+ result = await collection.updateOne(
22198
+ { _id: new import_mongodb41.ObjectId(_id) },
22199
+ { $set: updateFields },
22200
+ {
22201
+ ...arrayFilters.length > 0 && { arrayFilters },
22202
+ session
22203
+ }
22204
+ );
22186
22205
  }
22187
22206
  if (Object.keys(pushFields).length > 0) {
22188
- updatePayload.$push = pushFields;
22207
+ result = await collection.updateOne(
22208
+ { _id: new import_mongodb41.ObjectId(_id) },
22209
+ { $push: pushFields },
22210
+ { session }
22211
+ );
22189
22212
  }
22190
- const result = await collection.updateOne(
22191
- { _id: new import_mongodb41.ObjectId(_id) },
22192
- updatePayload,
22193
- {
22194
- ...arrayFilters.length > 0 && { arrayFilters },
22195
- // Only pass if not empty
22196
- session
22197
- }
22198
- );
22199
22213
  return result;
22200
22214
  } catch (error) {
22215
+ console.log("Error in updateById visitor transaction repo", error);
22201
22216
  throw error;
22202
22217
  }
22203
22218
  }
@@ -35469,7 +35484,7 @@ function useVisitorTransactionService() {
35469
35484
  } else if (item?.status && VALID_STATUSES.has(item.status)) {
35470
35485
  status = item.status;
35471
35486
  } else {
35472
- throw new Error("Invalid Visitor Pass Status");
35487
+ throw new Error("Invalid Key Status");
35473
35488
  }
35474
35489
  await KeyRepo.updateKeyById(
35475
35490
  item.keyId,