@7365admin1/core 3.32.2-staging.41 → 3.32.2-staging.42
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 +1 -0
- package/dist/index.js +50 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7788,6 +7788,7 @@ declare function useBuildingLevelRepo(): {
|
|
|
7788
7788
|
message: string;
|
|
7789
7789
|
data: bson.Document[];
|
|
7790
7790
|
}>;
|
|
7791
|
+
getActiveLevelsByIds: (ids: (string | ObjectId)[], session?: ClientSession) => Promise<TBuildingLevel[]>;
|
|
7791
7792
|
};
|
|
7792
7793
|
|
|
7793
7794
|
declare function useBuildingLevelService(): {
|
package/dist/index.js
CHANGED
|
@@ -29563,6 +29563,20 @@ function useBuildingLevelRepo() {
|
|
|
29563
29563
|
}
|
|
29564
29564
|
}
|
|
29565
29565
|
}
|
|
29566
|
+
async function getActiveLevelsByIds(ids, session) {
|
|
29567
|
+
if (!ids || ids.length === 0)
|
|
29568
|
+
return [];
|
|
29569
|
+
let objectIds;
|
|
29570
|
+
try {
|
|
29571
|
+
objectIds = ids.map((id) => new import_mongodb53.ObjectId(id));
|
|
29572
|
+
} catch {
|
|
29573
|
+
throw new import_node_server_utils87.BadRequestError("Invalid level ID format.");
|
|
29574
|
+
}
|
|
29575
|
+
return collection.find(
|
|
29576
|
+
{ _id: { $in: objectIds }, status: "active" /* ACTIVE */ },
|
|
29577
|
+
{ projection: { _id: 1, name: 1 }, session }
|
|
29578
|
+
).toArray();
|
|
29579
|
+
}
|
|
29566
29580
|
async function updateLevelById(_id, value, session) {
|
|
29567
29581
|
try {
|
|
29568
29582
|
_id = new import_mongodb53.ObjectId(_id);
|
|
@@ -29761,7 +29775,8 @@ function useBuildingLevelRepo() {
|
|
|
29761
29775
|
deleteById,
|
|
29762
29776
|
bulkWriteLevels,
|
|
29763
29777
|
batchUpdateByIds,
|
|
29764
|
-
getBuildingLevelList
|
|
29778
|
+
getBuildingLevelList,
|
|
29779
|
+
getActiveLevelsByIds
|
|
29765
29780
|
};
|
|
29766
29781
|
}
|
|
29767
29782
|
|
|
@@ -29782,7 +29797,10 @@ function useBuildingService() {
|
|
|
29782
29797
|
} = useBuildingUnitRepo();
|
|
29783
29798
|
const { updateStatusById } = useFileRepo();
|
|
29784
29799
|
const { deleteFile } = useFileService();
|
|
29785
|
-
const {
|
|
29800
|
+
const {
|
|
29801
|
+
bulkWriteLevels: _bulkWriteLevels,
|
|
29802
|
+
getActiveLevelsByIds: _getActiveLevelsByIds
|
|
29803
|
+
} = useBuildingLevelRepo();
|
|
29786
29804
|
function normalizeImportKey(value) {
|
|
29787
29805
|
return String(value ?? "").trim().replace(/\s+/g, " ").toLowerCase();
|
|
29788
29806
|
}
|
|
@@ -29876,23 +29894,37 @@ function useBuildingService() {
|
|
|
29876
29894
|
);
|
|
29877
29895
|
}
|
|
29878
29896
|
if (data.levels) {
|
|
29879
|
-
const
|
|
29880
|
-
|
|
29881
|
-
|
|
29882
|
-
|
|
29883
|
-
|
|
29884
|
-
|
|
29885
|
-
|
|
29886
|
-
|
|
29887
|
-
|
|
29888
|
-
|
|
29889
|
-
|
|
29890
|
-
|
|
29891
|
-
|
|
29892
|
-
|
|
29893
|
-
|
|
29894
|
-
|
|
29897
|
+
const submittedNames = data.levels ?? [];
|
|
29898
|
+
const existingLevels = await _getActiveLevelsByIds(
|
|
29899
|
+
building.levels,
|
|
29900
|
+
session
|
|
29901
|
+
);
|
|
29902
|
+
const seenKeys = new Set(
|
|
29903
|
+
existingLevels.map((level) => normalizeImportKey(level.name))
|
|
29904
|
+
);
|
|
29905
|
+
const newNames = submittedNames.filter((name) => {
|
|
29906
|
+
const key = normalizeImportKey(name);
|
|
29907
|
+
if (seenKeys.has(key))
|
|
29908
|
+
return false;
|
|
29909
|
+
seenKeys.add(key);
|
|
29910
|
+
return true;
|
|
29911
|
+
});
|
|
29912
|
+
if (newNames.length > 0) {
|
|
29913
|
+
const levelsPayload = newNames.map((name) => ({
|
|
29914
|
+
blockId: id,
|
|
29915
|
+
site: building.site.toString(),
|
|
29916
|
+
name,
|
|
29917
|
+
status: "active" /* ACTIVE */,
|
|
29918
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
29919
|
+
updatedAt: null,
|
|
29920
|
+
deletedAt: null
|
|
29921
|
+
}));
|
|
29922
|
+
const levels = await _bulkWriteLevels(levelsPayload, session);
|
|
29923
|
+
if (levels) {
|
|
29924
|
+
building.levels.push(...Object.values(levels.insertedIds));
|
|
29925
|
+
}
|
|
29895
29926
|
}
|
|
29927
|
+
data.levels = building.levels.map((levelId) => levelId.toString());
|
|
29896
29928
|
}
|
|
29897
29929
|
const buildingUnitData = {};
|
|
29898
29930
|
if (data.name && building.name !== data.name) {
|