@7365admin1/core 2.53.0 → 2.55.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 +17 -1
- package/dist/index.js +440 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +439 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4114,12 +4114,13 @@ function useOrgRepo() {
|
|
|
4114
4114
|
status = "active",
|
|
4115
4115
|
nature = ""
|
|
4116
4116
|
}) {
|
|
4117
|
-
page = page > 0 ? page - 1 : 0;
|
|
4118
4117
|
const query = { status };
|
|
4119
4118
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
4120
4119
|
const cacheOptions = {
|
|
4121
4120
|
status,
|
|
4122
|
-
sort
|
|
4121
|
+
sort,
|
|
4122
|
+
page,
|
|
4123
|
+
limit
|
|
4123
4124
|
};
|
|
4124
4125
|
if (search) {
|
|
4125
4126
|
query.$text = { $search: search };
|
|
@@ -4135,11 +4136,12 @@ function useOrgRepo() {
|
|
|
4135
4136
|
logger10.info(`Cache hit for key: ${cacheKey}`);
|
|
4136
4137
|
return cachedData;
|
|
4137
4138
|
}
|
|
4139
|
+
const normalizedPage = page > 0 ? page - 1 : 0;
|
|
4138
4140
|
try {
|
|
4139
4141
|
const items = await collection.aggregate([
|
|
4140
4142
|
{ $match: query },
|
|
4141
4143
|
{ $sort: sort },
|
|
4142
|
-
{ $skip:
|
|
4144
|
+
{ $skip: normalizedPage * limit },
|
|
4143
4145
|
{ $limit: limit },
|
|
4144
4146
|
{
|
|
4145
4147
|
$project: {
|
|
@@ -4153,7 +4155,7 @@ function useOrgRepo() {
|
|
|
4153
4155
|
}
|
|
4154
4156
|
]).toArray();
|
|
4155
4157
|
const length = await collection.countDocuments(query);
|
|
4156
|
-
const data = paginate7(items,
|
|
4158
|
+
const data = paginate7(items, normalizedPage, limit, length);
|
|
4157
4159
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
4158
4160
|
logger10.info(`Cache set for key: ${cacheKey}`);
|
|
4159
4161
|
}).catch((err) => {
|
|
@@ -5310,11 +5312,16 @@ function useVerificationService() {
|
|
|
5310
5312
|
const existing = await useVerificationRepo().findOne({
|
|
5311
5313
|
type,
|
|
5312
5314
|
email,
|
|
5313
|
-
"metadata.
|
|
5314
|
-
"metadata.siteId": metadata?.siteId
|
|
5315
|
+
"metadata.app": metadata.app
|
|
5315
5316
|
});
|
|
5316
|
-
if (existing)
|
|
5317
|
+
if (existing) {
|
|
5318
|
+
if (existing.status === "complete") {
|
|
5319
|
+
throw new BadRequestError20(
|
|
5320
|
+
`User already completed invite for app: ${metadata.app}`
|
|
5321
|
+
);
|
|
5322
|
+
}
|
|
5317
5323
|
return existing._id;
|
|
5324
|
+
}
|
|
5318
5325
|
const value = {
|
|
5319
5326
|
type,
|
|
5320
5327
|
email,
|
|
@@ -7571,6 +7578,7 @@ function useVerificationController() {
|
|
|
7571
7578
|
createServiceProviderInvite: _createServiceProviderInvite,
|
|
7572
7579
|
createForgetPassword: _createForgetPassword,
|
|
7573
7580
|
verify: _verify,
|
|
7581
|
+
updateStatusById: _updateStatusById,
|
|
7574
7582
|
cancelUserInvitation: _cancelUserInvitation
|
|
7575
7583
|
} = useVerificationService();
|
|
7576
7584
|
const { getVerifications: _getVerifications } = useVerificationRepo();
|
|
@@ -7784,6 +7792,28 @@ function useVerificationController() {
|
|
|
7784
7792
|
return;
|
|
7785
7793
|
}
|
|
7786
7794
|
}
|
|
7795
|
+
async function updateVerificationStatus(req, res, next) {
|
|
7796
|
+
const validation = Joi16.object({
|
|
7797
|
+
id: Joi16.string().hex().required(),
|
|
7798
|
+
status: Joi16.string().valid("pending", "complete", "expired", "cancelled").required()
|
|
7799
|
+
});
|
|
7800
|
+
const { error } = validation.validate(req.body);
|
|
7801
|
+
if (error) {
|
|
7802
|
+
logger22.log({ level: "error", message: error.message });
|
|
7803
|
+
next(new BadRequestError31(error.message));
|
|
7804
|
+
return;
|
|
7805
|
+
}
|
|
7806
|
+
try {
|
|
7807
|
+
const { id, status } = req.body;
|
|
7808
|
+
const result = await _updateStatusById(id, status);
|
|
7809
|
+
res.json({ message: result });
|
|
7810
|
+
return;
|
|
7811
|
+
} catch (error2) {
|
|
7812
|
+
logger22.log({ level: "error", message: error2.message });
|
|
7813
|
+
next(error2);
|
|
7814
|
+
return;
|
|
7815
|
+
}
|
|
7816
|
+
}
|
|
7787
7817
|
async function cancelUserInvitation(req, res, next) {
|
|
7788
7818
|
const validation = Joi16.string().hex().required();
|
|
7789
7819
|
const otpId = req.params.id;
|
|
@@ -7811,6 +7841,7 @@ function useVerificationController() {
|
|
|
7811
7841
|
createServiceProviderInvite,
|
|
7812
7842
|
createForgetPassword,
|
|
7813
7843
|
verify,
|
|
7844
|
+
updateVerificationStatus,
|
|
7814
7845
|
cancelUserInvitation,
|
|
7815
7846
|
createSimpleUserInvite
|
|
7816
7847
|
};
|
|
@@ -13708,9 +13739,26 @@ function useVisitorTransactionRepo() {
|
|
|
13708
13739
|
...status && { status },
|
|
13709
13740
|
...tab == "Overnight Parking" && { isOvernightParking: true }
|
|
13710
13741
|
};
|
|
13711
|
-
sort = Object.keys(sort).length > 0 ? sort : {
|
|
13742
|
+
sort = Object.keys(sort).length > 0 ? sort : { latestDate: -1 };
|
|
13712
13743
|
try {
|
|
13713
|
-
const basePipeline = [
|
|
13744
|
+
const basePipeline = [
|
|
13745
|
+
{ $match: query },
|
|
13746
|
+
{
|
|
13747
|
+
$addFields: {
|
|
13748
|
+
latestDate: {
|
|
13749
|
+
$max: ["$createdAt", "$updatedAt"]
|
|
13750
|
+
}
|
|
13751
|
+
}
|
|
13752
|
+
},
|
|
13753
|
+
{ $sort: { latestDate: -1 } },
|
|
13754
|
+
{ $skip: skip },
|
|
13755
|
+
{ $limit: limit },
|
|
13756
|
+
{
|
|
13757
|
+
$project: {
|
|
13758
|
+
latestDate: 0
|
|
13759
|
+
}
|
|
13760
|
+
}
|
|
13761
|
+
];
|
|
13714
13762
|
const [items, countResult] = await Promise.all([
|
|
13715
13763
|
collection.aggregate([
|
|
13716
13764
|
...basePipeline,
|
|
@@ -13850,9 +13898,6 @@ function useVisitorTransactionRepo() {
|
|
|
13850
13898
|
as: "passKeys"
|
|
13851
13899
|
}
|
|
13852
13900
|
},
|
|
13853
|
-
{ $sort: sort },
|
|
13854
|
-
{ $skip: skip },
|
|
13855
|
-
{ $limit: limit },
|
|
13856
13901
|
{
|
|
13857
13902
|
$lookup: {
|
|
13858
13903
|
from: "users",
|
|
@@ -15863,14 +15908,16 @@ function MBuildingUnit(value) {
|
|
|
15863
15908
|
|
|
15864
15909
|
// src/repositories/building-unit.repository.ts
|
|
15865
15910
|
import { ObjectId as ObjectId45 } from "mongodb";
|
|
15911
|
+
var building_units_namespace_collection = "building-units";
|
|
15866
15912
|
function useBuildingUnitRepo() {
|
|
15867
15913
|
const db = useAtlas33.getDb();
|
|
15868
15914
|
if (!db) {
|
|
15869
15915
|
throw new Error("Unable to connect to server.");
|
|
15870
15916
|
}
|
|
15871
|
-
const
|
|
15872
|
-
const
|
|
15873
|
-
|
|
15917
|
+
const collection = db.collection(building_units_namespace_collection);
|
|
15918
|
+
const { getCache, setCache, delNamespace, delCache } = useCache25(
|
|
15919
|
+
building_units_namespace_collection
|
|
15920
|
+
);
|
|
15874
15921
|
async function createIndexes() {
|
|
15875
15922
|
try {
|
|
15876
15923
|
await collection.createIndexes([
|
|
@@ -15896,12 +15943,12 @@ function useBuildingUnitRepo() {
|
|
|
15896
15943
|
delNamespace().then(() => {
|
|
15897
15944
|
logger52.log({
|
|
15898
15945
|
level: "info",
|
|
15899
|
-
message: `Cache namespace cleared for ${
|
|
15946
|
+
message: `Cache namespace cleared for ${building_units_namespace_collection}`
|
|
15900
15947
|
});
|
|
15901
15948
|
}).catch((err) => {
|
|
15902
15949
|
logger52.log({
|
|
15903
15950
|
level: "error",
|
|
15904
|
-
message: `Failed to clear cache namespace for ${
|
|
15951
|
+
message: `Failed to clear cache namespace for ${building_units_namespace_collection}: ${err.message}`
|
|
15905
15952
|
});
|
|
15906
15953
|
});
|
|
15907
15954
|
}
|
|
@@ -16048,7 +16095,10 @@ function useBuildingUnitRepo() {
|
|
|
16048
16095
|
...building && { building },
|
|
16049
16096
|
...status && { status }
|
|
16050
16097
|
};
|
|
16051
|
-
const cacheKey = makeCacheKey24(
|
|
16098
|
+
const cacheKey = makeCacheKey24(
|
|
16099
|
+
building_units_namespace_collection,
|
|
16100
|
+
cacheParams
|
|
16101
|
+
);
|
|
16052
16102
|
logger52.log({
|
|
16053
16103
|
level: "info",
|
|
16054
16104
|
message: `Cache key for getAll building units: ${cacheKey}`
|
|
@@ -16119,7 +16169,9 @@ function useBuildingUnitRepo() {
|
|
|
16119
16169
|
} catch (error) {
|
|
16120
16170
|
throw new BadRequestError71("Invalid ID.");
|
|
16121
16171
|
}
|
|
16122
|
-
const cacheKey = makeCacheKey24(
|
|
16172
|
+
const cacheKey = makeCacheKey24(building_units_namespace_collection, {
|
|
16173
|
+
_id: String(_id)
|
|
16174
|
+
});
|
|
16123
16175
|
try {
|
|
16124
16176
|
const cached = await getCache(cacheKey);
|
|
16125
16177
|
if (cached) {
|
|
@@ -16162,7 +16214,7 @@ function useBuildingUnitRepo() {
|
|
|
16162
16214
|
} catch (error) {
|
|
16163
16215
|
throw new BadRequestError71("Invalid building ID.");
|
|
16164
16216
|
}
|
|
16165
|
-
const cacheKey = makeCacheKey24(
|
|
16217
|
+
const cacheKey = makeCacheKey24(building_units_namespace_collection, {
|
|
16166
16218
|
building: String(building),
|
|
16167
16219
|
level
|
|
16168
16220
|
});
|
|
@@ -16236,7 +16288,7 @@ function useBuildingUnitRepo() {
|
|
|
16236
16288
|
} catch (error) {
|
|
16237
16289
|
throw new BadRequestError71("Invalid building ID.");
|
|
16238
16290
|
}
|
|
16239
|
-
const cacheKey = makeCacheKey24(
|
|
16291
|
+
const cacheKey = makeCacheKey24(building_units_namespace_collection, {
|
|
16240
16292
|
building: String(building)
|
|
16241
16293
|
});
|
|
16242
16294
|
try {
|
|
@@ -16310,7 +16362,10 @@ function useBuildingUnitRepo() {
|
|
|
16310
16362
|
block,
|
|
16311
16363
|
level
|
|
16312
16364
|
};
|
|
16313
|
-
const cacheKey = makeCacheKey24(
|
|
16365
|
+
const cacheKey = makeCacheKey24(
|
|
16366
|
+
building_units_namespace_collection,
|
|
16367
|
+
cacheOptions
|
|
16368
|
+
);
|
|
16314
16369
|
const cachedData = await getCache(cacheKey);
|
|
16315
16370
|
if (cachedData) {
|
|
16316
16371
|
logger52.info(`Cache hit for key: ${cacheKey}`);
|
|
@@ -16348,7 +16403,10 @@ function useBuildingUnitRepo() {
|
|
|
16348
16403
|
const cacheOptions = {
|
|
16349
16404
|
site: site.toString()
|
|
16350
16405
|
};
|
|
16351
|
-
const cacheKey = makeCacheKey24(
|
|
16406
|
+
const cacheKey = makeCacheKey24(
|
|
16407
|
+
building_units_namespace_collection,
|
|
16408
|
+
cacheOptions
|
|
16409
|
+
);
|
|
16352
16410
|
const cachedData = await getCache(cacheKey);
|
|
16353
16411
|
if (cachedData) {
|
|
16354
16412
|
logger52.info(`Cache hit for key: ${cacheKey}`);
|
|
@@ -16396,7 +16454,10 @@ function useBuildingUnitRepo() {
|
|
|
16396
16454
|
{ deletedAt: "" }
|
|
16397
16455
|
]
|
|
16398
16456
|
};
|
|
16399
|
-
const cacheKey = makeCacheKey24(
|
|
16457
|
+
const cacheKey = makeCacheKey24(
|
|
16458
|
+
building_units_namespace_collection,
|
|
16459
|
+
cacheOptions
|
|
16460
|
+
);
|
|
16400
16461
|
try {
|
|
16401
16462
|
const cached = await getCache(cacheKey);
|
|
16402
16463
|
if (cached) {
|
|
@@ -16432,6 +16493,54 @@ function useBuildingUnitRepo() {
|
|
|
16432
16493
|
}
|
|
16433
16494
|
}
|
|
16434
16495
|
}
|
|
16496
|
+
async function getBySiteBuildingLevel(site, block, level) {
|
|
16497
|
+
try {
|
|
16498
|
+
site = new ObjectId45(site);
|
|
16499
|
+
} catch (error) {
|
|
16500
|
+
throw new BadRequestError71("Invalid site ID.");
|
|
16501
|
+
}
|
|
16502
|
+
const cacheKey = makeCacheKey24(building_units_namespace_collection, {
|
|
16503
|
+
site: site.toString(),
|
|
16504
|
+
block,
|
|
16505
|
+
level
|
|
16506
|
+
});
|
|
16507
|
+
try {
|
|
16508
|
+
const cached = await getCache(cacheKey);
|
|
16509
|
+
if (cached) {
|
|
16510
|
+
logger52.log({
|
|
16511
|
+
level: "info",
|
|
16512
|
+
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
16513
|
+
});
|
|
16514
|
+
return cached;
|
|
16515
|
+
}
|
|
16516
|
+
const query = {
|
|
16517
|
+
site,
|
|
16518
|
+
block,
|
|
16519
|
+
level,
|
|
16520
|
+
status: "active"
|
|
16521
|
+
};
|
|
16522
|
+
console.log(query);
|
|
16523
|
+
const result = await collection.findOne(query);
|
|
16524
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
16525
|
+
logger52.log({
|
|
16526
|
+
level: "info",
|
|
16527
|
+
message: `Cache set for building unit by id: ${cacheKey}`
|
|
16528
|
+
});
|
|
16529
|
+
}).catch((err) => {
|
|
16530
|
+
logger52.log({
|
|
16531
|
+
level: "error",
|
|
16532
|
+
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
16533
|
+
});
|
|
16534
|
+
});
|
|
16535
|
+
return result;
|
|
16536
|
+
} catch (error) {
|
|
16537
|
+
if (error instanceof AppError10) {
|
|
16538
|
+
throw error;
|
|
16539
|
+
} else {
|
|
16540
|
+
throw new InternalServerError27("Failed to get building unit.");
|
|
16541
|
+
}
|
|
16542
|
+
}
|
|
16543
|
+
}
|
|
16435
16544
|
return {
|
|
16436
16545
|
createIndexes,
|
|
16437
16546
|
add,
|
|
@@ -16445,7 +16554,8 @@ function useBuildingUnitRepo() {
|
|
|
16445
16554
|
updateByBuildingId,
|
|
16446
16555
|
getBuildingUnits,
|
|
16447
16556
|
getBuildingUnitsWithOwner,
|
|
16448
|
-
getUnitByBlockLevelUnitNumber
|
|
16557
|
+
getUnitByBlockLevelUnitNumber,
|
|
16558
|
+
getBySiteBuildingLevel
|
|
16449
16559
|
};
|
|
16450
16560
|
}
|
|
16451
16561
|
|
|
@@ -19121,6 +19231,7 @@ function useBuildingRepo() {
|
|
|
19121
19231
|
throw new Error("Failed to create index on buildings. " + error.message);
|
|
19122
19232
|
}
|
|
19123
19233
|
}
|
|
19234
|
+
const { getBySiteBuildingLevel: _getBySiteBuildingLevel } = useBuildingUnitRepo();
|
|
19124
19235
|
async function add(value, session) {
|
|
19125
19236
|
try {
|
|
19126
19237
|
value = MBuilding(value);
|
|
@@ -19356,6 +19467,94 @@ function useBuildingRepo() {
|
|
|
19356
19467
|
}
|
|
19357
19468
|
}
|
|
19358
19469
|
}
|
|
19470
|
+
async function getBuildingLevelWithUnits(site, block) {
|
|
19471
|
+
try {
|
|
19472
|
+
site = new ObjectId49(site);
|
|
19473
|
+
} catch (error) {
|
|
19474
|
+
throw new BadRequestError79("Invalid ID.");
|
|
19475
|
+
}
|
|
19476
|
+
const query = {
|
|
19477
|
+
site,
|
|
19478
|
+
_id: new ObjectId49(block)
|
|
19479
|
+
};
|
|
19480
|
+
const cacheOptions = { ...query };
|
|
19481
|
+
const cacheKey = makeCacheKey26(buildings_namespace_collection, cacheOptions);
|
|
19482
|
+
try {
|
|
19483
|
+
console.log(query);
|
|
19484
|
+
const result = await collection.aggregate([
|
|
19485
|
+
{
|
|
19486
|
+
$match: {
|
|
19487
|
+
...query
|
|
19488
|
+
}
|
|
19489
|
+
},
|
|
19490
|
+
{
|
|
19491
|
+
$lookup: {
|
|
19492
|
+
from: "building-levels",
|
|
19493
|
+
let: { buildingId: "$_id" },
|
|
19494
|
+
pipeline: [
|
|
19495
|
+
{
|
|
19496
|
+
$match: {
|
|
19497
|
+
$expr: { $eq: ["$block", "$$buildingId"] }
|
|
19498
|
+
}
|
|
19499
|
+
},
|
|
19500
|
+
{
|
|
19501
|
+
$lookup: {
|
|
19502
|
+
from: "building-units",
|
|
19503
|
+
let: { levelId: "$_id" },
|
|
19504
|
+
pipeline: [
|
|
19505
|
+
{
|
|
19506
|
+
$match: {
|
|
19507
|
+
$expr: {
|
|
19508
|
+
$and: [
|
|
19509
|
+
{ $eq: ["$site", site] },
|
|
19510
|
+
{ $eq: ["$block", "$$buildingId"] },
|
|
19511
|
+
{ $eq: ["$level", "$$levelId"] },
|
|
19512
|
+
{ $eq: ["$status", "active"] }
|
|
19513
|
+
]
|
|
19514
|
+
}
|
|
19515
|
+
}
|
|
19516
|
+
}
|
|
19517
|
+
],
|
|
19518
|
+
as: "buildingUnits"
|
|
19519
|
+
}
|
|
19520
|
+
},
|
|
19521
|
+
// discard levels that have no active units
|
|
19522
|
+
{
|
|
19523
|
+
$match: {
|
|
19524
|
+
$expr: { $gt: [{ $size: "$buildingUnits" }, 0] }
|
|
19525
|
+
}
|
|
19526
|
+
}
|
|
19527
|
+
],
|
|
19528
|
+
as: "buildingLevels"
|
|
19529
|
+
}
|
|
19530
|
+
},
|
|
19531
|
+
{
|
|
19532
|
+
$project: {
|
|
19533
|
+
"_id": 1,
|
|
19534
|
+
"site": 1,
|
|
19535
|
+
"name": 1,
|
|
19536
|
+
"block": 1,
|
|
19537
|
+
"status": 1,
|
|
19538
|
+
"buildingFloorPlan": 1,
|
|
19539
|
+
"createdAt": 1,
|
|
19540
|
+
"updatedAt": 1,
|
|
19541
|
+
"deletedAt": 1,
|
|
19542
|
+
"levels": "$buildingLevels"
|
|
19543
|
+
}
|
|
19544
|
+
}
|
|
19545
|
+
]).toArray();
|
|
19546
|
+
if (!result) {
|
|
19547
|
+
throw new BadRequestError79("Building not found.");
|
|
19548
|
+
}
|
|
19549
|
+
return result;
|
|
19550
|
+
} catch (error) {
|
|
19551
|
+
if (error instanceof AppError13) {
|
|
19552
|
+
throw error;
|
|
19553
|
+
} else {
|
|
19554
|
+
throw new InternalServerError29("Failed to get building.");
|
|
19555
|
+
}
|
|
19556
|
+
}
|
|
19557
|
+
}
|
|
19359
19558
|
function delCachedData() {
|
|
19360
19559
|
delNamespace().then(() => {
|
|
19361
19560
|
logger60.log({
|
|
@@ -19376,7 +19575,8 @@ function useBuildingRepo() {
|
|
|
19376
19575
|
getById,
|
|
19377
19576
|
updateById,
|
|
19378
19577
|
deleteById,
|
|
19379
|
-
getBuildingLevel
|
|
19578
|
+
getBuildingLevel,
|
|
19579
|
+
getBuildingLevelWithUnits
|
|
19380
19580
|
};
|
|
19381
19581
|
}
|
|
19382
19582
|
|
|
@@ -19535,7 +19735,8 @@ function useBuildingController() {
|
|
|
19535
19735
|
const {
|
|
19536
19736
|
getAll: _getAll,
|
|
19537
19737
|
getById: _getById,
|
|
19538
|
-
getBuildingLevel: _getBuildingLevel
|
|
19738
|
+
getBuildingLevel: _getBuildingLevel,
|
|
19739
|
+
getBuildingLevelWithUnits: _getBuildingLevelWithUnits
|
|
19539
19740
|
} = useBuildingRepo();
|
|
19540
19741
|
const {
|
|
19541
19742
|
updateById: _updateById,
|
|
@@ -19804,6 +20005,26 @@ function useBuildingController() {
|
|
|
19804
20005
|
next(error);
|
|
19805
20006
|
}
|
|
19806
20007
|
}
|
|
20008
|
+
async function getBuildingLevelWithUnits(req, res, next) {
|
|
20009
|
+
const site = req.params.site ?? "";
|
|
20010
|
+
let block = req.query.block;
|
|
20011
|
+
const validation = Joi44.object({
|
|
20012
|
+
site: Joi44.string().hex().required(),
|
|
20013
|
+
block: Joi44.string().required()
|
|
20014
|
+
});
|
|
20015
|
+
const { error } = validation.validate({ site, block });
|
|
20016
|
+
if (error) {
|
|
20017
|
+
next(new BadRequestError81(error.message));
|
|
20018
|
+
return;
|
|
20019
|
+
}
|
|
20020
|
+
try {
|
|
20021
|
+
const siteBlock = await _getBuildingLevelWithUnits(site, block);
|
|
20022
|
+
res.json(siteBlock);
|
|
20023
|
+
return;
|
|
20024
|
+
} catch (error2) {
|
|
20025
|
+
next(error2);
|
|
20026
|
+
}
|
|
20027
|
+
}
|
|
19807
20028
|
return {
|
|
19808
20029
|
createBuilding,
|
|
19809
20030
|
getAll,
|
|
@@ -19811,7 +20032,8 @@ function useBuildingController() {
|
|
|
19811
20032
|
updateById,
|
|
19812
20033
|
deleteById,
|
|
19813
20034
|
getBuildingLevel,
|
|
19814
|
-
uploadSpreadsheetBuilding
|
|
20035
|
+
uploadSpreadsheetBuilding,
|
|
20036
|
+
getBuildingLevelWithUnits
|
|
19815
20037
|
};
|
|
19816
20038
|
}
|
|
19817
20039
|
|
|
@@ -23718,7 +23940,10 @@ function useVisitorTransactionService() {
|
|
|
23718
23940
|
nric: value.nric,
|
|
23719
23941
|
start,
|
|
23720
23942
|
end,
|
|
23721
|
-
recNo: value.recNo
|
|
23943
|
+
recNo: value.recNo,
|
|
23944
|
+
...value.block && { block: value.block },
|
|
23945
|
+
...value.level && { level: value.level },
|
|
23946
|
+
...value.unit && { unit: new ObjectId59(value.unit) }
|
|
23722
23947
|
};
|
|
23723
23948
|
await addVehicle(vehiclePayload);
|
|
23724
23949
|
} else {
|
|
@@ -23850,6 +24075,8 @@ function useVisitorTransactionService() {
|
|
|
23850
24075
|
}
|
|
23851
24076
|
if (value.unit) {
|
|
23852
24077
|
value.unit = typeof value.unit === "string" ? new ObjectId59(value.unit) : value.unit;
|
|
24078
|
+
const unit = await _getUnitById(value.unit);
|
|
24079
|
+
value.unitName = unit?.name;
|
|
23853
24080
|
}
|
|
23854
24081
|
await _updateVisitorTansactionById(id, value, session);
|
|
23855
24082
|
await session?.commitTransaction();
|
|
@@ -32705,21 +32932,23 @@ function useEventManagementController() {
|
|
|
32705
32932
|
}
|
|
32706
32933
|
}
|
|
32707
32934
|
async function deleteEventManagementById(req, res, next) {
|
|
32708
|
-
const validation = Joi82.string().hex().required();
|
|
32709
|
-
const _id = req.params.id;
|
|
32710
|
-
const { error } = validation.validate(_id);
|
|
32711
|
-
if (error) {
|
|
32712
|
-
logger115.log({ level: "error", message: error.message });
|
|
32713
|
-
next(new BadRequestError137(error.message));
|
|
32714
|
-
return;
|
|
32715
|
-
}
|
|
32716
32935
|
try {
|
|
32936
|
+
const schema2 = Joi82.object({
|
|
32937
|
+
_id: Joi82.string().hex().length(24).required()
|
|
32938
|
+
});
|
|
32939
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
32940
|
+
if (error) {
|
|
32941
|
+
logger115.log({ level: "error", message: error.message });
|
|
32942
|
+
next(new BadRequestError137(error.message));
|
|
32943
|
+
return;
|
|
32944
|
+
}
|
|
32945
|
+
const { _id } = value;
|
|
32717
32946
|
await _deleteEventManagementById(_id);
|
|
32718
32947
|
res.status(200).json({ message: "Successfully deleted event." });
|
|
32719
32948
|
return;
|
|
32720
|
-
} catch (
|
|
32721
|
-
logger115.log({ level: "error", message:
|
|
32722
|
-
next(
|
|
32949
|
+
} catch (error) {
|
|
32950
|
+
logger115.log({ level: "error", message: error.message });
|
|
32951
|
+
next(error);
|
|
32723
32952
|
return;
|
|
32724
32953
|
}
|
|
32725
32954
|
}
|
|
@@ -36307,7 +36536,111 @@ function UseAccessManagementRepo() {
|
|
|
36307
36536
|
const items = result[0].items;
|
|
36308
36537
|
return paginate39(items, page, limit, length);
|
|
36309
36538
|
} catch (error) {
|
|
36310
|
-
|
|
36539
|
+
throw new Error(error.message);
|
|
36540
|
+
}
|
|
36541
|
+
}
|
|
36542
|
+
async function assignMultipleCardsRepo({
|
|
36543
|
+
assignees,
|
|
36544
|
+
unit,
|
|
36545
|
+
type,
|
|
36546
|
+
acm_url
|
|
36547
|
+
}) {
|
|
36548
|
+
const session = useAtlas76.getClient()?.startSession();
|
|
36549
|
+
try {
|
|
36550
|
+
session?.startTransaction();
|
|
36551
|
+
if (assignees.length < 1) {
|
|
36552
|
+
throw new Error("No user to Assign.");
|
|
36553
|
+
}
|
|
36554
|
+
assignees = assignees.map((data) => new ObjectId90(data));
|
|
36555
|
+
unit = new ObjectId90(unit);
|
|
36556
|
+
let availableCards = [];
|
|
36557
|
+
let update = [];
|
|
36558
|
+
let cards = [];
|
|
36559
|
+
availableCards = await collection().aggregate([
|
|
36560
|
+
{
|
|
36561
|
+
$match: {
|
|
36562
|
+
$expr: {
|
|
36563
|
+
$and: [
|
|
36564
|
+
{ $eq: ["$assignedUnit", unit] },
|
|
36565
|
+
{ $eq: ["$userId", null] },
|
|
36566
|
+
{ $eq: ["$type", type] },
|
|
36567
|
+
{ $eq: ["$isActivated", true] }
|
|
36568
|
+
]
|
|
36569
|
+
}
|
|
36570
|
+
}
|
|
36571
|
+
}
|
|
36572
|
+
]).toArray();
|
|
36573
|
+
if (assignees.length > availableCards.length) {
|
|
36574
|
+
throw new Error(`Not enough ${type} cards available.`);
|
|
36575
|
+
}
|
|
36576
|
+
cards = availableCards?.slice(0, assignees.length).map((card, index) => {
|
|
36577
|
+
const userId = new ObjectId90(assignees[index].toString());
|
|
36578
|
+
card.staffNo = userId.toString().slice(-10);
|
|
36579
|
+
return card;
|
|
36580
|
+
});
|
|
36581
|
+
update = availableCards.slice(0, assignees.length).map((card, index) => ({ _id: card._id, userId: new ObjectId90(assignees[index]) }));
|
|
36582
|
+
const commands = cards.map((item, index) => {
|
|
36583
|
+
let ag = null;
|
|
36584
|
+
if (item.accessGroup !== void 0) {
|
|
36585
|
+
if (item.accessGroup?.length > 0) {
|
|
36586
|
+
ag = item.accessGroup.map((g) => `<GROUP_NAME>${g}</GROUP_NAME>`).join("\n ");
|
|
36587
|
+
}
|
|
36588
|
+
}
|
|
36589
|
+
const command = {
|
|
36590
|
+
commandId1: index * 2 + 1,
|
|
36591
|
+
commandId2: index * 2 + 2,
|
|
36592
|
+
staffName: `STAFF-${item._id.toString().slice(-10)}`,
|
|
36593
|
+
staffNo1: `STAFF-${item._id.toString().slice(-10)}`,
|
|
36594
|
+
staffNo2: `STAFF-${item._id.toString().slice(-10)}`,
|
|
36595
|
+
dateOfJoin: formatEntryPassDate(item.startDate),
|
|
36596
|
+
accessLevel: item.accessLevel ?? "0",
|
|
36597
|
+
cardNo: item.cardNo,
|
|
36598
|
+
pin: typeof item.pin === "string" && item.pin.trim() !== "" ? item.pin : "123456",
|
|
36599
|
+
startDate: formatEntryPassDate(item.startDate),
|
|
36600
|
+
endDate: formatEntryPassDate(item.endDate),
|
|
36601
|
+
cardType: 0,
|
|
36602
|
+
isActivated: item.isActivated ? 1 : 0,
|
|
36603
|
+
isAntiPassBack: item.isAntiPassBack ? 1 : 0,
|
|
36604
|
+
isLiftCard: item.isLiftCard ? 1 : 0,
|
|
36605
|
+
isLiftActivate: item.isLiftCard ? 1 : 0,
|
|
36606
|
+
liftAccessLevel: item.liftAccessLevel || 1,
|
|
36607
|
+
liftAccessStartDate: formatEntryPassDate(item.liftAccessStartDate) || "19770510",
|
|
36608
|
+
liftAccessEndDate: formatEntryPassDate(item.liftAccessEndDate) || "19770510",
|
|
36609
|
+
accessGroup: ag
|
|
36610
|
+
};
|
|
36611
|
+
return readTemplate(`${item.accessLevel !== null ? "add-card" : "add-card-lift"}`, { ...command });
|
|
36612
|
+
}).flat();
|
|
36613
|
+
const response = await sendCommand(commands.join("").toString(), acm_url);
|
|
36614
|
+
const result = await parseStringPromise2(response, { explicitArray: false });
|
|
36615
|
+
console.log("status code", result.RESULT.$.STCODE);
|
|
36616
|
+
if (result && result.RESULT.$.STCODE !== "0") {
|
|
36617
|
+
throw new Error("Command failed, server error.");
|
|
36618
|
+
}
|
|
36619
|
+
for (const { _id, userId } of update) {
|
|
36620
|
+
await collection().updateOne({ _id }, { $set: { userId, staffNo: `STAFF-${userId.toString().slice(-10)}` } }, { session });
|
|
36621
|
+
}
|
|
36622
|
+
await session?.commitTransaction();
|
|
36623
|
+
return "Cards assigned successfully.";
|
|
36624
|
+
} catch (error) {
|
|
36625
|
+
await session?.abortTransaction();
|
|
36626
|
+
throw new Error(error.message);
|
|
36627
|
+
} finally {
|
|
36628
|
+
await session?.endSession();
|
|
36629
|
+
}
|
|
36630
|
+
}
|
|
36631
|
+
async function visitorCheckoutRepo({ userId }) {
|
|
36632
|
+
const session = useAtlas76.getClient()?.startSession();
|
|
36633
|
+
try {
|
|
36634
|
+
session?.startTransaction();
|
|
36635
|
+
const id = new ObjectId90(userId);
|
|
36636
|
+
await collection().updateMany({ userId: id }, { $set: { userId: null, status: "Available" } }, { session });
|
|
36637
|
+
session?.commitTransaction();
|
|
36638
|
+
return "Successful Checkout";
|
|
36639
|
+
} catch (error) {
|
|
36640
|
+
await session?.abortTransaction();
|
|
36641
|
+
throw new Error(error.message);
|
|
36642
|
+
} finally {
|
|
36643
|
+
await session?.endSession();
|
|
36311
36644
|
}
|
|
36312
36645
|
}
|
|
36313
36646
|
return {
|
|
@@ -36342,7 +36675,9 @@ function UseAccessManagementRepo() {
|
|
|
36342
36675
|
checkoutVisitorRepo,
|
|
36343
36676
|
getBlockLevelAndUnitListRepo,
|
|
36344
36677
|
indexCombination,
|
|
36345
|
-
getTransactionsRepo
|
|
36678
|
+
getTransactionsRepo,
|
|
36679
|
+
assignMultipleCardsRepo,
|
|
36680
|
+
visitorCheckoutRepo
|
|
36346
36681
|
};
|
|
36347
36682
|
}
|
|
36348
36683
|
|
|
@@ -36383,7 +36718,9 @@ function useAccessManagementSvc() {
|
|
|
36383
36718
|
signQrCodeRepo,
|
|
36384
36719
|
checkoutVisitorRepo,
|
|
36385
36720
|
getBlockLevelAndUnitListRepo,
|
|
36386
|
-
getTransactionsRepo
|
|
36721
|
+
getTransactionsRepo,
|
|
36722
|
+
assignMultipleCardsRepo,
|
|
36723
|
+
visitorCheckoutRepo
|
|
36387
36724
|
} = UseAccessManagementRepo();
|
|
36388
36725
|
const addPhysicalCardSvc = async (payload) => {
|
|
36389
36726
|
try {
|
|
@@ -36679,6 +37016,22 @@ function useAccessManagementSvc() {
|
|
|
36679
37016
|
try {
|
|
36680
37017
|
const response = await getTransactionsRepo({ page, limit, site, cardNo, url });
|
|
36681
37018
|
return response;
|
|
37019
|
+
} catch (err) {
|
|
37020
|
+
throw new Error(err.message);
|
|
37021
|
+
}
|
|
37022
|
+
};
|
|
37023
|
+
const assignMultipleCardsSvc = async ({ assignees, unit, type, acm_url }) => {
|
|
37024
|
+
try {
|
|
37025
|
+
const response = await assignMultipleCardsRepo({ assignees, unit, type, acm_url });
|
|
37026
|
+
return response;
|
|
37027
|
+
} catch (err) {
|
|
37028
|
+
throw new Error(err.message);
|
|
37029
|
+
}
|
|
37030
|
+
};
|
|
37031
|
+
const visitorCheckoutSvc = async ({ userId }) => {
|
|
37032
|
+
try {
|
|
37033
|
+
const response = await visitorCheckoutRepo({ userId });
|
|
37034
|
+
return response;
|
|
36682
37035
|
} catch (err) {
|
|
36683
37036
|
return Promise.reject("Server internal error.");
|
|
36684
37037
|
}
|
|
@@ -36718,7 +37071,9 @@ function useAccessManagementSvc() {
|
|
|
36718
37071
|
signQrCodeSvc,
|
|
36719
37072
|
checkoutVisitorSvc,
|
|
36720
37073
|
getBlockLevelAndUnitListSvc,
|
|
36721
|
-
getTransactionsSvc
|
|
37074
|
+
getTransactionsSvc,
|
|
37075
|
+
assignMultipleCardsSvc,
|
|
37076
|
+
visitorCheckoutSvc
|
|
36722
37077
|
};
|
|
36723
37078
|
}
|
|
36724
37079
|
|
|
@@ -36759,7 +37114,9 @@ function useAccessManagementController() {
|
|
|
36759
37114
|
signQrCodeSvc,
|
|
36760
37115
|
checkoutVisitorSvc,
|
|
36761
37116
|
getBlockLevelAndUnitListSvc,
|
|
36762
|
-
getTransactionsSvc
|
|
37117
|
+
getTransactionsSvc,
|
|
37118
|
+
assignMultipleCardsSvc,
|
|
37119
|
+
visitorCheckoutSvc
|
|
36763
37120
|
} = useAccessManagementSvc();
|
|
36764
37121
|
const addPhysicalCard = async (req, res) => {
|
|
36765
37122
|
try {
|
|
@@ -37543,6 +37900,39 @@ function useAccessManagementController() {
|
|
|
37543
37900
|
});
|
|
37544
37901
|
return res.json(result);
|
|
37545
37902
|
} catch (error2) {
|
|
37903
|
+
return res.status(400).json({
|
|
37904
|
+
data: null,
|
|
37905
|
+
message: error2.message
|
|
37906
|
+
});
|
|
37907
|
+
}
|
|
37908
|
+
};
|
|
37909
|
+
const assignMultipleCards = async (req, res) => {
|
|
37910
|
+
try {
|
|
37911
|
+
const { assignees, unit, type, acm_url } = req.body;
|
|
37912
|
+
const schema2 = Joi85.object({
|
|
37913
|
+
assignees: Joi85.array().items(Joi85.string().hex()).required(),
|
|
37914
|
+
type: Joi85.string().required(),
|
|
37915
|
+
unit: Joi85.string().hex().required()
|
|
37916
|
+
});
|
|
37917
|
+
const { error } = schema2.validate({ assignees, type, unit });
|
|
37918
|
+
if (error) {
|
|
37919
|
+
throw new Error(`${error.message}`);
|
|
37920
|
+
}
|
|
37921
|
+
const result = await assignMultipleCardsSvc({ assignees, unit, type, acm_url });
|
|
37922
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
37923
|
+
} catch (error) {
|
|
37924
|
+
return res.status(400).json({
|
|
37925
|
+
data: null,
|
|
37926
|
+
message: error.message
|
|
37927
|
+
});
|
|
37928
|
+
}
|
|
37929
|
+
};
|
|
37930
|
+
const visitorCheckout = async (req, res) => {
|
|
37931
|
+
try {
|
|
37932
|
+
const userId = req.params.userId;
|
|
37933
|
+
const result = await visitorCheckoutSvc({ userId });
|
|
37934
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
37935
|
+
} catch (error) {
|
|
37546
37936
|
return Promise.reject("Internal Server Error");
|
|
37547
37937
|
}
|
|
37548
37938
|
};
|
|
@@ -37579,7 +37969,9 @@ function useAccessManagementController() {
|
|
|
37579
37969
|
checkoutVisitor,
|
|
37580
37970
|
removeAccessCard,
|
|
37581
37971
|
getBlockLevelAndUnitList,
|
|
37582
|
-
getTransactions: getTransactions2
|
|
37972
|
+
getTransactions: getTransactions2,
|
|
37973
|
+
assignMultipleCards,
|
|
37974
|
+
visitorCheckout
|
|
37583
37975
|
};
|
|
37584
37976
|
}
|
|
37585
37977
|
|
|
@@ -51850,6 +52242,7 @@ export {
|
|
|
51850
52242
|
allowedNatures,
|
|
51851
52243
|
attendanceSchema,
|
|
51852
52244
|
attendanceSettingsSchema,
|
|
52245
|
+
building_units_namespace_collection,
|
|
51853
52246
|
buildings_namespace_collection,
|
|
51854
52247
|
bulletin_boards_namespace_collection,
|
|
51855
52248
|
calculatePercentage,
|