@7365admin1/core 3.48.1-staging.182 → 3.48.1-staging.183
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.js +180 -141
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +180 -141
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -33693,7 +33693,7 @@ function useBuildingUnitRepo() {
|
|
|
33693
33693
|
...site && { site: (0, import_node_server_utils97.toObjectId)(site) },
|
|
33694
33694
|
...building && { building: (0, import_node_server_utils97.toObjectId)(building) }
|
|
33695
33695
|
};
|
|
33696
|
-
sort = Object.keys(sort).length > 0 ? sort : { _id:
|
|
33696
|
+
sort = Object.keys(sort).length > 0 ? sort : { block: 1, "level.name": 1, name: 1, _id: 1 };
|
|
33697
33697
|
const cacheParams = {
|
|
33698
33698
|
page,
|
|
33699
33699
|
limit,
|
|
@@ -33757,38 +33757,44 @@ function useBuildingUnitRepo() {
|
|
|
33757
33757
|
}
|
|
33758
33758
|
] : []
|
|
33759
33759
|
];
|
|
33760
|
-
const items = await collection.aggregate(
|
|
33761
|
-
|
|
33762
|
-
|
|
33763
|
-
|
|
33764
|
-
|
|
33765
|
-
|
|
33766
|
-
|
|
33767
|
-
|
|
33768
|
-
|
|
33769
|
-
$
|
|
33770
|
-
|
|
33771
|
-
|
|
33772
|
-
|
|
33773
|
-
|
|
33774
|
-
|
|
33775
|
-
|
|
33776
|
-
|
|
33777
|
-
|
|
33778
|
-
|
|
33779
|
-
|
|
33780
|
-
|
|
33760
|
+
const items = await collection.aggregate(
|
|
33761
|
+
[
|
|
33762
|
+
...pipeline,
|
|
33763
|
+
{
|
|
33764
|
+
$lookup: {
|
|
33765
|
+
from: "sites",
|
|
33766
|
+
let: { siteId: "$site" },
|
|
33767
|
+
pipeline: [
|
|
33768
|
+
{
|
|
33769
|
+
$match: {
|
|
33770
|
+
$expr: { $eq: ["$_id", "$$siteId"] },
|
|
33771
|
+
status: "active" /* ACTIVE */
|
|
33772
|
+
}
|
|
33773
|
+
},
|
|
33774
|
+
{
|
|
33775
|
+
$project: {
|
|
33776
|
+
name: 1,
|
|
33777
|
+
description: 1,
|
|
33778
|
+
orgId: 1,
|
|
33779
|
+
metadata: 1,
|
|
33780
|
+
status: 1,
|
|
33781
|
+
address: 1
|
|
33782
|
+
}
|
|
33781
33783
|
}
|
|
33782
|
-
|
|
33783
|
-
|
|
33784
|
-
|
|
33785
|
-
}
|
|
33786
|
-
|
|
33787
|
-
|
|
33788
|
-
|
|
33789
|
-
|
|
33790
|
-
|
|
33791
|
-
|
|
33784
|
+
],
|
|
33785
|
+
as: "site"
|
|
33786
|
+
}
|
|
33787
|
+
},
|
|
33788
|
+
{ $set: { site: { $first: "$site" } } },
|
|
33789
|
+
{ $sort: sort },
|
|
33790
|
+
{ $skip: page * limit },
|
|
33791
|
+
{ $limit: limit }
|
|
33792
|
+
],
|
|
33793
|
+
// Sort units by block, then level name (natural: Lvl 2 before Lvl 10),
|
|
33794
|
+
// then unit name. Skip collation when a search regex is active (Mongo
|
|
33795
|
+
// rejects $regex + non-simple collation); browse view is what needs it.
|
|
33796
|
+
searchText ? {} : { collation: { locale: "en", numericOrdering: true } }
|
|
33797
|
+
).toArray();
|
|
33792
33798
|
const total = await collection.aggregate([...pipeline, { $count: "length" }]).toArray();
|
|
33793
33799
|
const length = total[0]?.length ?? 0;
|
|
33794
33800
|
const data = (0, import_node_server_utils97.paginate)(items, page, limit, length);
|
|
@@ -33827,7 +33833,7 @@ function useBuildingUnitRepo() {
|
|
|
33827
33833
|
...building && { building: (0, import_node_server_utils97.toObjectId)(building) },
|
|
33828
33834
|
...level && { level: (0, import_node_server_utils97.toObjectId)(level) }
|
|
33829
33835
|
};
|
|
33830
|
-
sort = Object.keys(sort).length > 0 ? sort : { _id:
|
|
33836
|
+
sort = Object.keys(sort).length > 0 ? sort : { block: 1, "level.name": 1, name: 1, _id: 1 };
|
|
33831
33837
|
const cacheParams = {
|
|
33832
33838
|
page,
|
|
33833
33839
|
limit,
|
|
@@ -33855,35 +33861,40 @@ function useBuildingUnitRepo() {
|
|
|
33855
33861
|
});
|
|
33856
33862
|
return cached;
|
|
33857
33863
|
}
|
|
33858
|
-
const items = await collection.aggregate(
|
|
33859
|
-
|
|
33860
|
-
|
|
33861
|
-
|
|
33862
|
-
|
|
33863
|
-
|
|
33864
|
-
|
|
33865
|
-
|
|
33866
|
-
|
|
33867
|
-
|
|
33868
|
-
|
|
33869
|
-
|
|
33870
|
-
|
|
33871
|
-
|
|
33872
|
-
|
|
33873
|
-
|
|
33874
|
-
|
|
33875
|
-
|
|
33876
|
-
|
|
33877
|
-
|
|
33878
|
-
|
|
33879
|
-
|
|
33880
|
-
|
|
33881
|
-
|
|
33882
|
-
|
|
33883
|
-
|
|
33884
|
-
|
|
33885
|
-
|
|
33886
|
-
|
|
33864
|
+
const items = await collection.aggregate(
|
|
33865
|
+
[
|
|
33866
|
+
{ $match: query2 },
|
|
33867
|
+
{
|
|
33868
|
+
$project: {
|
|
33869
|
+
site: 1,
|
|
33870
|
+
name: 1,
|
|
33871
|
+
building: 1,
|
|
33872
|
+
buildingName: 1,
|
|
33873
|
+
block: 1,
|
|
33874
|
+
level: 1,
|
|
33875
|
+
unitNumber: 1,
|
|
33876
|
+
createdAt: 1,
|
|
33877
|
+
updatedAt: 1
|
|
33878
|
+
}
|
|
33879
|
+
},
|
|
33880
|
+
{
|
|
33881
|
+
$lookup: {
|
|
33882
|
+
from: "building-levels",
|
|
33883
|
+
localField: "level",
|
|
33884
|
+
foreignField: "_id",
|
|
33885
|
+
pipeline: [{ $project: { name: 1 } }],
|
|
33886
|
+
as: "level"
|
|
33887
|
+
}
|
|
33888
|
+
},
|
|
33889
|
+
{ $set: { level: { $first: "$level" } } },
|
|
33890
|
+
{ $sort: sort },
|
|
33891
|
+
{ $skip: page * limit },
|
|
33892
|
+
{ $limit: limit }
|
|
33893
|
+
],
|
|
33894
|
+
// Natural sort by block, level name, unit name. Skip collation when a
|
|
33895
|
+
// $text search is active (Mongo rejects the combo); browse view needs it.
|
|
33896
|
+
search ? {} : { collation: { locale: "en", numericOrdering: true } }
|
|
33897
|
+
).toArray();
|
|
33887
33898
|
const length = await collection.countDocuments(query2);
|
|
33888
33899
|
const data = (0, import_node_server_utils97.paginate)(items, page, limit, length);
|
|
33889
33900
|
setCache(cacheKey, data, 600).then(() => {
|
|
@@ -36064,7 +36075,7 @@ function useBuildingRepo() {
|
|
|
36064
36075
|
]
|
|
36065
36076
|
}
|
|
36066
36077
|
};
|
|
36067
|
-
sort = Object.keys(sort).length ? sort : { _id:
|
|
36078
|
+
sort = Object.keys(sort).length ? sort : { name: 1, _id: 1 };
|
|
36068
36079
|
const cacheParams = {
|
|
36069
36080
|
page,
|
|
36070
36081
|
limit,
|
|
@@ -36087,36 +36098,44 @@ function useBuildingRepo() {
|
|
|
36087
36098
|
});
|
|
36088
36099
|
return cached;
|
|
36089
36100
|
}
|
|
36090
|
-
const items = await collection.aggregate(
|
|
36091
|
-
|
|
36092
|
-
|
|
36093
|
-
|
|
36094
|
-
|
|
36095
|
-
|
|
36096
|
-
|
|
36097
|
-
|
|
36098
|
-
|
|
36099
|
-
pipeline: [
|
|
36100
|
-
{
|
|
36101
|
-
$match: {
|
|
36102
|
-
status: "active" /* ACTIVE */,
|
|
36103
|
-
$expr: {
|
|
36104
|
-
$or: [
|
|
36105
|
-
{ $in: ["$_id", "$$buildingLevelIds"] },
|
|
36106
|
-
{ $eq: ["$blockId", "$$buildingId"] }
|
|
36107
|
-
]
|
|
36108
|
-
}
|
|
36109
|
-
}
|
|
36101
|
+
const items = await collection.aggregate(
|
|
36102
|
+
[
|
|
36103
|
+
{ $match: query2 },
|
|
36104
|
+
{
|
|
36105
|
+
$lookup: {
|
|
36106
|
+
from: "building-levels",
|
|
36107
|
+
let: {
|
|
36108
|
+
buildingId: "$_id",
|
|
36109
|
+
buildingLevelIds: { $ifNull: ["$levels", []] }
|
|
36110
36110
|
},
|
|
36111
|
-
|
|
36112
|
-
|
|
36113
|
-
|
|
36114
|
-
|
|
36115
|
-
|
|
36116
|
-
|
|
36117
|
-
|
|
36118
|
-
|
|
36119
|
-
|
|
36111
|
+
pipeline: [
|
|
36112
|
+
{
|
|
36113
|
+
$match: {
|
|
36114
|
+
status: "active" /* ACTIVE */,
|
|
36115
|
+
$expr: {
|
|
36116
|
+
$or: [
|
|
36117
|
+
{ $in: ["$_id", "$$buildingLevelIds"] },
|
|
36118
|
+
{ $eq: ["$blockId", "$$buildingId"] }
|
|
36119
|
+
]
|
|
36120
|
+
}
|
|
36121
|
+
}
|
|
36122
|
+
},
|
|
36123
|
+
{ $project: { _id: 1, name: 1 } },
|
|
36124
|
+
{ $sort: { name: 1 } }
|
|
36125
|
+
],
|
|
36126
|
+
as: "levels"
|
|
36127
|
+
}
|
|
36128
|
+
},
|
|
36129
|
+
{ $sort: sort },
|
|
36130
|
+
{ $skip: page * limit },
|
|
36131
|
+
{ $limit: limit }
|
|
36132
|
+
],
|
|
36133
|
+
// numericOrdering => natural order (Blk 2 < Blk 100 < Blk 165, and
|
|
36134
|
+
// levels Lvl 2 before Lvl 10). Skip collation when a $text search is
|
|
36135
|
+
// active (Mongo rejects the combo); the default browse view is what
|
|
36136
|
+
// needs the natural ordering.
|
|
36137
|
+
searchText ? {} : { collation: { locale: "en", numericOrdering: true } }
|
|
36138
|
+
).toArray();
|
|
36120
36139
|
const length = await collection.countDocuments(query2);
|
|
36121
36140
|
const data = (0, import_node_server_utils104.paginate)(items, page, limit, length);
|
|
36122
36141
|
setCache(cacheKey, data, 600).then(() => {
|
|
@@ -36465,18 +36484,25 @@ function useBuildingRepo() {
|
|
|
36465
36484
|
const cacheOptions = { ...query2 };
|
|
36466
36485
|
const cacheKey = (0, import_node_server_utils104.makeCacheKey)(buildings_namespace_collection, cacheOptions);
|
|
36467
36486
|
try {
|
|
36468
|
-
const result = await collection.aggregate(
|
|
36469
|
-
|
|
36470
|
-
|
|
36471
|
-
|
|
36472
|
-
|
|
36473
|
-
|
|
36474
|
-
|
|
36475
|
-
|
|
36476
|
-
|
|
36477
|
-
|
|
36478
|
-
|
|
36479
|
-
|
|
36487
|
+
const result = await collection.aggregate(
|
|
36488
|
+
[
|
|
36489
|
+
{
|
|
36490
|
+
$match: {
|
|
36491
|
+
...query2
|
|
36492
|
+
}
|
|
36493
|
+
},
|
|
36494
|
+
{
|
|
36495
|
+
$project: {
|
|
36496
|
+
name: 1
|
|
36497
|
+
}
|
|
36498
|
+
},
|
|
36499
|
+
{ $sort: { name: 1, _id: 1 } }
|
|
36500
|
+
],
|
|
36501
|
+
// numericOrdering => natural order in the block dropdowns
|
|
36502
|
+
// (Blk 2 < Blk 10 < Blk 165). No search branch here, so collation
|
|
36503
|
+
// always applies.
|
|
36504
|
+
{ collation: { locale: "en", numericOrdering: true } }
|
|
36505
|
+
).toArray();
|
|
36480
36506
|
return {
|
|
36481
36507
|
success: true,
|
|
36482
36508
|
message: "Buildings retrieved successfully",
|
|
@@ -36641,6 +36667,9 @@ function useBuildingLevelRepo() {
|
|
|
36641
36667
|
const { delNamespace: delBuildingNamespace } = (0, import_node_server_utils107.useCache)(
|
|
36642
36668
|
buildings_namespace_collection
|
|
36643
36669
|
);
|
|
36670
|
+
const { delNamespace: delUnitNamespace } = (0, import_node_server_utils107.useCache)(
|
|
36671
|
+
building_units_namespace_collection
|
|
36672
|
+
);
|
|
36644
36673
|
async function createIndexes() {
|
|
36645
36674
|
try {
|
|
36646
36675
|
await collection.createIndexes([
|
|
@@ -36680,6 +36709,12 @@ function useBuildingLevelRepo() {
|
|
|
36680
36709
|
message: `Failed to clear buildings cache: ${err.message}`
|
|
36681
36710
|
});
|
|
36682
36711
|
});
|
|
36712
|
+
delUnitNamespace().catch((err) => {
|
|
36713
|
+
import_node_server_utils107.logger.log({
|
|
36714
|
+
level: "error",
|
|
36715
|
+
message: `Failed to clear building-units cache: ${err.message}`
|
|
36716
|
+
});
|
|
36717
|
+
});
|
|
36683
36718
|
}
|
|
36684
36719
|
async function add(value, session) {
|
|
36685
36720
|
try {
|
|
@@ -36742,19 +36777,25 @@ function useBuildingLevelRepo() {
|
|
|
36742
36777
|
});
|
|
36743
36778
|
return cached;
|
|
36744
36779
|
}
|
|
36745
|
-
const sortStage = Object.keys(sort).length > 0 ? { $sort: sort } : { $sort: {
|
|
36746
|
-
const items = await collection.aggregate(
|
|
36747
|
-
|
|
36748
|
-
|
|
36749
|
-
|
|
36750
|
-
|
|
36751
|
-
|
|
36752
|
-
|
|
36753
|
-
|
|
36754
|
-
|
|
36755
|
-
|
|
36756
|
-
|
|
36757
|
-
|
|
36780
|
+
const sortStage = Object.keys(sort).length > 0 ? { $sort: sort } : { $sort: { name: 1 } };
|
|
36781
|
+
const items = await collection.aggregate(
|
|
36782
|
+
[
|
|
36783
|
+
{ $match: query2 },
|
|
36784
|
+
{
|
|
36785
|
+
$addFields: {
|
|
36786
|
+
latestDate: { $max: ["$updatedAt", "$createdAt"] }
|
|
36787
|
+
}
|
|
36788
|
+
},
|
|
36789
|
+
sortStage,
|
|
36790
|
+
{ $unset: "latestDate" },
|
|
36791
|
+
{ $skip: page * limit },
|
|
36792
|
+
{ $limit: limit }
|
|
36793
|
+
],
|
|
36794
|
+
// numericOrdering gives natural order (Lvl 2 before Lvl 10). Skip
|
|
36795
|
+
// collation when a $text search is active (Mongo rejects the combo);
|
|
36796
|
+
// ordering matters for the default browse list.
|
|
36797
|
+
search ? {} : { collation: { locale: "en", numericOrdering: true } }
|
|
36798
|
+
).toArray();
|
|
36758
36799
|
const length = await collection.countDocuments(query2);
|
|
36759
36800
|
const data = (0, import_node_server_utils107.paginate)(items, page, limit, length);
|
|
36760
36801
|
setCache(cacheKey, data, 600).then(() => {
|
|
@@ -37027,18 +37068,22 @@ function useBuildingLevelRepo() {
|
|
|
37027
37068
|
const levelIds = [
|
|
37028
37069
|
...new Set(levelsWithUnits.map((l) => l.level.toString()))
|
|
37029
37070
|
].map((id) => new import_mongodb70.ObjectId(id));
|
|
37030
|
-
const result = await collection.aggregate(
|
|
37031
|
-
|
|
37032
|
-
|
|
37033
|
-
|
|
37034
|
-
|
|
37035
|
-
|
|
37036
|
-
|
|
37037
|
-
|
|
37038
|
-
|
|
37039
|
-
|
|
37040
|
-
|
|
37041
|
-
|
|
37071
|
+
const result = await collection.aggregate(
|
|
37072
|
+
[
|
|
37073
|
+
{
|
|
37074
|
+
$match: {
|
|
37075
|
+
_id: { $in: levelIds }
|
|
37076
|
+
}
|
|
37077
|
+
},
|
|
37078
|
+
{
|
|
37079
|
+
$project: {
|
|
37080
|
+
name: 1
|
|
37081
|
+
}
|
|
37082
|
+
},
|
|
37083
|
+
{ $sort: { name: 1 } }
|
|
37084
|
+
],
|
|
37085
|
+
{ collation: { locale: "en", numericOrdering: true } }
|
|
37086
|
+
).toArray();
|
|
37042
37087
|
return {
|
|
37043
37088
|
success: true,
|
|
37044
37089
|
message: "Building levels retrieved successfully",
|
|
@@ -37679,7 +37724,7 @@ function useBuildingController() {
|
|
|
37679
37724
|
search: import_joi53.default.string().optional().allow("", null),
|
|
37680
37725
|
site: import_joi53.default.string().hex().optional().allow("", null),
|
|
37681
37726
|
status: import_joi53.default.string().valid(...Object.values(BuildingStatus)).default("active" /* ACTIVE */),
|
|
37682
|
-
sort: import_joi53.default.string().valid(...Object.values(SortFields)).
|
|
37727
|
+
sort: import_joi53.default.string().valid(...Object.values(SortFields)).optional(),
|
|
37683
37728
|
order: import_joi53.default.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */)
|
|
37684
37729
|
});
|
|
37685
37730
|
const { error, value } = validation.validate(query2);
|
|
@@ -37694,9 +37739,7 @@ function useBuildingController() {
|
|
|
37694
37739
|
const status = value.status;
|
|
37695
37740
|
const site = value.site ?? "";
|
|
37696
37741
|
const search = value.search ?? "";
|
|
37697
|
-
const sortObj = {
|
|
37698
|
-
[sort]: order === "asc" /* ASC */ ? 1 : -1
|
|
37699
|
-
};
|
|
37742
|
+
const sortObj = sort ? { [sort]: order === "asc" /* ASC */ ? 1 : -1 } : {};
|
|
37700
37743
|
try {
|
|
37701
37744
|
const buildings = await _getAll({
|
|
37702
37745
|
page,
|
|
@@ -38311,7 +38354,7 @@ function useBuildingUnitController() {
|
|
|
38311
38354
|
site: import_joi54.default.string().hex().length(24).optional().allow("", null),
|
|
38312
38355
|
building: import_joi54.default.string().hex().optional().allow("", null),
|
|
38313
38356
|
status: import_joi54.default.string().valid(...Object.values(BuildingStatus)).default("active" /* ACTIVE */),
|
|
38314
|
-
sort: import_joi54.default.string().valid(...Object.values(SortFields)).
|
|
38357
|
+
sort: import_joi54.default.string().valid(...Object.values(SortFields)).optional(),
|
|
38315
38358
|
order: import_joi54.default.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */)
|
|
38316
38359
|
});
|
|
38317
38360
|
const query2 = {
|
|
@@ -38332,9 +38375,7 @@ function useBuildingUnitController() {
|
|
|
38332
38375
|
const sort = value.sort;
|
|
38333
38376
|
const order = value.order;
|
|
38334
38377
|
const status = value.status;
|
|
38335
|
-
const sortObj = {
|
|
38336
|
-
[sort]: order === "asc" /* ASC */ ? -1 : 1
|
|
38337
|
-
};
|
|
38378
|
+
const sortObj = sort ? { [sort]: order === "asc" /* ASC */ ? -1 : 1 } : {};
|
|
38338
38379
|
const site = value.site;
|
|
38339
38380
|
const building = value.building;
|
|
38340
38381
|
const search = value.search;
|
|
@@ -38477,7 +38518,7 @@ function useBuildingUnitController() {
|
|
|
38477
38518
|
site: import_joi54.default.string().hex().length(24).optional().allow("", null),
|
|
38478
38519
|
building: import_joi54.default.string().hex().optional().allow("", null),
|
|
38479
38520
|
status: import_joi54.default.string().valid(...Object.values(BuildingStatus)).default("active" /* ACTIVE */),
|
|
38480
|
-
sort: import_joi54.default.string().valid(...Object.values(SortFields)).
|
|
38521
|
+
sort: import_joi54.default.string().valid(...Object.values(SortFields)).optional(),
|
|
38481
38522
|
order: import_joi54.default.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */),
|
|
38482
38523
|
level: import_joi54.default.string().hex().length(24).optional().allow(null, "")
|
|
38483
38524
|
});
|
|
@@ -38499,9 +38540,7 @@ function useBuildingUnitController() {
|
|
|
38499
38540
|
const sort = value.sort;
|
|
38500
38541
|
const order = value.order;
|
|
38501
38542
|
const status = value.status;
|
|
38502
|
-
const sortObj = {
|
|
38503
|
-
[sort]: order === "asc" /* ASC */ ? -1 : 1
|
|
38504
|
-
};
|
|
38543
|
+
const sortObj = sort ? { [sort]: order === "asc" /* ASC */ ? -1 : 1 } : {};
|
|
38505
38544
|
const site = value.site;
|
|
38506
38545
|
const building = value.building;
|
|
38507
38546
|
const search = value.search;
|