@7365admin1/core 3.0.2 → 3.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 +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +108 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +108 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -11347,12 +11347,28 @@ function useSiteRepo() {
|
|
|
11347
11347
|
{ $match: { "buildings.0": { $exists: true } } },
|
|
11348
11348
|
{
|
|
11349
11349
|
$lookup: {
|
|
11350
|
-
from: "building-
|
|
11350
|
+
from: "building-levels",
|
|
11351
11351
|
let: { buildingIds: "$buildings._id" },
|
|
11352
11352
|
pipeline: [
|
|
11353
11353
|
{
|
|
11354
11354
|
$match: {
|
|
11355
|
-
$expr: { $in: ["$
|
|
11355
|
+
$expr: { $in: ["$blockId", "$$buildingIds"] },
|
|
11356
|
+
status: { $ne: "deleted" }
|
|
11357
|
+
}
|
|
11358
|
+
}
|
|
11359
|
+
],
|
|
11360
|
+
as: "levels"
|
|
11361
|
+
}
|
|
11362
|
+
},
|
|
11363
|
+
{ $match: { "levels.0": { $exists: true } } },
|
|
11364
|
+
{
|
|
11365
|
+
$lookup: {
|
|
11366
|
+
from: "building-units",
|
|
11367
|
+
let: { levelIds: "$levels._id" },
|
|
11368
|
+
pipeline: [
|
|
11369
|
+
{
|
|
11370
|
+
$match: {
|
|
11371
|
+
$expr: { $in: ["$level", "$$levelIds"] },
|
|
11356
11372
|
status: { $ne: "deleted" }
|
|
11357
11373
|
}
|
|
11358
11374
|
},
|
|
@@ -24397,7 +24413,7 @@ function usePersonRepo() {
|
|
|
24397
24413
|
pipeline: [
|
|
24398
24414
|
{
|
|
24399
24415
|
$match: {
|
|
24400
|
-
$expr: { $eq: [
|
|
24416
|
+
$expr: { $eq: ["$_id", "$$blockId"] }
|
|
24401
24417
|
}
|
|
24402
24418
|
},
|
|
24403
24419
|
{ $project: { _id: 1, name: 1, block: 1 } }
|
|
@@ -24413,7 +24429,7 @@ function usePersonRepo() {
|
|
|
24413
24429
|
pipeline: [
|
|
24414
24430
|
{
|
|
24415
24431
|
$match: {
|
|
24416
|
-
$expr: { $eq: [
|
|
24432
|
+
$expr: { $eq: ["$_id", "$$levelId"] }
|
|
24417
24433
|
}
|
|
24418
24434
|
},
|
|
24419
24435
|
{ $project: { _id: 1, name: 1 } }
|
|
@@ -24644,7 +24660,7 @@ function usePersonRepo() {
|
|
|
24644
24660
|
pipeline: [
|
|
24645
24661
|
{
|
|
24646
24662
|
$match: {
|
|
24647
|
-
$expr: { $eq: [
|
|
24663
|
+
$expr: { $eq: ["$_id", "$$blockId"] }
|
|
24648
24664
|
}
|
|
24649
24665
|
},
|
|
24650
24666
|
{ $project: { _id: 1, name: 1, block: 1 } }
|
|
@@ -24660,7 +24676,7 @@ function usePersonRepo() {
|
|
|
24660
24676
|
pipeline: [
|
|
24661
24677
|
{
|
|
24662
24678
|
$match: {
|
|
24663
|
-
$expr: { $eq: [
|
|
24679
|
+
$expr: { $eq: ["$_id", "$$levelId"] }
|
|
24664
24680
|
}
|
|
24665
24681
|
},
|
|
24666
24682
|
{ $project: { _id: 1, name: 1 } }
|
|
@@ -24734,7 +24750,7 @@ function usePersonRepo() {
|
|
|
24734
24750
|
pipeline: [
|
|
24735
24751
|
{
|
|
24736
24752
|
$match: {
|
|
24737
|
-
$expr: { $eq: [
|
|
24753
|
+
$expr: { $eq: ["$_id", "$$blockId"] }
|
|
24738
24754
|
}
|
|
24739
24755
|
},
|
|
24740
24756
|
{ $project: { _id: 1, name: 1, block: 1 } }
|
|
@@ -24750,7 +24766,7 @@ function usePersonRepo() {
|
|
|
24750
24766
|
pipeline: [
|
|
24751
24767
|
{
|
|
24752
24768
|
$match: {
|
|
24753
|
-
$expr: { $eq: [
|
|
24769
|
+
$expr: { $eq: ["$_id", "$$levelId"] }
|
|
24754
24770
|
}
|
|
24755
24771
|
},
|
|
24756
24772
|
{ $project: { _id: 1, name: 1 } }
|
|
@@ -27549,6 +27565,9 @@ function useBuildingRepo() {
|
|
|
27549
27565
|
throw new Error("Unable to connect to server.");
|
|
27550
27566
|
}
|
|
27551
27567
|
const collection = db.collection(buildings_namespace_collection);
|
|
27568
|
+
const buildingUnitCollection = db.collection(
|
|
27569
|
+
building_units_namespace_collection
|
|
27570
|
+
);
|
|
27552
27571
|
const { getCache, setCache, delNamespace } = useCache28(
|
|
27553
27572
|
buildings_namespace_collection
|
|
27554
27573
|
);
|
|
@@ -28072,6 +28091,49 @@ function useBuildingRepo() {
|
|
|
28072
28091
|
}
|
|
28073
28092
|
}
|
|
28074
28093
|
}
|
|
28094
|
+
async function getBuildingWithUnitsList(site) {
|
|
28095
|
+
try {
|
|
28096
|
+
site = new ObjectId50(site);
|
|
28097
|
+
} catch (error) {
|
|
28098
|
+
throw new BadRequestError80("Invalid site ID.");
|
|
28099
|
+
}
|
|
28100
|
+
const buildingUnitsQuery = {
|
|
28101
|
+
site,
|
|
28102
|
+
status: "active" /* ACTIVE */
|
|
28103
|
+
};
|
|
28104
|
+
try {
|
|
28105
|
+
const buildingsWithUnits = await buildingUnitCollection.aggregate([
|
|
28106
|
+
{ $match: buildingUnitsQuery },
|
|
28107
|
+
{ $project: { building: 1 } }
|
|
28108
|
+
]).toArray();
|
|
28109
|
+
const buildingIds = [
|
|
28110
|
+
...new Set(buildingsWithUnits.map((l) => l.building.toString()))
|
|
28111
|
+
].map((id) => new ObjectId50(id));
|
|
28112
|
+
const result = await collection.aggregate([
|
|
28113
|
+
{
|
|
28114
|
+
$match: {
|
|
28115
|
+
_id: { $in: buildingIds }
|
|
28116
|
+
}
|
|
28117
|
+
},
|
|
28118
|
+
{
|
|
28119
|
+
$project: {
|
|
28120
|
+
name: 1
|
|
28121
|
+
}
|
|
28122
|
+
}
|
|
28123
|
+
]).toArray();
|
|
28124
|
+
return {
|
|
28125
|
+
success: true,
|
|
28126
|
+
message: "Buildings with units retrieved successfully",
|
|
28127
|
+
data: result
|
|
28128
|
+
};
|
|
28129
|
+
} catch (error) {
|
|
28130
|
+
if (error instanceof AppError13) {
|
|
28131
|
+
throw error;
|
|
28132
|
+
} else {
|
|
28133
|
+
throw new InternalServerError29("Failed to get buildings.");
|
|
28134
|
+
}
|
|
28135
|
+
}
|
|
28136
|
+
}
|
|
28075
28137
|
return {
|
|
28076
28138
|
createIndexes,
|
|
28077
28139
|
add,
|
|
@@ -28083,7 +28145,8 @@ function useBuildingRepo() {
|
|
|
28083
28145
|
getBuildingLevel,
|
|
28084
28146
|
getBuildingLevelForResident,
|
|
28085
28147
|
getBuildingLevelWithUnits,
|
|
28086
|
-
getBuildingList
|
|
28148
|
+
getBuildingList,
|
|
28149
|
+
getBuildingWithUnitsList
|
|
28087
28150
|
};
|
|
28088
28151
|
}
|
|
28089
28152
|
|
|
@@ -28534,7 +28597,7 @@ function useBuildingLevelRepo() {
|
|
|
28534
28597
|
if (error instanceof AppError14) {
|
|
28535
28598
|
throw error;
|
|
28536
28599
|
} else {
|
|
28537
|
-
throw new InternalServerError30("Failed to get building.");
|
|
28600
|
+
throw new InternalServerError30("Failed to get building level.");
|
|
28538
28601
|
}
|
|
28539
28602
|
}
|
|
28540
28603
|
}
|
|
@@ -28818,7 +28881,8 @@ function useBuildingController() {
|
|
|
28818
28881
|
getBuildingLevel: _getBuildingLevel,
|
|
28819
28882
|
getBuildingLevelForResident: _getBuildingLevelForResident,
|
|
28820
28883
|
getBuildingLevelWithUnits: _getBuildingLevelWithUnits,
|
|
28821
|
-
getBuildingList: _getBuildingList
|
|
28884
|
+
getBuildingList: _getBuildingList,
|
|
28885
|
+
getBuildingWithUnitsList: _getBuildingWithUnitsList
|
|
28822
28886
|
} = useBuildingRepo();
|
|
28823
28887
|
const {
|
|
28824
28888
|
updateById: _updateById,
|
|
@@ -29205,6 +29269,28 @@ function useBuildingController() {
|
|
|
29205
29269
|
next(error);
|
|
29206
29270
|
}
|
|
29207
29271
|
}
|
|
29272
|
+
async function getBuildingWithUnitsList(req, res, next) {
|
|
29273
|
+
try {
|
|
29274
|
+
const schema2 = Joi46.object({
|
|
29275
|
+
site: Joi46.string().hex().length(24).required()
|
|
29276
|
+
});
|
|
29277
|
+
const { error, value } = schema2.validate({
|
|
29278
|
+
site: req.params.siteId
|
|
29279
|
+
});
|
|
29280
|
+
if (error) {
|
|
29281
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
29282
|
+
logger65.log({ level: "error", message: messages });
|
|
29283
|
+
next(new BadRequestError84(messages));
|
|
29284
|
+
return;
|
|
29285
|
+
}
|
|
29286
|
+
const { site } = value;
|
|
29287
|
+
const result = await _getBuildingWithUnitsList(site);
|
|
29288
|
+
res.json(result);
|
|
29289
|
+
return;
|
|
29290
|
+
} catch (error) {
|
|
29291
|
+
next(error);
|
|
29292
|
+
}
|
|
29293
|
+
}
|
|
29208
29294
|
return {
|
|
29209
29295
|
createBuilding,
|
|
29210
29296
|
getAll,
|
|
@@ -29216,7 +29302,8 @@ function useBuildingController() {
|
|
|
29216
29302
|
getBuildingLevelForResident,
|
|
29217
29303
|
uploadSpreadsheetBuilding,
|
|
29218
29304
|
getBuildingLevelWithUnits,
|
|
29219
|
-
getBuildingList
|
|
29305
|
+
getBuildingList,
|
|
29306
|
+
getBuildingWithUnitsList
|
|
29220
29307
|
};
|
|
29221
29308
|
}
|
|
29222
29309
|
|
|
@@ -34713,7 +34800,6 @@ function usePersonService() {
|
|
|
34713
34800
|
return "People added successfully.";
|
|
34714
34801
|
} catch (error) {
|
|
34715
34802
|
console.log("error message service", error);
|
|
34716
|
-
console.log("error message service", error.message);
|
|
34717
34803
|
logger84.error("Error in people service add:", error);
|
|
34718
34804
|
await session.abortTransaction();
|
|
34719
34805
|
throw error;
|
|
@@ -34740,6 +34826,15 @@ function usePersonService() {
|
|
|
34740
34826
|
if (value.site && typeof value.site === "string") {
|
|
34741
34827
|
value.site = new ObjectId65(value.site);
|
|
34742
34828
|
}
|
|
34829
|
+
if (value.block && typeof value.block === "string") {
|
|
34830
|
+
value.block = new ObjectId65(value.block);
|
|
34831
|
+
}
|
|
34832
|
+
if (value.level && typeof value.level === "string") {
|
|
34833
|
+
value.level = new ObjectId65(value.level);
|
|
34834
|
+
}
|
|
34835
|
+
if (value.unit && typeof value.unit === "string") {
|
|
34836
|
+
value.unit = new ObjectId65(value.unit);
|
|
34837
|
+
}
|
|
34743
34838
|
const isOrgChanged = value.org && person.org?.toString() !== value.org.toString();
|
|
34744
34839
|
await _updateById(_id, value, session);
|
|
34745
34840
|
if (isOrgChanged && person.user) {
|