@7365admin1/core 3.7.0 → 3.7.1
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 +7 -6
- package/dist/index.js +147 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +147 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -11889,9 +11889,7 @@ function useVerificationService() {
|
|
|
11889
11889
|
...metadata,
|
|
11890
11890
|
app
|
|
11891
11891
|
},
|
|
11892
|
-
expireAt: new Date(
|
|
11893
|
-
Date.now() + 72 * 60 * 60 * 1e3
|
|
11894
|
-
).toISOString(),
|
|
11892
|
+
expireAt: new Date(Date.now() + 72 * 60 * 60 * 1e3).toISOString(),
|
|
11895
11893
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
11896
11894
|
};
|
|
11897
11895
|
const createdId = await add(value);
|
|
@@ -11910,10 +11908,7 @@ function useVerificationService() {
|
|
|
11910
11908
|
hasPestControl: app === "pest_control_services",
|
|
11911
11909
|
hasPoolMaintenance: app === "pool_maintenance_services"
|
|
11912
11910
|
},
|
|
11913
|
-
filePath: getDirectory(
|
|
11914
|
-
__dirname,
|
|
11915
|
-
"./public/handlebars/user-invite"
|
|
11916
|
-
)
|
|
11911
|
+
filePath: getDirectory(__dirname, "./public/handlebars/user-invite")
|
|
11917
11912
|
});
|
|
11918
11913
|
await mailer.sendMail({
|
|
11919
11914
|
to: email,
|
|
@@ -12056,7 +12051,15 @@ function useVerificationService() {
|
|
|
12056
12051
|
throw error2;
|
|
12057
12052
|
}
|
|
12058
12053
|
}
|
|
12059
|
-
async function createSimpleServiceProviderInvite({
|
|
12054
|
+
async function createSimpleServiceProviderInvite({
|
|
12055
|
+
email,
|
|
12056
|
+
app,
|
|
12057
|
+
name,
|
|
12058
|
+
role,
|
|
12059
|
+
orgId,
|
|
12060
|
+
siteId,
|
|
12061
|
+
siteName
|
|
12062
|
+
}) {
|
|
12060
12063
|
const schema2 = Joi11.object({
|
|
12061
12064
|
email: Joi11.string().email().lowercase().required(),
|
|
12062
12065
|
app: Joi11.string().allow("", null),
|
|
@@ -12098,7 +12101,10 @@ function useVerificationService() {
|
|
|
12098
12101
|
};
|
|
12099
12102
|
try {
|
|
12100
12103
|
const id = await _add(value);
|
|
12101
|
-
const filePath = getDirectory(
|
|
12104
|
+
const filePath = getDirectory(
|
|
12105
|
+
__dirname,
|
|
12106
|
+
`./public/handlebars/${value.type}`
|
|
12107
|
+
);
|
|
12102
12108
|
const link = `${APP_MAIN}/verify/${value.type}/${id}`;
|
|
12103
12109
|
const emailContent = compileHandlebar({
|
|
12104
12110
|
context: {
|
|
@@ -21025,6 +21031,15 @@ async function convertObjectIdUtil(id) {
|
|
|
21025
21031
|
return Promise.reject("Invalid ID conversion to ObjectId");
|
|
21026
21032
|
}
|
|
21027
21033
|
}
|
|
21034
|
+
async function convertObjectIdUtil2(id, fieldName) {
|
|
21035
|
+
try {
|
|
21036
|
+
if (!id)
|
|
21037
|
+
throw new Error(`Invalid ID conversion to ObjectId of ${fieldName}.`);
|
|
21038
|
+
return new ObjectId40(id);
|
|
21039
|
+
} catch (_) {
|
|
21040
|
+
throw new Error(`Invalid ID conversion to ObjectId of ${fieldName}.`);
|
|
21041
|
+
}
|
|
21042
|
+
}
|
|
21028
21043
|
|
|
21029
21044
|
// src/repositories/visitor-transaction.repo.ts
|
|
21030
21045
|
import moment from "moment-timezone";
|
|
@@ -22827,6 +22842,38 @@ function useVehicleRepo() {
|
|
|
22827
22842
|
throw error;
|
|
22828
22843
|
}
|
|
22829
22844
|
}
|
|
22845
|
+
async function getBlocklistedVehicleByPlateNumber(plateNumber, site) {
|
|
22846
|
+
if (!plateNumber) {
|
|
22847
|
+
throw new BadRequestError69("Plate number is required");
|
|
22848
|
+
}
|
|
22849
|
+
const baseQuery = {
|
|
22850
|
+
type: "blocklist" /* BLOCKLIST */,
|
|
22851
|
+
plateNumber,
|
|
22852
|
+
...site && {
|
|
22853
|
+
site: typeof site === "string" ? new ObjectId43(site) : site
|
|
22854
|
+
}
|
|
22855
|
+
};
|
|
22856
|
+
try {
|
|
22857
|
+
const pipeline = [
|
|
22858
|
+
{ $match: baseQuery },
|
|
22859
|
+
{
|
|
22860
|
+
$addFields: {
|
|
22861
|
+
latestDate: { $max: ["$createdAt", "$updatedAt"] }
|
|
22862
|
+
}
|
|
22863
|
+
},
|
|
22864
|
+
{ $sort: { latestDate: -1 } },
|
|
22865
|
+
{
|
|
22866
|
+
$project: {
|
|
22867
|
+
latestDate: 0
|
|
22868
|
+
}
|
|
22869
|
+
}
|
|
22870
|
+
];
|
|
22871
|
+
const [result] = await collection.aggregate(pipeline).toArray();
|
|
22872
|
+
return result;
|
|
22873
|
+
} catch (error) {
|
|
22874
|
+
throw error;
|
|
22875
|
+
}
|
|
22876
|
+
}
|
|
22830
22877
|
return {
|
|
22831
22878
|
createIndex,
|
|
22832
22879
|
createTextIndex,
|
|
@@ -22845,7 +22892,8 @@ function useVehicleRepo() {
|
|
|
22845
22892
|
bulkUpsertVehicles,
|
|
22846
22893
|
getSpecificVehicleById,
|
|
22847
22894
|
getBlocklistedVehicles,
|
|
22848
|
-
getVehicleBySiteAndPlateNumber
|
|
22895
|
+
getVehicleBySiteAndPlateNumber,
|
|
22896
|
+
getBlocklistedVehicleByPlateNumber
|
|
22849
22897
|
};
|
|
22850
22898
|
}
|
|
22851
22899
|
|
|
@@ -33279,6 +33327,71 @@ var KeyRepo = class {
|
|
|
33279
33327
|
return Promise.reject("Failed to delete key");
|
|
33280
33328
|
}
|
|
33281
33329
|
}
|
|
33330
|
+
static async getById2(id) {
|
|
33331
|
+
return this.collection().aggregate([
|
|
33332
|
+
{ $match: { _id: new ObjectId61(id) } },
|
|
33333
|
+
{
|
|
33334
|
+
$lookup: {
|
|
33335
|
+
from: "qr-code-templates",
|
|
33336
|
+
localField: "template",
|
|
33337
|
+
foreignField: "_id",
|
|
33338
|
+
as: "QRTemplateInfo"
|
|
33339
|
+
}
|
|
33340
|
+
},
|
|
33341
|
+
{
|
|
33342
|
+
$unwind: {
|
|
33343
|
+
path: "$QRTemplateInfo",
|
|
33344
|
+
preserveNullAndEmptyArrays: true
|
|
33345
|
+
}
|
|
33346
|
+
},
|
|
33347
|
+
{
|
|
33348
|
+
$addFields: {
|
|
33349
|
+
prefixPass: { $toUpper: "$QRTemplateInfo.prefixPass" },
|
|
33350
|
+
prefixKey: { $toUpper: "$QRTemplateInfo.prefixKey" },
|
|
33351
|
+
templateName: "$QRTemplateInfo.name"
|
|
33352
|
+
}
|
|
33353
|
+
},
|
|
33354
|
+
{
|
|
33355
|
+
$addFields: {
|
|
33356
|
+
prefixAndName: {
|
|
33357
|
+
$cond: {
|
|
33358
|
+
if: { $or: [{ $not: "$prefixPass" }, { $not: "$prefixKey" }] },
|
|
33359
|
+
then: "$name",
|
|
33360
|
+
else: {
|
|
33361
|
+
$cond: {
|
|
33362
|
+
if: { $eq: ["$passType", "pass-key"] },
|
|
33363
|
+
then: { $concat: ["$prefixKey", "$name"] },
|
|
33364
|
+
else: { $concat: ["$prefixPass", "$name"] }
|
|
33365
|
+
}
|
|
33366
|
+
}
|
|
33367
|
+
}
|
|
33368
|
+
}
|
|
33369
|
+
}
|
|
33370
|
+
}
|
|
33371
|
+
]).toArray().then((results) => results.length ? results[0] : null);
|
|
33372
|
+
}
|
|
33373
|
+
static async checkPassKeyAvailability(visitorPass, passKeys) {
|
|
33374
|
+
if (Array.isArray(visitorPass) && visitorPass.length > 0) {
|
|
33375
|
+
for (let i = 0; i < visitorPass.length; i++) {
|
|
33376
|
+
let pass = await convertObjectIdUtil2(visitorPass[i].keyId, "Pass ID");
|
|
33377
|
+
const getPass = await this.getById2(pass);
|
|
33378
|
+
if (!getPass)
|
|
33379
|
+
throw new Error("Pass not found");
|
|
33380
|
+
if (getPass?.status && getPass?.status.toLowerCase() != "Available".toLowerCase())
|
|
33381
|
+
throw new Error(`Pass ${getPass?.prefixAndName} is ${getPass?.status}`);
|
|
33382
|
+
}
|
|
33383
|
+
}
|
|
33384
|
+
if (Array.isArray(passKeys) && passKeys.length > 0) {
|
|
33385
|
+
for (let i = 0; i < passKeys.length; i++) {
|
|
33386
|
+
let key = await convertObjectIdUtil2(passKeys[i].keyId, "Key ID");
|
|
33387
|
+
const getPass = await this.getById2(key);
|
|
33388
|
+
if (!getPass)
|
|
33389
|
+
throw new Error(`Key not found`);
|
|
33390
|
+
if (getPass?.status && getPass?.status.toLowerCase() != "Available".toLowerCase())
|
|
33391
|
+
throw new Error(`Pass ${getPass?.prefixAndName} is ${getPass?.status}`);
|
|
33392
|
+
}
|
|
33393
|
+
}
|
|
33394
|
+
}
|
|
33282
33395
|
};
|
|
33283
33396
|
|
|
33284
33397
|
// src/services/visitor-transaction.service.ts
|
|
@@ -33315,7 +33428,9 @@ function useVisitorTransactionService() {
|
|
|
33315
33428
|
} = useDahuaService();
|
|
33316
33429
|
const { getAllSites: _getAllSites } = useSiteRepo();
|
|
33317
33430
|
const { getByUserId: _getByUserId } = usePersonRepo();
|
|
33318
|
-
const {
|
|
33431
|
+
const {
|
|
33432
|
+
getBlocklistedVehicleByPlateNumber: _getBlocklistedVehicleByPlateNumber
|
|
33433
|
+
} = useVehicleRepo();
|
|
33319
33434
|
const { getById: _getUnitById } = useBuildingUnitRepo();
|
|
33320
33435
|
function extractKeyId(item) {
|
|
33321
33436
|
if (!item)
|
|
@@ -33393,6 +33508,13 @@ function useVisitorTransactionService() {
|
|
|
33393
33508
|
const start = value.checkIn ? new Date(value.checkIn) : /* @__PURE__ */ new Date();
|
|
33394
33509
|
try {
|
|
33395
33510
|
session?.startTransaction();
|
|
33511
|
+
if (value.plateNumber) {
|
|
33512
|
+
const result2 = await _getBlocklistedVehicleByPlateNumber(
|
|
33513
|
+
value.plateNumber
|
|
33514
|
+
);
|
|
33515
|
+
if (result2)
|
|
33516
|
+
throw new BadRequestError100("Plate number is blocklisted");
|
|
33517
|
+
}
|
|
33396
33518
|
let camera;
|
|
33397
33519
|
if (value.site && value.plateNumber) {
|
|
33398
33520
|
try {
|
|
@@ -33458,6 +33580,7 @@ function useVisitorTransactionService() {
|
|
|
33458
33580
|
for (let i = 0; i < value.members.length; i += chunkSize) {
|
|
33459
33581
|
const chunk = value.members.slice(i, i + chunkSize);
|
|
33460
33582
|
for (const member of chunk) {
|
|
33583
|
+
await KeyRepo.checkPassKeyAvailability(member.visitorPass, member.passKeys);
|
|
33461
33584
|
if (member.visitorPass && Array.isArray(member.visitorPass) && member.visitorPass.length > 0) {
|
|
33462
33585
|
for (const vp of member.visitorPass) {
|
|
33463
33586
|
try {
|
|
@@ -33544,6 +33667,7 @@ function useVisitorTransactionService() {
|
|
|
33544
33667
|
if (found === 1)
|
|
33545
33668
|
throw new BadRequestError100("This plate number is blocklisted");
|
|
33546
33669
|
}
|
|
33670
|
+
await KeyRepo.checkPassKeyAvailability(value.visitorPass, value.passKeys);
|
|
33547
33671
|
if (value.visitorPass && Array.isArray(value.visitorPass) && value.visitorPass.length > 0 && value.visitorPass) {
|
|
33548
33672
|
for (const vp of value.visitorPass) {
|
|
33549
33673
|
try {
|
|
@@ -33591,7 +33715,9 @@ function useVisitorTransactionService() {
|
|
|
33591
33715
|
password,
|
|
33592
33716
|
plateNumber: value?.plateNumber
|
|
33593
33717
|
});
|
|
33594
|
-
logger80.info(`Barrier command sent successfully to ${host}`, {
|
|
33718
|
+
logger80.info(`Barrier command sent successfully to ${host}`, {
|
|
33719
|
+
response: openBarrier
|
|
33720
|
+
});
|
|
33595
33721
|
} catch (error) {
|
|
33596
33722
|
logger80.error(
|
|
33597
33723
|
`Failed to open barrier at host ${host}. Critical system error:`,
|
|
@@ -33731,7 +33857,9 @@ function useVisitorTransactionService() {
|
|
|
33731
33857
|
password,
|
|
33732
33858
|
plateNumber: value?.plateNumber
|
|
33733
33859
|
});
|
|
33734
|
-
logger80.info(`Barrier command sent successfully to ${host}`, {
|
|
33860
|
+
logger80.info(`Barrier command sent successfully to ${host}`, {
|
|
33861
|
+
response: openBarrier
|
|
33862
|
+
});
|
|
33735
33863
|
} catch (error) {
|
|
33736
33864
|
logger80.error(
|
|
33737
33865
|
`Failed to open barrier at host ${host}. Critical system error:`,
|
|
@@ -33944,7 +34072,12 @@ function useVisitorTransactionController() {
|
|
|
33944
34072
|
return;
|
|
33945
34073
|
} catch (error) {
|
|
33946
34074
|
logger81.log({ level: "error", message: error.message });
|
|
33947
|
-
|
|
34075
|
+
console.log("error", error);
|
|
34076
|
+
if (error?.message) {
|
|
34077
|
+
next(new BadRequestError101(error?.message));
|
|
34078
|
+
} else {
|
|
34079
|
+
next(error);
|
|
34080
|
+
}
|
|
33948
34081
|
return;
|
|
33949
34082
|
}
|
|
33950
34083
|
}
|