@7365admin1/core 3.0.1 → 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 +12 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +112 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +112 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1952,6 +1952,11 @@ declare function useBuildingRepo(): {
|
|
|
1952
1952
|
message: string;
|
|
1953
1953
|
data: bson.Document[];
|
|
1954
1954
|
}>;
|
|
1955
|
+
getBuildingWithUnitsList: (site: string | ObjectId) => Promise<{
|
|
1956
|
+
success: boolean;
|
|
1957
|
+
message: string;
|
|
1958
|
+
data: bson.Document[];
|
|
1959
|
+
}>;
|
|
1955
1960
|
};
|
|
1956
1961
|
|
|
1957
1962
|
declare function useBuildingService(): {
|
|
@@ -1981,6 +1986,7 @@ declare function useBuildingController(): {
|
|
|
1981
1986
|
uploadSpreadsheetBuilding: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1982
1987
|
getBuildingLevelWithUnits: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1983
1988
|
getBuildingList: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1989
|
+
getBuildingWithUnitsList: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1984
1990
|
};
|
|
1985
1991
|
|
|
1986
1992
|
declare const building_units_namespace_collection = "building-units";
|
package/dist/index.js
CHANGED
|
@@ -11725,12 +11725,28 @@ function useSiteRepo() {
|
|
|
11725
11725
|
{ $match: { "buildings.0": { $exists: true } } },
|
|
11726
11726
|
{
|
|
11727
11727
|
$lookup: {
|
|
11728
|
-
from: "building-
|
|
11728
|
+
from: "building-levels",
|
|
11729
11729
|
let: { buildingIds: "$buildings._id" },
|
|
11730
11730
|
pipeline: [
|
|
11731
11731
|
{
|
|
11732
11732
|
$match: {
|
|
11733
|
-
$expr: { $in: ["$
|
|
11733
|
+
$expr: { $in: ["$blockId", "$$buildingIds"] },
|
|
11734
|
+
status: { $ne: "deleted" }
|
|
11735
|
+
}
|
|
11736
|
+
}
|
|
11737
|
+
],
|
|
11738
|
+
as: "levels"
|
|
11739
|
+
}
|
|
11740
|
+
},
|
|
11741
|
+
{ $match: { "levels.0": { $exists: true } } },
|
|
11742
|
+
{
|
|
11743
|
+
$lookup: {
|
|
11744
|
+
from: "building-units",
|
|
11745
|
+
let: { levelIds: "$levels._id" },
|
|
11746
|
+
pipeline: [
|
|
11747
|
+
{
|
|
11748
|
+
$match: {
|
|
11749
|
+
$expr: { $in: ["$level", "$$levelIds"] },
|
|
11734
11750
|
status: { $ne: "deleted" }
|
|
11735
11751
|
}
|
|
11736
11752
|
},
|
|
@@ -22299,7 +22315,7 @@ function useVehicleRepo() {
|
|
|
22299
22315
|
pipeline: [
|
|
22300
22316
|
{
|
|
22301
22317
|
$match: {
|
|
22302
|
-
$expr: { $eq: [
|
|
22318
|
+
$expr: { $eq: ["$_id", "$$blockId"] }
|
|
22303
22319
|
}
|
|
22304
22320
|
},
|
|
22305
22321
|
{ $project: { _id: 1, name: 1, block: 1 } }
|
|
@@ -22315,7 +22331,7 @@ function useVehicleRepo() {
|
|
|
22315
22331
|
pipeline: [
|
|
22316
22332
|
{
|
|
22317
22333
|
$match: {
|
|
22318
|
-
$expr: { $eq: [
|
|
22334
|
+
$expr: { $eq: ["$_id", "$$levelId"] }
|
|
22319
22335
|
}
|
|
22320
22336
|
},
|
|
22321
22337
|
{ $project: { _id: 1, name: 1 } }
|
|
@@ -22327,11 +22343,11 @@ function useVehicleRepo() {
|
|
|
22327
22343
|
{
|
|
22328
22344
|
$lookup: {
|
|
22329
22345
|
from: "building-units",
|
|
22330
|
-
let: { unitId:
|
|
22346
|
+
let: { unitId: "$unit" },
|
|
22331
22347
|
pipeline: [
|
|
22332
22348
|
{
|
|
22333
22349
|
$match: {
|
|
22334
|
-
$expr: { $eq: [
|
|
22350
|
+
$expr: { $eq: ["$_id", "$$unitId"] }
|
|
22335
22351
|
}
|
|
22336
22352
|
},
|
|
22337
22353
|
{ $project: { _id: 1, name: 1 } }
|
|
@@ -24609,7 +24625,7 @@ function usePersonRepo() {
|
|
|
24609
24625
|
pipeline: [
|
|
24610
24626
|
{
|
|
24611
24627
|
$match: {
|
|
24612
|
-
$expr: { $eq: [
|
|
24628
|
+
$expr: { $eq: ["$_id", "$$blockId"] }
|
|
24613
24629
|
}
|
|
24614
24630
|
},
|
|
24615
24631
|
{ $project: { _id: 1, name: 1, block: 1 } }
|
|
@@ -24625,7 +24641,7 @@ function usePersonRepo() {
|
|
|
24625
24641
|
pipeline: [
|
|
24626
24642
|
{
|
|
24627
24643
|
$match: {
|
|
24628
|
-
$expr: { $eq: [
|
|
24644
|
+
$expr: { $eq: ["$_id", "$$levelId"] }
|
|
24629
24645
|
}
|
|
24630
24646
|
},
|
|
24631
24647
|
{ $project: { _id: 1, name: 1 } }
|
|
@@ -24856,7 +24872,7 @@ function usePersonRepo() {
|
|
|
24856
24872
|
pipeline: [
|
|
24857
24873
|
{
|
|
24858
24874
|
$match: {
|
|
24859
|
-
$expr: { $eq: [
|
|
24875
|
+
$expr: { $eq: ["$_id", "$$blockId"] }
|
|
24860
24876
|
}
|
|
24861
24877
|
},
|
|
24862
24878
|
{ $project: { _id: 1, name: 1, block: 1 } }
|
|
@@ -24872,7 +24888,7 @@ function usePersonRepo() {
|
|
|
24872
24888
|
pipeline: [
|
|
24873
24889
|
{
|
|
24874
24890
|
$match: {
|
|
24875
|
-
$expr: { $eq: [
|
|
24891
|
+
$expr: { $eq: ["$_id", "$$levelId"] }
|
|
24876
24892
|
}
|
|
24877
24893
|
},
|
|
24878
24894
|
{ $project: { _id: 1, name: 1 } }
|
|
@@ -24946,7 +24962,7 @@ function usePersonRepo() {
|
|
|
24946
24962
|
pipeline: [
|
|
24947
24963
|
{
|
|
24948
24964
|
$match: {
|
|
24949
|
-
$expr: { $eq: [
|
|
24965
|
+
$expr: { $eq: ["$_id", "$$blockId"] }
|
|
24950
24966
|
}
|
|
24951
24967
|
},
|
|
24952
24968
|
{ $project: { _id: 1, name: 1, block: 1 } }
|
|
@@ -24962,7 +24978,7 @@ function usePersonRepo() {
|
|
|
24962
24978
|
pipeline: [
|
|
24963
24979
|
{
|
|
24964
24980
|
$match: {
|
|
24965
|
-
$expr: { $eq: [
|
|
24981
|
+
$expr: { $eq: ["$_id", "$$levelId"] }
|
|
24966
24982
|
}
|
|
24967
24983
|
},
|
|
24968
24984
|
{ $project: { _id: 1, name: 1 } }
|
|
@@ -27737,6 +27753,9 @@ function useBuildingRepo() {
|
|
|
27737
27753
|
throw new Error("Unable to connect to server.");
|
|
27738
27754
|
}
|
|
27739
27755
|
const collection = db.collection(buildings_namespace_collection);
|
|
27756
|
+
const buildingUnitCollection = db.collection(
|
|
27757
|
+
building_units_namespace_collection
|
|
27758
|
+
);
|
|
27740
27759
|
const { getCache, setCache, delNamespace } = (0, import_node_server_utils83.useCache)(
|
|
27741
27760
|
buildings_namespace_collection
|
|
27742
27761
|
);
|
|
@@ -28260,6 +28279,49 @@ function useBuildingRepo() {
|
|
|
28260
28279
|
}
|
|
28261
28280
|
}
|
|
28262
28281
|
}
|
|
28282
|
+
async function getBuildingWithUnitsList(site) {
|
|
28283
|
+
try {
|
|
28284
|
+
site = new import_mongodb50.ObjectId(site);
|
|
28285
|
+
} catch (error) {
|
|
28286
|
+
throw new import_node_server_utils83.BadRequestError("Invalid site ID.");
|
|
28287
|
+
}
|
|
28288
|
+
const buildingUnitsQuery = {
|
|
28289
|
+
site,
|
|
28290
|
+
status: "active" /* ACTIVE */
|
|
28291
|
+
};
|
|
28292
|
+
try {
|
|
28293
|
+
const buildingsWithUnits = await buildingUnitCollection.aggregate([
|
|
28294
|
+
{ $match: buildingUnitsQuery },
|
|
28295
|
+
{ $project: { building: 1 } }
|
|
28296
|
+
]).toArray();
|
|
28297
|
+
const buildingIds = [
|
|
28298
|
+
...new Set(buildingsWithUnits.map((l) => l.building.toString()))
|
|
28299
|
+
].map((id) => new import_mongodb50.ObjectId(id));
|
|
28300
|
+
const result = await collection.aggregate([
|
|
28301
|
+
{
|
|
28302
|
+
$match: {
|
|
28303
|
+
_id: { $in: buildingIds }
|
|
28304
|
+
}
|
|
28305
|
+
},
|
|
28306
|
+
{
|
|
28307
|
+
$project: {
|
|
28308
|
+
name: 1
|
|
28309
|
+
}
|
|
28310
|
+
}
|
|
28311
|
+
]).toArray();
|
|
28312
|
+
return {
|
|
28313
|
+
success: true,
|
|
28314
|
+
message: "Buildings with units retrieved successfully",
|
|
28315
|
+
data: result
|
|
28316
|
+
};
|
|
28317
|
+
} catch (error) {
|
|
28318
|
+
if (error instanceof import_node_server_utils83.AppError) {
|
|
28319
|
+
throw error;
|
|
28320
|
+
} else {
|
|
28321
|
+
throw new import_node_server_utils83.InternalServerError("Failed to get buildings.");
|
|
28322
|
+
}
|
|
28323
|
+
}
|
|
28324
|
+
}
|
|
28263
28325
|
return {
|
|
28264
28326
|
createIndexes,
|
|
28265
28327
|
add,
|
|
@@ -28271,7 +28333,8 @@ function useBuildingRepo() {
|
|
|
28271
28333
|
getBuildingLevel,
|
|
28272
28334
|
getBuildingLevelForResident,
|
|
28273
28335
|
getBuildingLevelWithUnits,
|
|
28274
|
-
getBuildingList
|
|
28336
|
+
getBuildingList,
|
|
28337
|
+
getBuildingWithUnitsList
|
|
28275
28338
|
};
|
|
28276
28339
|
}
|
|
28277
28340
|
|
|
@@ -28707,7 +28770,7 @@ function useBuildingLevelRepo() {
|
|
|
28707
28770
|
if (error instanceof import_node_server_utils86.AppError) {
|
|
28708
28771
|
throw error;
|
|
28709
28772
|
} else {
|
|
28710
|
-
throw new import_node_server_utils86.InternalServerError("Failed to get building.");
|
|
28773
|
+
throw new import_node_server_utils86.InternalServerError("Failed to get building level.");
|
|
28711
28774
|
}
|
|
28712
28775
|
}
|
|
28713
28776
|
}
|
|
@@ -28991,7 +29054,8 @@ function useBuildingController() {
|
|
|
28991
29054
|
getBuildingLevel: _getBuildingLevel,
|
|
28992
29055
|
getBuildingLevelForResident: _getBuildingLevelForResident,
|
|
28993
29056
|
getBuildingLevelWithUnits: _getBuildingLevelWithUnits,
|
|
28994
|
-
getBuildingList: _getBuildingList
|
|
29057
|
+
getBuildingList: _getBuildingList,
|
|
29058
|
+
getBuildingWithUnitsList: _getBuildingWithUnitsList
|
|
28995
29059
|
} = useBuildingRepo();
|
|
28996
29060
|
const {
|
|
28997
29061
|
updateById: _updateById,
|
|
@@ -29378,6 +29442,28 @@ function useBuildingController() {
|
|
|
29378
29442
|
next(error);
|
|
29379
29443
|
}
|
|
29380
29444
|
}
|
|
29445
|
+
async function getBuildingWithUnitsList(req, res, next) {
|
|
29446
|
+
try {
|
|
29447
|
+
const schema2 = import_joi46.default.object({
|
|
29448
|
+
site: import_joi46.default.string().hex().length(24).required()
|
|
29449
|
+
});
|
|
29450
|
+
const { error, value } = schema2.validate({
|
|
29451
|
+
site: req.params.siteId
|
|
29452
|
+
});
|
|
29453
|
+
if (error) {
|
|
29454
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
29455
|
+
import_node_server_utils88.logger.log({ level: "error", message: messages });
|
|
29456
|
+
next(new import_node_server_utils88.BadRequestError(messages));
|
|
29457
|
+
return;
|
|
29458
|
+
}
|
|
29459
|
+
const { site } = value;
|
|
29460
|
+
const result = await _getBuildingWithUnitsList(site);
|
|
29461
|
+
res.json(result);
|
|
29462
|
+
return;
|
|
29463
|
+
} catch (error) {
|
|
29464
|
+
next(error);
|
|
29465
|
+
}
|
|
29466
|
+
}
|
|
29381
29467
|
return {
|
|
29382
29468
|
createBuilding,
|
|
29383
29469
|
getAll,
|
|
@@ -29389,7 +29475,8 @@ function useBuildingController() {
|
|
|
29389
29475
|
getBuildingLevelForResident,
|
|
29390
29476
|
uploadSpreadsheetBuilding,
|
|
29391
29477
|
getBuildingLevelWithUnits,
|
|
29392
|
-
getBuildingList
|
|
29478
|
+
getBuildingList,
|
|
29479
|
+
getBuildingWithUnitsList
|
|
29393
29480
|
};
|
|
29394
29481
|
}
|
|
29395
29482
|
|
|
@@ -34823,7 +34910,6 @@ function usePersonService() {
|
|
|
34823
34910
|
return "People added successfully.";
|
|
34824
34911
|
} catch (error) {
|
|
34825
34912
|
console.log("error message service", error);
|
|
34826
|
-
console.log("error message service", error.message);
|
|
34827
34913
|
import_node_server_utils111.logger.error("Error in people service add:", error);
|
|
34828
34914
|
await session.abortTransaction();
|
|
34829
34915
|
throw error;
|
|
@@ -34850,6 +34936,15 @@ function usePersonService() {
|
|
|
34850
34936
|
if (value.site && typeof value.site === "string") {
|
|
34851
34937
|
value.site = new import_mongodb65.ObjectId(value.site);
|
|
34852
34938
|
}
|
|
34939
|
+
if (value.block && typeof value.block === "string") {
|
|
34940
|
+
value.block = new import_mongodb65.ObjectId(value.block);
|
|
34941
|
+
}
|
|
34942
|
+
if (value.level && typeof value.level === "string") {
|
|
34943
|
+
value.level = new import_mongodb65.ObjectId(value.level);
|
|
34944
|
+
}
|
|
34945
|
+
if (value.unit && typeof value.unit === "string") {
|
|
34946
|
+
value.unit = new import_mongodb65.ObjectId(value.unit);
|
|
34947
|
+
}
|
|
34853
34948
|
const isOrgChanged = value.org && person.org?.toString() !== value.org.toString();
|
|
34854
34949
|
await _updateById(_id, value, session);
|
|
34855
34950
|
if (isOrgChanged && person.user) {
|