@7365admin1/core 3.42.2 → 3.42.3

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
@@ -30089,6 +30089,20 @@ function useBuildingLevelRepo() {
30089
30089
  }
30090
30090
  }
30091
30091
  }
30092
+ async function getActiveLevelsByIds(ids, session) {
30093
+ if (!ids || ids.length === 0)
30094
+ return [];
30095
+ let objectIds;
30096
+ try {
30097
+ objectIds = ids.map((id) => new ObjectId56(id));
30098
+ } catch {
30099
+ throw new BadRequestError83("Invalid level ID format.");
30100
+ }
30101
+ return collection.find(
30102
+ { _id: { $in: objectIds }, status: "active" /* ACTIVE */ },
30103
+ { projection: { _id: 1, name: 1 }, session }
30104
+ ).toArray();
30105
+ }
30092
30106
  async function updateLevelById(_id, value, session) {
30093
30107
  try {
30094
30108
  _id = new ObjectId56(_id);
@@ -30287,7 +30301,8 @@ function useBuildingLevelRepo() {
30287
30301
  deleteById,
30288
30302
  bulkWriteLevels,
30289
30303
  batchUpdateByIds,
30290
- getBuildingLevelList
30304
+ getBuildingLevelList,
30305
+ getActiveLevelsByIds
30291
30306
  };
30292
30307
  }
30293
30308
 
@@ -30308,7 +30323,10 @@ function useBuildingService() {
30308
30323
  } = useBuildingUnitRepo();
30309
30324
  const { updateStatusById } = useFileRepo();
30310
30325
  const { deleteFile } = useFileService();
30311
- const { bulkWriteLevels: _bulkWriteLevels } = useBuildingLevelRepo();
30326
+ const {
30327
+ bulkWriteLevels: _bulkWriteLevels,
30328
+ getActiveLevelsByIds: _getActiveLevelsByIds
30329
+ } = useBuildingLevelRepo();
30312
30330
  function normalizeImportKey(value) {
30313
30331
  return String(value ?? "").trim().replace(/\s+/g, " ").toLowerCase();
30314
30332
  }
@@ -30402,23 +30420,37 @@ function useBuildingService() {
30402
30420
  );
30403
30421
  }
30404
30422
  if (data.levels) {
30405
- const levelsPayload = (data.levels ?? []).map((levelName) => ({
30406
- blockId: id,
30407
- site: building.site.toString(),
30408
- name: levelName,
30409
- status: "active" /* ACTIVE */,
30410
- createdAt: /* @__PURE__ */ new Date(),
30411
- updatedAt: null,
30412
- deletedAt: null
30413
- }));
30414
- let levels;
30415
- if (levelsPayload.length > 0) {
30416
- levels = await _bulkWriteLevels(levelsPayload, session);
30417
- }
30418
- if (levels) {
30419
- building.levels.push(...Object.values(levels.insertedIds));
30420
- data.levels = building.levels.map((id2) => id2.toString());
30423
+ const submittedNames = data.levels ?? [];
30424
+ const existingLevels = await _getActiveLevelsByIds(
30425
+ building.levels,
30426
+ session
30427
+ );
30428
+ const seenKeys = new Set(
30429
+ existingLevels.map((level) => normalizeImportKey(level.name))
30430
+ );
30431
+ const newNames = submittedNames.filter((name) => {
30432
+ const key = normalizeImportKey(name);
30433
+ if (seenKeys.has(key))
30434
+ return false;
30435
+ seenKeys.add(key);
30436
+ return true;
30437
+ });
30438
+ if (newNames.length > 0) {
30439
+ const levelsPayload = newNames.map((name) => ({
30440
+ blockId: id,
30441
+ site: building.site.toString(),
30442
+ name,
30443
+ status: "active" /* ACTIVE */,
30444
+ createdAt: /* @__PURE__ */ new Date(),
30445
+ updatedAt: null,
30446
+ deletedAt: null
30447
+ }));
30448
+ const levels = await _bulkWriteLevels(levelsPayload, session);
30449
+ if (levels) {
30450
+ building.levels.push(...Object.values(levels.insertedIds));
30451
+ }
30421
30452
  }
30453
+ data.levels = building.levels.map((levelId) => levelId.toString());
30422
30454
  }
30423
30455
  const buildingUnitData = {};
30424
30456
  if (data.name && building.name !== data.name) {