@7365admin1/core 2.25.0 → 2.26.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 +130 -48
- package/dist/index.js +450 -91
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +494 -126
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4129,7 +4129,10 @@ function useOrgRepo() {
|
|
|
4129
4129
|
import { ObjectId as ObjectId16 } from "mongodb";
|
|
4130
4130
|
|
|
4131
4131
|
// src/models/site.model.ts
|
|
4132
|
-
import {
|
|
4132
|
+
import {
|
|
4133
|
+
BadRequestError as BadRequestError16,
|
|
4134
|
+
logger as logger11
|
|
4135
|
+
} from "@7365admin1/node-server-utils";
|
|
4133
4136
|
import Joi9 from "joi";
|
|
4134
4137
|
import { ObjectId as ObjectId15 } from "mongodb";
|
|
4135
4138
|
var addressSchema = Joi9.object({
|
|
@@ -4186,7 +4189,9 @@ var siteSchema = Joi9.object({
|
|
|
4186
4189
|
category: Joi9.string().valid(...Object.values(SiteCategories)).default("commercial" /* COMMERCIAL */),
|
|
4187
4190
|
deliveryCompanyList: Joi9.array().items(Joi9.string()).optional().allow(null),
|
|
4188
4191
|
isOpenGate: Joi9.boolean().optional().default(false),
|
|
4189
|
-
dahuaTimeExpiration: Joi9.number().optional().allow(null)
|
|
4192
|
+
dahuaTimeExpiration: Joi9.number().optional().allow(null),
|
|
4193
|
+
siteDocs: Joi9.array().items(Joi9.string().hex().length(24).allow(null, "")),
|
|
4194
|
+
unitDocs: Joi9.array().items(Joi9.string().hex().length(24).allow(null, ""))
|
|
4190
4195
|
});
|
|
4191
4196
|
var updateSiteSchema = Joi9.object({
|
|
4192
4197
|
_id: Joi9.string().hex().length(24).required(),
|
|
@@ -4194,7 +4199,9 @@ var updateSiteSchema = Joi9.object({
|
|
|
4194
4199
|
metadata: metadataSchema3.optional(),
|
|
4195
4200
|
deliveryCompanyList: Joi9.array().items(Joi9.string().trim()).optional().allow(null),
|
|
4196
4201
|
isOpenGate: Joi9.boolean().optional().allow(null),
|
|
4197
|
-
dahuaTimeExpiration: Joi9.number().optional().allow(null)
|
|
4202
|
+
dahuaTimeExpiration: Joi9.number().optional().allow(null),
|
|
4203
|
+
siteDocs: Joi9.array().items(Joi9.string().hex().length(24).allow(null, "")),
|
|
4204
|
+
unitDocs: Joi9.array().items(Joi9.string().hex().length(24).allow(null, ""))
|
|
4198
4205
|
});
|
|
4199
4206
|
function MSite(value) {
|
|
4200
4207
|
const { error } = siteSchema.validate(value);
|
|
@@ -4221,6 +4228,8 @@ function MSite(value) {
|
|
|
4221
4228
|
deliveryCompanyList: value.deliveryCompanyList ?? [],
|
|
4222
4229
|
isOpenGate: value.isOpenGate,
|
|
4223
4230
|
dahuaTimeExpiration: value.dahuaTimeExpiration,
|
|
4231
|
+
siteDocs: value.siteDocs ?? [],
|
|
4232
|
+
unitDocs: value.unitDocs ?? [],
|
|
4224
4233
|
updatedAt: value.updatedAt ?? "",
|
|
4225
4234
|
deletedAt: value.deletedAt ?? ""
|
|
4226
4235
|
};
|
|
@@ -4237,7 +4246,7 @@ import {
|
|
|
4237
4246
|
logger as logger12,
|
|
4238
4247
|
makeCacheKey as makeCacheKey9,
|
|
4239
4248
|
AppError as AppError4,
|
|
4240
|
-
toObjectId
|
|
4249
|
+
toObjectId as toObjectId2
|
|
4241
4250
|
} from "@7365admin1/node-server-utils";
|
|
4242
4251
|
import Joi10 from "joi";
|
|
4243
4252
|
function useSiteRepo() {
|
|
@@ -4623,7 +4632,7 @@ function useSiteRepo() {
|
|
|
4623
4632
|
}
|
|
4624
4633
|
}
|
|
4625
4634
|
async function updateSiteById(id, payload, session) {
|
|
4626
|
-
const _id =
|
|
4635
|
+
const _id = toObjectId2(id);
|
|
4627
4636
|
payload.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4628
4637
|
try {
|
|
4629
4638
|
const res = await collection.updateOne(
|
|
@@ -8487,7 +8496,7 @@ import {
|
|
|
8487
8496
|
import { z } from "zod";
|
|
8488
8497
|
import { ObjectId as ObjectId25 } from "mongodb";
|
|
8489
8498
|
import { BadRequestError as BadRequestError38 } from "@7365admin1/node-server-utils";
|
|
8490
|
-
function
|
|
8499
|
+
function toObjectId3(value) {
|
|
8491
8500
|
if (typeof value === "string") {
|
|
8492
8501
|
if (!/^[a-fA-F0-9]{24}$/.test(value)) {
|
|
8493
8502
|
throw new BadRequestError38(`Invalid ObjectId format: ${value}`);
|
|
@@ -8539,7 +8548,7 @@ var TInvoice = z.object({
|
|
|
8539
8548
|
message: "Invalid ObjectId: Must be a 24-character hex string."
|
|
8540
8549
|
}),
|
|
8541
8550
|
z.instanceof(ObjectId25, { message: "Invalid ObjectId instance." })
|
|
8542
|
-
]).optional().transform((val) => val ?
|
|
8551
|
+
]).optional().transform((val) => val ? toObjectId3(val) : void 0),
|
|
8543
8552
|
invoiceNumber: z.string({ required_error: "Invoice number is required." }),
|
|
8544
8553
|
type: TInvoiceType.default("other"),
|
|
8545
8554
|
amount: z.number().min(0, { message: "Invoice amount must be at least 0." }),
|
|
@@ -12292,7 +12301,7 @@ import {
|
|
|
12292
12301
|
logger as logger46,
|
|
12293
12302
|
makeCacheKey as makeCacheKey21,
|
|
12294
12303
|
paginate as paginate16,
|
|
12295
|
-
toObjectId as
|
|
12304
|
+
toObjectId as toObjectId5,
|
|
12296
12305
|
useAtlas as useAtlas29,
|
|
12297
12306
|
useCache as useCache22
|
|
12298
12307
|
} from "@7365admin1/node-server-utils";
|
|
@@ -12520,7 +12529,7 @@ function useSiteCameraRepo() {
|
|
|
12520
12529
|
});
|
|
12521
12530
|
}
|
|
12522
12531
|
async function getBySite(site, options = {}) {
|
|
12523
|
-
const _site =
|
|
12532
|
+
const _site = toObjectId5(site);
|
|
12524
12533
|
const cacheKeyOptions = {
|
|
12525
12534
|
site,
|
|
12526
12535
|
tag: "get-by-site",
|
|
@@ -12756,7 +12765,7 @@ import {
|
|
|
12756
12765
|
logger as logger47,
|
|
12757
12766
|
makeCacheKey as makeCacheKey22,
|
|
12758
12767
|
paginate as paginate17,
|
|
12759
|
-
toObjectId as
|
|
12768
|
+
toObjectId as toObjectId6,
|
|
12760
12769
|
useAtlas as useAtlas30,
|
|
12761
12770
|
useCache as useCache23
|
|
12762
12771
|
} from "@7365admin1/node-server-utils";
|
|
@@ -12769,17 +12778,22 @@ import { ObjectId as ObjectId38 } from "mongodb";
|
|
|
12769
12778
|
import { BadRequestError as BadRequestError64 } from "@7365admin1/node-server-utils";
|
|
12770
12779
|
import Joi35 from "joi";
|
|
12771
12780
|
import { ObjectId as ObjectId37 } from "mongodb";
|
|
12772
|
-
var PersonTypes = /* @__PURE__ */ ((
|
|
12773
|
-
|
|
12774
|
-
|
|
12775
|
-
|
|
12776
|
-
|
|
12777
|
-
|
|
12778
|
-
|
|
12779
|
-
|
|
12780
|
-
|
|
12781
|
-
return
|
|
12781
|
+
var PersonTypes = /* @__PURE__ */ ((PersonTypes3) => {
|
|
12782
|
+
PersonTypes3["WALK_IN"] = "walk-in";
|
|
12783
|
+
PersonTypes3["DROP_OFF"] = "drop-off";
|
|
12784
|
+
PersonTypes3["CONTRACTOR"] = "contractor";
|
|
12785
|
+
PersonTypes3["DELIVERY"] = "delivery";
|
|
12786
|
+
PersonTypes3["PICK_UP"] = "pick-up";
|
|
12787
|
+
PersonTypes3["GUEST"] = "guest";
|
|
12788
|
+
PersonTypes3["TENANT"] = "tenant";
|
|
12789
|
+
PersonTypes3["RESIDENT"] = "resident";
|
|
12790
|
+
return PersonTypes3;
|
|
12782
12791
|
})(PersonTypes || {});
|
|
12792
|
+
var PersonStatus = /* @__PURE__ */ ((PersonStatus2) => {
|
|
12793
|
+
PersonStatus2["ACTIVE"] = "active";
|
|
12794
|
+
PersonStatus2["DELETED"] = "deleted";
|
|
12795
|
+
return PersonStatus2;
|
|
12796
|
+
})(PersonStatus || {});
|
|
12783
12797
|
var PERSON_TYPES = [
|
|
12784
12798
|
"walk-in",
|
|
12785
12799
|
"drop-off",
|
|
@@ -13250,7 +13264,7 @@ function useVisitorTransactionRepo() {
|
|
|
13250
13264
|
}
|
|
13251
13265
|
}
|
|
13252
13266
|
async function getOpenByPlateNumber(plateNumber, site) {
|
|
13253
|
-
const _site = typeof site === "string" ? site :
|
|
13267
|
+
const _site = typeof site === "string" ? site : toObjectId6(site);
|
|
13254
13268
|
const cacheKey = makeCacheKey22(visitors_namespace_collection, {
|
|
13255
13269
|
plateNumber,
|
|
13256
13270
|
key: "get-open-transaction-plate-number",
|
|
@@ -13367,7 +13381,7 @@ function useVisitorTransactionRepo() {
|
|
|
13367
13381
|
}
|
|
13368
13382
|
}
|
|
13369
13383
|
async function getExpiredCheckedOutTransactionsBySite(siteId) {
|
|
13370
|
-
const site =
|
|
13384
|
+
const site = toObjectId6(siteId);
|
|
13371
13385
|
try {
|
|
13372
13386
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
13373
13387
|
const expiredTransactions = await collection.find({
|
|
@@ -13498,7 +13512,8 @@ var vehicleSchema = Joi37.object({
|
|
|
13498
13512
|
start: Joi37.date().optional().allow("", null),
|
|
13499
13513
|
end: Joi37.date().optional().allow("", null),
|
|
13500
13514
|
unitName: Joi37.string().optional().allow("", null),
|
|
13501
|
-
status: Joi37.string().optional().valid(...Object.values(VehicleStatus)).allow("")
|
|
13515
|
+
status: Joi37.string().optional().valid(...Object.values(VehicleStatus)).allow(""),
|
|
13516
|
+
peopleId: Joi37.string().hex().length(24).optional().allow(null, "")
|
|
13502
13517
|
});
|
|
13503
13518
|
function MVehicle(value) {
|
|
13504
13519
|
const { error } = vehicleSchema.validate(value);
|
|
@@ -13527,6 +13542,13 @@ function MVehicle(value) {
|
|
|
13527
13542
|
throw new BadRequestError66("Invalid building unit ID format.");
|
|
13528
13543
|
}
|
|
13529
13544
|
}
|
|
13545
|
+
if (value.peopleId) {
|
|
13546
|
+
try {
|
|
13547
|
+
value.peopleId = new ObjectId40(value.peopleId);
|
|
13548
|
+
} catch (error2) {
|
|
13549
|
+
throw new BadRequestError66("Invalid building unit ID format.");
|
|
13550
|
+
}
|
|
13551
|
+
}
|
|
13530
13552
|
const createdAtDate = value.createdAt ? new Date(value.createdAt) : /* @__PURE__ */ new Date();
|
|
13531
13553
|
const expiredDate = new Date(createdAtDate);
|
|
13532
13554
|
expiredDate.setFullYear(expiredDate.getFullYear() + 10);
|
|
@@ -13551,6 +13573,7 @@ function MVehicle(value) {
|
|
|
13551
13573
|
end: value.end ?? expiredAt,
|
|
13552
13574
|
status: value.status ?? "active" /* ACTIVE */,
|
|
13553
13575
|
unitName: value.unitName ?? "",
|
|
13576
|
+
peopleId: value.peopleId ?? "",
|
|
13554
13577
|
createdAt,
|
|
13555
13578
|
updatedAt: value.updatedAt ?? "",
|
|
13556
13579
|
deletedAt: value.deletedAt ?? ""
|
|
@@ -13615,7 +13638,7 @@ import {
|
|
|
13615
13638
|
makeCacheKey as makeCacheKey23,
|
|
13616
13639
|
NotFoundError as NotFoundError17,
|
|
13617
13640
|
paginate as paginate18,
|
|
13618
|
-
toObjectId as
|
|
13641
|
+
toObjectId as toObjectId7,
|
|
13619
13642
|
useAtlas as useAtlas31,
|
|
13620
13643
|
useCache as useCache24
|
|
13621
13644
|
} from "@7365admin1/node-server-utils";
|
|
@@ -14340,7 +14363,7 @@ function useVehicleRepo() {
|
|
|
14340
14363
|
page = page > 0 ? page - 1 : 0;
|
|
14341
14364
|
const skip = page * limit;
|
|
14342
14365
|
try {
|
|
14343
|
-
const unit =
|
|
14366
|
+
const unit = toObjectId7(unitId);
|
|
14344
14367
|
const query = {
|
|
14345
14368
|
unit
|
|
14346
14369
|
};
|
|
@@ -14413,7 +14436,7 @@ import {
|
|
|
14413
14436
|
useAtlas as useAtlas32,
|
|
14414
14437
|
useCache as useCache25,
|
|
14415
14438
|
AppError as AppError10,
|
|
14416
|
-
toObjectId as
|
|
14439
|
+
toObjectId as toObjectId8
|
|
14417
14440
|
} from "@7365admin1/node-server-utils";
|
|
14418
14441
|
import { ObjectId as ObjectId42 } from "mongodb";
|
|
14419
14442
|
var site_people_namespace_collection = "site.people";
|
|
@@ -14727,7 +14750,7 @@ function usePersonRepo() {
|
|
|
14727
14750
|
}
|
|
14728
14751
|
async function getPeopleByUnit({
|
|
14729
14752
|
status = "active",
|
|
14730
|
-
type,
|
|
14753
|
+
type = [],
|
|
14731
14754
|
unit
|
|
14732
14755
|
}, session) {
|
|
14733
14756
|
const cacheKey = makeCacheKey24(site_people_namespace_collection, {
|
|
@@ -14736,13 +14759,20 @@ function usePersonRepo() {
|
|
|
14736
14759
|
type,
|
|
14737
14760
|
key: "get-residents-by-unit"
|
|
14738
14761
|
});
|
|
14762
|
+
const cacheData = await getCache(cacheKey);
|
|
14763
|
+
if (cacheData) {
|
|
14764
|
+
logger50.info(`Cache hit for key: ${cacheKey}`);
|
|
14765
|
+
return cacheData;
|
|
14766
|
+
}
|
|
14739
14767
|
try {
|
|
14740
|
-
const
|
|
14741
|
-
|
|
14742
|
-
|
|
14743
|
-
|
|
14744
|
-
|
|
14745
|
-
|
|
14768
|
+
const query = {
|
|
14769
|
+
unit,
|
|
14770
|
+
status,
|
|
14771
|
+
...Array.isArray(type) && type.length > 0 && {
|
|
14772
|
+
type: { $in: type }
|
|
14773
|
+
}
|
|
14774
|
+
};
|
|
14775
|
+
const data = await collection.find(query).sort({ _id: -1 }).toArray();
|
|
14746
14776
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
14747
14777
|
logger50.info(`Cache set for key: ${cacheKey}`);
|
|
14748
14778
|
}).catch((err) => {
|
|
@@ -14884,13 +14914,14 @@ function usePersonRepo() {
|
|
|
14884
14914
|
throw new InternalServerError25("Failed to retrieve person by NRIC.");
|
|
14885
14915
|
}
|
|
14886
14916
|
}
|
|
14887
|
-
async function
|
|
14917
|
+
async function pushVehicleById(id, plate, session) {
|
|
14888
14918
|
const { plateNumber, recNo } = plate;
|
|
14889
14919
|
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
14920
|
+
const _id = toObjectId8(id);
|
|
14890
14921
|
try {
|
|
14891
14922
|
const updateExisting = await collection.updateOne(
|
|
14892
14923
|
{
|
|
14893
|
-
|
|
14924
|
+
_id,
|
|
14894
14925
|
"plates.plateNumber": plateNumber
|
|
14895
14926
|
},
|
|
14896
14927
|
{
|
|
@@ -14903,7 +14934,7 @@ function usePersonRepo() {
|
|
|
14903
14934
|
);
|
|
14904
14935
|
if (updateExisting.matchedCount === 0) {
|
|
14905
14936
|
await collection.updateOne(
|
|
14906
|
-
{
|
|
14937
|
+
{ _id },
|
|
14907
14938
|
{
|
|
14908
14939
|
$push: {
|
|
14909
14940
|
plates: {
|
|
@@ -14944,7 +14975,7 @@ function usePersonRepo() {
|
|
|
14944
14975
|
}
|
|
14945
14976
|
}
|
|
14946
14977
|
async function getByUserId(userId) {
|
|
14947
|
-
const user =
|
|
14978
|
+
const user = toObjectId8(userId);
|
|
14948
14979
|
const cacheKey = makeCacheKey24(site_people_namespace_collection, {
|
|
14949
14980
|
user: userId
|
|
14950
14981
|
});
|
|
@@ -14995,7 +15026,7 @@ function usePersonRepo() {
|
|
|
14995
15026
|
getCompany,
|
|
14996
15027
|
getPeopleByPlateNumber,
|
|
14997
15028
|
getPeopleByNRIC,
|
|
14998
|
-
|
|
15029
|
+
pushVehicleById,
|
|
14999
15030
|
pullVehicleByRecNo,
|
|
15000
15031
|
getByUserId
|
|
15001
15032
|
};
|
|
@@ -15026,7 +15057,7 @@ function useVehicleService() {
|
|
|
15026
15057
|
} = useDahuaService();
|
|
15027
15058
|
const { getAllCameraWithPassword: _getAllSiteCameras } = useSiteCameraRepo();
|
|
15028
15059
|
const { getById: _getById } = useOrgRepo();
|
|
15029
|
-
const {
|
|
15060
|
+
const { pushVehicleById: _pushVehicleById } = usePersonRepo();
|
|
15030
15061
|
const { pullVehicleByRecNo: _pullVehicleByRecNo } = usePersonRepo();
|
|
15031
15062
|
async function add(value) {
|
|
15032
15063
|
const session = useAtlas33.getClient()?.startSession();
|
|
@@ -15133,9 +15164,9 @@ function useVehicleService() {
|
|
|
15133
15164
|
}
|
|
15134
15165
|
const responseData = dahuaResponse?.data?.toString("utf-8") ?? "";
|
|
15135
15166
|
vehicleValue.recNo = responseData.split("=")[1]?.trim();
|
|
15136
|
-
if (value.
|
|
15137
|
-
await
|
|
15138
|
-
value.
|
|
15167
|
+
if (value.peopleId && vehicleValue.recNo) {
|
|
15168
|
+
await _pushVehicleById(
|
|
15169
|
+
value.peopleId,
|
|
15139
15170
|
{
|
|
15140
15171
|
plateNumber,
|
|
15141
15172
|
recNo: vehicleValue.recNo
|
|
@@ -15295,9 +15326,9 @@ function useVehicleService() {
|
|
|
15295
15326
|
value.recNo = responseData.split("=")[1]?.trim();
|
|
15296
15327
|
}
|
|
15297
15328
|
value.status = "active" /* ACTIVE */;
|
|
15298
|
-
if (vehicle.
|
|
15299
|
-
await
|
|
15300
|
-
vehicle.
|
|
15329
|
+
if (vehicle.peopleId && value.recNo) {
|
|
15330
|
+
await _pushVehicleById(
|
|
15331
|
+
vehicle.peopleId,
|
|
15301
15332
|
{
|
|
15302
15333
|
plateNumber: _plateNumber,
|
|
15303
15334
|
recNo: value.recNo
|
|
@@ -15412,9 +15443,9 @@ function useVehicleService() {
|
|
|
15412
15443
|
value.recNo = responseData.split("=")[1]?.trim();
|
|
15413
15444
|
}
|
|
15414
15445
|
value.status = "active" /* ACTIVE */;
|
|
15415
|
-
if (vehicle.
|
|
15416
|
-
await
|
|
15417
|
-
vehicle.
|
|
15446
|
+
if (vehicle.peopleId && value.recNo) {
|
|
15447
|
+
await _pushVehicleById(
|
|
15448
|
+
vehicle.peopleId,
|
|
15418
15449
|
{
|
|
15419
15450
|
plateNumber: _plateNumber,
|
|
15420
15451
|
recNo: value.recNo
|
|
@@ -15451,7 +15482,7 @@ function useVehicleService() {
|
|
|
15451
15482
|
const _start = vehicle.start;
|
|
15452
15483
|
const _end = vehicle.end;
|
|
15453
15484
|
const _recNo = plate.recNo;
|
|
15454
|
-
const _type = plate.type;
|
|
15485
|
+
const _type = value.type ? value.type : plate.type;
|
|
15455
15486
|
const { name, plateNumber, start, end, recNo, type, unit, site, ...rest } = value;
|
|
15456
15487
|
const startDahua = value.start ? formatDahuaDate(new Date(value.start)) : formatDahuaDate(new Date(_start));
|
|
15457
15488
|
const endDahua = value.end ? formatDahuaDate(new Date(value.end)) : formatDahuaDate(new Date(_end));
|
|
@@ -15479,20 +15510,60 @@ function useVehicleService() {
|
|
|
15479
15510
|
}
|
|
15480
15511
|
for (const camera of siteCameras) {
|
|
15481
15512
|
const { host, username, password } = camera;
|
|
15482
|
-
|
|
15483
|
-
|
|
15484
|
-
|
|
15485
|
-
|
|
15486
|
-
|
|
15487
|
-
|
|
15488
|
-
|
|
15489
|
-
|
|
15490
|
-
|
|
15491
|
-
|
|
15492
|
-
|
|
15493
|
-
|
|
15494
|
-
|
|
15495
|
-
|
|
15513
|
+
if (value.type) {
|
|
15514
|
+
const removePlateNumber = {
|
|
15515
|
+
host,
|
|
15516
|
+
username,
|
|
15517
|
+
password,
|
|
15518
|
+
mode: plate.type === "blocklist" /* BLOCKLIST */ ? "TrafficBlackList" /* TRAFFIC_BLACKLIST */ : "TrafficRedList" /* TRAFFIC_REDLIST */,
|
|
15519
|
+
//whitelist or blocklist
|
|
15520
|
+
recno: _recNo
|
|
15521
|
+
};
|
|
15522
|
+
const responseForDeletion = await _removePlateNumber(
|
|
15523
|
+
removePlateNumber
|
|
15524
|
+
);
|
|
15525
|
+
if (responseForDeletion?.statusCode !== 200) {
|
|
15526
|
+
throw new BadRequestError69(
|
|
15527
|
+
"Failed to delete plate number to ANPR"
|
|
15528
|
+
);
|
|
15529
|
+
}
|
|
15530
|
+
const dahuaPayload = {
|
|
15531
|
+
host,
|
|
15532
|
+
username,
|
|
15533
|
+
password,
|
|
15534
|
+
plateNumber: _plateNumber,
|
|
15535
|
+
mode: value.type === "blocklist" /* BLOCKLIST */ ? "TrafficBlackList" /* TRAFFIC_BLACKLIST */ : "TrafficRedList" /* TRAFFIC_REDLIST */,
|
|
15536
|
+
//whitelist or blocklist
|
|
15537
|
+
owner: _name,
|
|
15538
|
+
...startDahua ? { start: startDahua } : {},
|
|
15539
|
+
...endDahua ? { end: endDahua } : {}
|
|
15540
|
+
};
|
|
15541
|
+
const dahuaResponse = await _addPlateNumber(dahuaPayload);
|
|
15542
|
+
if (dahuaResponse?.statusCode !== 200) {
|
|
15543
|
+
throw new BadRequestError69(
|
|
15544
|
+
"Failed to update plate number to ANPR"
|
|
15545
|
+
);
|
|
15546
|
+
}
|
|
15547
|
+
const responseData = dahuaResponse?.data?.toString("utf-8") ?? "";
|
|
15548
|
+
value.recNo = responseData.split("=")[1]?.trim();
|
|
15549
|
+
} else {
|
|
15550
|
+
const dahuaPayload = {
|
|
15551
|
+
host,
|
|
15552
|
+
username,
|
|
15553
|
+
password,
|
|
15554
|
+
plateNumber: plateNumber ? plateNumber : _plateNumber,
|
|
15555
|
+
recno: _recNo,
|
|
15556
|
+
mode: _type === "blocklist" /* BLOCKLIST */ ? "TrafficBlackList" /* TRAFFIC_BLACKLIST */ : "TrafficRedList" /* TRAFFIC_REDLIST */,
|
|
15557
|
+
start: startDahua,
|
|
15558
|
+
end: endDahua,
|
|
15559
|
+
owner: name ? name : _name
|
|
15560
|
+
};
|
|
15561
|
+
const dahuaResponse = await _updatePlateNumber(dahuaPayload);
|
|
15562
|
+
if (dahuaResponse?.statusCode !== 200) {
|
|
15563
|
+
throw new BadRequestError69(
|
|
15564
|
+
"Failed to update plate number to ANPR"
|
|
15565
|
+
);
|
|
15566
|
+
}
|
|
15496
15567
|
}
|
|
15497
15568
|
}
|
|
15498
15569
|
}
|
|
@@ -15504,7 +15575,9 @@ function useVehicleService() {
|
|
|
15504
15575
|
...end && { end },
|
|
15505
15576
|
...unit && {
|
|
15506
15577
|
unit: typeof unit === "string" ? new ObjectId43(unit) : unit
|
|
15507
|
-
}
|
|
15578
|
+
},
|
|
15579
|
+
...value.recNo && { recNo: value.recNo },
|
|
15580
|
+
...type && { type: value.type }
|
|
15508
15581
|
};
|
|
15509
15582
|
await _updateVehicleById(_id, formattedValue, session);
|
|
15510
15583
|
await session.commitTransaction();
|
|
@@ -17014,7 +17087,7 @@ import {
|
|
|
17014
17087
|
logger as logger60,
|
|
17015
17088
|
makeCacheKey as makeCacheKey26,
|
|
17016
17089
|
paginate as paginate21,
|
|
17017
|
-
toObjectId as
|
|
17090
|
+
toObjectId as toObjectId10,
|
|
17018
17091
|
useAtlas as useAtlas37,
|
|
17019
17092
|
useCache as useCache28
|
|
17020
17093
|
} from "@7365admin1/node-server-utils";
|
|
@@ -17176,8 +17249,8 @@ function useBuildingUnitRepo() {
|
|
|
17176
17249
|
const query = {
|
|
17177
17250
|
status,
|
|
17178
17251
|
...search && { $text: { $search: search } },
|
|
17179
|
-
...site && { site:
|
|
17180
|
-
...building && { building:
|
|
17252
|
+
...site && { site: toObjectId10(site) },
|
|
17253
|
+
...building && { building: toObjectId10(building) }
|
|
17181
17254
|
};
|
|
17182
17255
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
17183
17256
|
const cacheParams = {
|
|
@@ -19257,8 +19330,24 @@ function useCustomerSiteController() {
|
|
|
19257
19330
|
import { BadRequestError as BadRequestError88, logger as logger69 } from "@7365admin1/node-server-utils";
|
|
19258
19331
|
import Joi51 from "joi";
|
|
19259
19332
|
import { ObjectId as ObjectId50 } from "mongodb";
|
|
19333
|
+
|
|
19334
|
+
// src/models/base.model.ts
|
|
19335
|
+
var AppServiceType = /* @__PURE__ */ ((AppServiceType2) => {
|
|
19336
|
+
AppServiceType2["REAL_ESTATE_DEVELOPER"] = "real_estate_developer";
|
|
19337
|
+
AppServiceType2["PROPERTY_MANAGEMENT_AGENCY"] = "property_management_agency";
|
|
19338
|
+
AppServiceType2["SECURITY_AGENCY"] = "security_agency";
|
|
19339
|
+
AppServiceType2["CLEANING_SERVICES"] = "cleaning_services";
|
|
19340
|
+
AppServiceType2["MECHANICAL_ELECTRICAL_SERVICES"] = "mechanical_electrical_services";
|
|
19341
|
+
AppServiceType2["LANDSCAPING_SERVICES"] = "landscaping_services";
|
|
19342
|
+
AppServiceType2["PEST_CONTROL_SERVICES"] = "pest_control_services";
|
|
19343
|
+
AppServiceType2["POOL_MAINTENANCE_SERVICES"] = "pool_maintenance_services";
|
|
19344
|
+
return AppServiceType2;
|
|
19345
|
+
})(AppServiceType || {});
|
|
19346
|
+
|
|
19347
|
+
// src/models/attendance-settings.model.ts
|
|
19260
19348
|
var attendanceSettingsSchema = Joi51.object({
|
|
19261
19349
|
site: Joi51.string().hex().required(),
|
|
19350
|
+
serviceType: Joi51.string().valid(...Object.values(AppServiceType)).required(),
|
|
19262
19351
|
isLocationEnabled: Joi51.boolean().required(),
|
|
19263
19352
|
location: Joi51.when("isLocationEnabled", {
|
|
19264
19353
|
is: true,
|
|
@@ -19301,6 +19390,7 @@ function MAttendanceSettings(value) {
|
|
|
19301
19390
|
}
|
|
19302
19391
|
return {
|
|
19303
19392
|
site: value.site,
|
|
19393
|
+
serviceType: value.serviceType,
|
|
19304
19394
|
isLocationEnabled: value.isLocationEnabled,
|
|
19305
19395
|
location: value.isLocationEnabled && value.location ? value.location : void 0,
|
|
19306
19396
|
isGeofencingEnabled: value.isLocationEnabled ? value.isGeofencingEnabled ?? false : void 0,
|
|
@@ -19333,7 +19423,10 @@ function useAttendanceSettingsRepository() {
|
|
|
19333
19423
|
const { delNamespace, setCache, getCache } = useCache30(namespace_collection);
|
|
19334
19424
|
async function createIndex() {
|
|
19335
19425
|
try {
|
|
19336
|
-
await collection.createIndexes([
|
|
19426
|
+
await collection.createIndexes([
|
|
19427
|
+
{ key: { site: 1 } },
|
|
19428
|
+
{ key: { serviceType: 1 } }
|
|
19429
|
+
]);
|
|
19337
19430
|
} catch (error) {
|
|
19338
19431
|
throw new InternalServerError30(
|
|
19339
19432
|
"Failed to create index on attendance settings."
|
|
@@ -19357,15 +19450,16 @@ function useAttendanceSettingsRepository() {
|
|
|
19357
19450
|
throw error;
|
|
19358
19451
|
}
|
|
19359
19452
|
}
|
|
19360
|
-
async function getAttendanceSettingsBySite(site, session) {
|
|
19453
|
+
async function getAttendanceSettingsBySite(site, serviceType, session) {
|
|
19361
19454
|
try {
|
|
19362
19455
|
site = new ObjectId51(site);
|
|
19363
19456
|
} catch (error) {
|
|
19364
19457
|
throw new BadRequestError89("Invalid attendance settings site ID format.");
|
|
19365
19458
|
}
|
|
19366
|
-
const query = { site };
|
|
19459
|
+
const query = { site, serviceType };
|
|
19367
19460
|
const cacheKey = makeCacheKey28(namespace_collection, {
|
|
19368
|
-
site: site.toString()
|
|
19461
|
+
site: site.toString(),
|
|
19462
|
+
serviceType
|
|
19369
19463
|
});
|
|
19370
19464
|
if (!session) {
|
|
19371
19465
|
const cachedData = await getCache(cacheKey);
|
|
@@ -19437,8 +19531,8 @@ function useAttendanceSettingsRepository() {
|
|
|
19437
19531
|
return {
|
|
19438
19532
|
createIndex,
|
|
19439
19533
|
createAttendanceSettings,
|
|
19440
|
-
|
|
19441
|
-
|
|
19534
|
+
getAttendanceSettingsBySite,
|
|
19535
|
+
updateAttendanceSettings
|
|
19442
19536
|
};
|
|
19443
19537
|
}
|
|
19444
19538
|
|
|
@@ -19449,9 +19543,9 @@ function useAttendanceSettingsService() {
|
|
|
19449
19543
|
createAttendanceSettings,
|
|
19450
19544
|
getAttendanceSettingsBySite: _getAttendanceSettingsBySite
|
|
19451
19545
|
} = useAttendanceSettingsRepository();
|
|
19452
|
-
async function getAttendanceSettingsBySite(site) {
|
|
19546
|
+
async function getAttendanceSettingsBySite(site, serviceType) {
|
|
19453
19547
|
try {
|
|
19454
|
-
let settings = await _getAttendanceSettingsBySite(site);
|
|
19548
|
+
let settings = await _getAttendanceSettingsBySite(site, serviceType);
|
|
19455
19549
|
if (!settings) {
|
|
19456
19550
|
logger71.info(
|
|
19457
19551
|
`No attendance settings found for site ${site}, creating default settings`
|
|
@@ -19462,12 +19556,13 @@ function useAttendanceSettingsService() {
|
|
|
19462
19556
|
await createAttendanceSettings(
|
|
19463
19557
|
{
|
|
19464
19558
|
site,
|
|
19559
|
+
serviceType,
|
|
19465
19560
|
isLocationEnabled: false
|
|
19466
19561
|
},
|
|
19467
19562
|
session
|
|
19468
19563
|
);
|
|
19469
19564
|
await session?.commitTransaction();
|
|
19470
|
-
settings = await _getAttendanceSettingsBySite(site);
|
|
19565
|
+
settings = await _getAttendanceSettingsBySite(site, serviceType);
|
|
19471
19566
|
} catch (error) {
|
|
19472
19567
|
await session?.abortTransaction();
|
|
19473
19568
|
throw error;
|
|
@@ -19491,16 +19586,21 @@ function useAttendanceSettingsController() {
|
|
|
19491
19586
|
const { getAttendanceSettingsBySite: _getAttendanceSettingsBySite } = useAttendanceSettingsService();
|
|
19492
19587
|
const { updateAttendanceSettings: _updateAttendanceSettings } = useAttendanceSettingsRepository();
|
|
19493
19588
|
async function getAttendanceSettingsBySite(req, res, next) {
|
|
19494
|
-
const
|
|
19495
|
-
const
|
|
19496
|
-
|
|
19589
|
+
const query = { ...req.query, ...req.params };
|
|
19590
|
+
const validation = Joi52.object({
|
|
19591
|
+
site: Joi52.string().hex().required(),
|
|
19592
|
+
serviceType: Joi52.string().valid(...Object.values(AppServiceType)).required()
|
|
19593
|
+
});
|
|
19594
|
+
const { error } = validation.validate(query);
|
|
19497
19595
|
if (error) {
|
|
19498
19596
|
logger72.log({ level: "error", message: error.message });
|
|
19499
19597
|
next(new BadRequestError90(error.message));
|
|
19500
19598
|
return;
|
|
19501
19599
|
}
|
|
19600
|
+
const site = req.params.site ?? "";
|
|
19601
|
+
const serviceType = req.query.serviceType ?? "";
|
|
19502
19602
|
try {
|
|
19503
|
-
const data = await _getAttendanceSettingsBySite(site);
|
|
19603
|
+
const data = await _getAttendanceSettingsBySite(site, serviceType);
|
|
19504
19604
|
res.json(data);
|
|
19505
19605
|
return;
|
|
19506
19606
|
} catch (error2) {
|
|
@@ -19539,6 +19639,7 @@ import Joi53 from "joi";
|
|
|
19539
19639
|
import { ObjectId as ObjectId52 } from "mongodb";
|
|
19540
19640
|
var attendanceSchema = Joi53.object({
|
|
19541
19641
|
site: Joi53.string().hex().required(),
|
|
19642
|
+
serviceType: Joi53.string().valid(...Object.values(AppServiceType)).required(),
|
|
19542
19643
|
checkIn: Joi53.object({
|
|
19543
19644
|
timestamp: Joi53.date().required(),
|
|
19544
19645
|
location: Joi53.object({
|
|
@@ -19571,6 +19672,7 @@ function MAttendance(value) {
|
|
|
19571
19672
|
}
|
|
19572
19673
|
return {
|
|
19573
19674
|
site: value.site,
|
|
19675
|
+
serviceType: value.serviceType,
|
|
19574
19676
|
checkIn: value.checkIn,
|
|
19575
19677
|
checkOut: null,
|
|
19576
19678
|
user: value.user,
|
|
@@ -19604,6 +19706,7 @@ function useAttendanceRepository() {
|
|
|
19604
19706
|
try {
|
|
19605
19707
|
await collection.createIndexes([
|
|
19606
19708
|
{ key: { site: 1 } },
|
|
19709
|
+
{ key: { serviceType: 1 } },
|
|
19607
19710
|
{ key: { user: 1 } }
|
|
19608
19711
|
]);
|
|
19609
19712
|
} catch (error) {
|
|
@@ -19631,13 +19734,15 @@ function useAttendanceRepository() {
|
|
|
19631
19734
|
page = 1,
|
|
19632
19735
|
limit = 10,
|
|
19633
19736
|
search = "",
|
|
19634
|
-
site
|
|
19737
|
+
site,
|
|
19738
|
+
serviceType
|
|
19635
19739
|
}) {
|
|
19636
19740
|
page = page > 0 ? page - 1 : 0;
|
|
19637
|
-
const query = {};
|
|
19741
|
+
const query = { serviceType };
|
|
19638
19742
|
const cacheOptions = {
|
|
19639
19743
|
page,
|
|
19640
|
-
limit
|
|
19744
|
+
limit,
|
|
19745
|
+
serviceType
|
|
19641
19746
|
};
|
|
19642
19747
|
try {
|
|
19643
19748
|
site = new ObjectId53(site);
|
|
@@ -20014,7 +20119,11 @@ function useAttendanceService() {
|
|
|
20014
20119
|
const session = useAtlas46.getClient()?.startSession();
|
|
20015
20120
|
try {
|
|
20016
20121
|
session?.startTransaction();
|
|
20017
|
-
const setting = await getAttendanceSettingsBySite(
|
|
20122
|
+
const setting = await getAttendanceSettingsBySite(
|
|
20123
|
+
value.site,
|
|
20124
|
+
value.serviceType,
|
|
20125
|
+
session
|
|
20126
|
+
);
|
|
20018
20127
|
if (setting?.isLocationEnabled && setting?.isGeofencingEnabled) {
|
|
20019
20128
|
if (!setting.location || !value.checkIn.location) {
|
|
20020
20129
|
throw new BadRequestError93("Location data is required for check-in.");
|
|
@@ -20061,6 +20170,7 @@ function useAttendanceService() {
|
|
|
20061
20170
|
const attendance = await getRawAttendanceById(_id, session);
|
|
20062
20171
|
const setting = await getAttendanceSettingsBySite(
|
|
20063
20172
|
attendance.site,
|
|
20173
|
+
attendance.serviceType,
|
|
20064
20174
|
session
|
|
20065
20175
|
);
|
|
20066
20176
|
if (setting?.isLocationEnabled && setting?.isGeofencingEnabled) {
|
|
@@ -20146,7 +20256,8 @@ function useAttendanceController() {
|
|
|
20146
20256
|
page: Joi54.number().min(1).optional().allow("", null),
|
|
20147
20257
|
limit: Joi54.number().min(1).optional().allow("", null),
|
|
20148
20258
|
search: Joi54.string().optional().allow("", null),
|
|
20149
|
-
site: Joi54.string().hex().required()
|
|
20259
|
+
site: Joi54.string().hex().required(),
|
|
20260
|
+
serviceType: Joi54.string().valid(...Object.values(AppServiceType)).required()
|
|
20150
20261
|
});
|
|
20151
20262
|
const { error } = validation.validate(query);
|
|
20152
20263
|
if (error) {
|
|
@@ -20158,12 +20269,14 @@ function useAttendanceController() {
|
|
|
20158
20269
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
20159
20270
|
const search = req.query.search ?? "";
|
|
20160
20271
|
const site = req.params.site ?? "";
|
|
20272
|
+
const serviceType = req.query.serviceType ?? "";
|
|
20161
20273
|
try {
|
|
20162
20274
|
const data = await _getAllAttendances({
|
|
20163
20275
|
page,
|
|
20164
20276
|
limit,
|
|
20165
20277
|
search,
|
|
20166
|
-
site
|
|
20278
|
+
site,
|
|
20279
|
+
serviceType
|
|
20167
20280
|
});
|
|
20168
20281
|
res.json(data);
|
|
20169
20282
|
return;
|
|
@@ -21601,20 +21714,37 @@ function usePersonController() {
|
|
|
21601
21714
|
}
|
|
21602
21715
|
}
|
|
21603
21716
|
async function getPeopleByUnit(req, res, next) {
|
|
21604
|
-
const
|
|
21605
|
-
|
|
21606
|
-
|
|
21607
|
-
|
|
21608
|
-
|
|
21609
|
-
|
|
21610
|
-
|
|
21611
|
-
|
|
21612
|
-
|
|
21613
|
-
|
|
21614
|
-
|
|
21615
|
-
|
|
21616
|
-
|
|
21617
|
-
|
|
21717
|
+
const PERSON_TYPES3 = Object.values(PersonTypes);
|
|
21718
|
+
console.log(req.query);
|
|
21719
|
+
try {
|
|
21720
|
+
const schema2 = Joi58.object({
|
|
21721
|
+
unit: Joi58.string().required(),
|
|
21722
|
+
type: Joi58.string().optional().allow("", null).custom((value2, helpers) => {
|
|
21723
|
+
if (!value2)
|
|
21724
|
+
return ["resident" /* RESIDENT */];
|
|
21725
|
+
const parsed = value2.split(",").map((v) => v.trim()).filter(Boolean);
|
|
21726
|
+
for (const t of parsed) {
|
|
21727
|
+
if (!PERSON_TYPES3.includes(t)) {
|
|
21728
|
+
return helpers.error("any.only");
|
|
21729
|
+
}
|
|
21730
|
+
}
|
|
21731
|
+
return parsed;
|
|
21732
|
+
}).messages({
|
|
21733
|
+
"any.only": `Type must be one of: ${PERSON_TYPES3.join(", ")}`
|
|
21734
|
+
}),
|
|
21735
|
+
status: Joi58.string().valid(...Object.values(PersonStatus)).optional().default("active" /* ACTIVE */)
|
|
21736
|
+
});
|
|
21737
|
+
const { error, value } = schema2.validate(
|
|
21738
|
+
{ unit: req.params.unit, ...req.query },
|
|
21739
|
+
{ abortEarly: false }
|
|
21740
|
+
);
|
|
21741
|
+
if (error) {
|
|
21742
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
21743
|
+
logger82.log({ level: "error", message: messages });
|
|
21744
|
+
next(new BadRequestError100(messages));
|
|
21745
|
+
return;
|
|
21746
|
+
}
|
|
21747
|
+
const { unit, type, status } = value;
|
|
21618
21748
|
const data = await _getPeopleByUnit({
|
|
21619
21749
|
status,
|
|
21620
21750
|
type,
|
|
@@ -21622,9 +21752,9 @@ function usePersonController() {
|
|
|
21622
21752
|
});
|
|
21623
21753
|
res.json(data);
|
|
21624
21754
|
return;
|
|
21625
|
-
} catch (
|
|
21626
|
-
logger82.log({ level: "error", message:
|
|
21627
|
-
next(
|
|
21755
|
+
} catch (error) {
|
|
21756
|
+
logger82.log({ level: "error", message: error.message });
|
|
21757
|
+
next(error);
|
|
21628
21758
|
return;
|
|
21629
21759
|
}
|
|
21630
21760
|
}
|
|
@@ -25419,7 +25549,7 @@ import {
|
|
|
25419
25549
|
makeCacheKey as makeCacheKey37,
|
|
25420
25550
|
NotFoundError as NotFoundError27,
|
|
25421
25551
|
paginate as paginate31,
|
|
25422
|
-
toObjectId as
|
|
25552
|
+
toObjectId as toObjectId11,
|
|
25423
25553
|
useAtlas as useAtlas60,
|
|
25424
25554
|
useCache as useCache39
|
|
25425
25555
|
} from "@7365admin1/node-server-utils";
|
|
@@ -25475,7 +25605,7 @@ function useSiteFacilityBookingRepo() {
|
|
|
25475
25605
|
page = page > 0 ? page - 1 : 0;
|
|
25476
25606
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
25477
25607
|
const skip = page * limit;
|
|
25478
|
-
const siteId =
|
|
25608
|
+
const siteId = toObjectId11(site);
|
|
25479
25609
|
const query = {
|
|
25480
25610
|
site: siteId,
|
|
25481
25611
|
status,
|
|
@@ -25521,7 +25651,7 @@ function useSiteFacilityBookingRepo() {
|
|
|
25521
25651
|
}
|
|
25522
25652
|
}
|
|
25523
25653
|
async function getSiteFacilityBookingById(id, session) {
|
|
25524
|
-
const _id =
|
|
25654
|
+
const _id = toObjectId11(id);
|
|
25525
25655
|
const cacheKey = makeCacheKey37(facility_bookings_namespace_collection, {
|
|
25526
25656
|
id
|
|
25527
25657
|
});
|
|
@@ -25547,17 +25677,17 @@ function useSiteFacilityBookingRepo() {
|
|
|
25547
25677
|
}
|
|
25548
25678
|
async function updateSiteFacilityBookingById(id, value, session) {
|
|
25549
25679
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
25550
|
-
const _id =
|
|
25680
|
+
const _id = toObjectId11(id);
|
|
25551
25681
|
if (value.site)
|
|
25552
|
-
value.site = typeof value.site === "string" ?
|
|
25682
|
+
value.site = typeof value.site === "string" ? toObjectId11(value.site) : value.site;
|
|
25553
25683
|
if (value.user)
|
|
25554
|
-
value.user = typeof value.user === "string" ?
|
|
25684
|
+
value.user = typeof value.user === "string" ? toObjectId11(value.user) : value.user;
|
|
25555
25685
|
if (value.date)
|
|
25556
25686
|
value.date = value.date ? new Date(value.date).toISOString() : value.date;
|
|
25557
25687
|
if (value.approvedBy)
|
|
25558
|
-
value.approvedBy = typeof value.approvedBy === "string" ?
|
|
25688
|
+
value.approvedBy = typeof value.approvedBy === "string" ? toObjectId11(value.approvedBy) : value.approvedBy;
|
|
25559
25689
|
if (value.createdBy)
|
|
25560
|
-
value.createdBy = typeof value.createdBy === "string" ?
|
|
25690
|
+
value.createdBy = typeof value.createdBy === "string" ? toObjectId11(value.createdBy) : value.createdBy;
|
|
25561
25691
|
try {
|
|
25562
25692
|
const res = await collection.updateOne(
|
|
25563
25693
|
{ _id },
|
|
@@ -28199,7 +28329,7 @@ function useSiteBillingConfigurationController() {
|
|
|
28199
28329
|
(acc, [key, value2]) => ({ ...acc, [key]: value2 }),
|
|
28200
28330
|
{}
|
|
28201
28331
|
);
|
|
28202
|
-
req.body.createdBy = cookies?.["user"].toString()
|
|
28332
|
+
req.body.createdBy = cookies?.["user"] ? cookies["user"].toString() : req.body.createdBy;
|
|
28203
28333
|
const data = { ...req.body };
|
|
28204
28334
|
const { error, value } = schemaBillingConfiguration.validate(data);
|
|
28205
28335
|
if (error) {
|
|
@@ -35329,7 +35459,7 @@ function useStatementOfAccountController() {
|
|
|
35329
35459
|
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
35330
35460
|
{}
|
|
35331
35461
|
);
|
|
35332
|
-
req.body.createdBy = cookies?.["user"].toString()
|
|
35462
|
+
req.body.createdBy = cookies?.["user"] ? cookies["user"].toString() : req.body.createdBy;
|
|
35333
35463
|
const data = { ...req.body };
|
|
35334
35464
|
const validation = Joi93.object({
|
|
35335
35465
|
dateFrom: Joi93.string().required(),
|
|
@@ -40002,7 +40132,7 @@ import {
|
|
|
40002
40132
|
InternalServerError as InternalServerError59,
|
|
40003
40133
|
logger as logger155,
|
|
40004
40134
|
makeCacheKey as makeCacheKey57,
|
|
40005
|
-
toObjectId as
|
|
40135
|
+
toObjectId as toObjectId12,
|
|
40006
40136
|
useAtlas as useAtlas97,
|
|
40007
40137
|
useCache as useCache59
|
|
40008
40138
|
} from "@7365admin1/node-server-utils";
|
|
@@ -40094,7 +40224,7 @@ function useNewDashboardRepo() {
|
|
|
40094
40224
|
securityDashboardCollection
|
|
40095
40225
|
);
|
|
40096
40226
|
async function getMetric(collectionString, siteId, period) {
|
|
40097
|
-
const site =
|
|
40227
|
+
const site = toObjectId12(siteId);
|
|
40098
40228
|
const range = getPeriodRangeWithPrevious(period);
|
|
40099
40229
|
const collection = db.collection(collectionString);
|
|
40100
40230
|
const current = await collection.countDocuments({
|
|
@@ -42072,7 +42202,7 @@ import {
|
|
|
42072
42202
|
InternalServerError as InternalServerError63,
|
|
42073
42203
|
logger as logger163,
|
|
42074
42204
|
makeCacheKey as makeCacheKey61,
|
|
42075
|
-
toObjectId as
|
|
42205
|
+
toObjectId as toObjectId13,
|
|
42076
42206
|
useAtlas as useAtlas102,
|
|
42077
42207
|
useCache as useCache63
|
|
42078
42208
|
} from "@7365admin1/node-server-utils";
|
|
@@ -42151,7 +42281,7 @@ function useOvernightParkingRepo() {
|
|
|
42151
42281
|
}
|
|
42152
42282
|
}
|
|
42153
42283
|
async function getSiteOvernightParking(site) {
|
|
42154
|
-
const siteId =
|
|
42284
|
+
const siteId = toObjectId13(site);
|
|
42155
42285
|
const cacheKey = makeCacheKey61(overnight_parking_namespace_collection, {
|
|
42156
42286
|
site
|
|
42157
42287
|
});
|
|
@@ -42247,7 +42377,7 @@ function useOvernightParkingController() {
|
|
|
42247
42377
|
|
|
42248
42378
|
// src/models/overnight-parking-request.model.ts
|
|
42249
42379
|
import Joi118 from "joi";
|
|
42250
|
-
import { toObjectId as
|
|
42380
|
+
import { toObjectId as toObjectId14 } from "@7365admin1/node-server-utils";
|
|
42251
42381
|
var OvernightParkingRequestStatus = /* @__PURE__ */ ((OvernightParkingRequestStatus2) => {
|
|
42252
42382
|
OvernightParkingRequestStatus2["PENDING"] = "pending";
|
|
42253
42383
|
OvernightParkingRequestStatus2["APPROVED"] = "approved";
|
|
@@ -42284,7 +42414,7 @@ function MOvernightParkingRequest(value) {
|
|
|
42284
42414
|
throw new Error(error.details[0].message);
|
|
42285
42415
|
}
|
|
42286
42416
|
if (value.site && typeof value.site === "string")
|
|
42287
|
-
value.site =
|
|
42417
|
+
value.site = toObjectId14(value.site);
|
|
42288
42418
|
const data = {
|
|
42289
42419
|
...value,
|
|
42290
42420
|
createdAt: value.createdAt ? new Date(value.createdAt).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -42301,7 +42431,7 @@ import {
|
|
|
42301
42431
|
logger as logger165,
|
|
42302
42432
|
makeCacheKey as makeCacheKey62,
|
|
42303
42433
|
paginate as paginate54,
|
|
42304
|
-
toObjectId as
|
|
42434
|
+
toObjectId as toObjectId15,
|
|
42305
42435
|
useAtlas as useAtlas103,
|
|
42306
42436
|
useCache as useCache64
|
|
42307
42437
|
} from "@7365admin1/node-server-utils";
|
|
@@ -42369,7 +42499,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
42369
42499
|
}) {
|
|
42370
42500
|
page = page ? page - 1 : 0;
|
|
42371
42501
|
const skip = page * limit;
|
|
42372
|
-
const siteId =
|
|
42502
|
+
const siteId = toObjectId15(site);
|
|
42373
42503
|
const query = {
|
|
42374
42504
|
site: siteId,
|
|
42375
42505
|
...status && { status }
|
|
@@ -42420,7 +42550,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
42420
42550
|
logger165.info(`Cache hit for key: ${cacheKey}`);
|
|
42421
42551
|
return cachedData;
|
|
42422
42552
|
}
|
|
42423
|
-
const _id =
|
|
42553
|
+
const _id = toObjectId15(id);
|
|
42424
42554
|
const data = await collection.findOne({ _id });
|
|
42425
42555
|
if (!data)
|
|
42426
42556
|
throw new BadRequestError187("Overnight parking request not found.");
|
|
@@ -42436,7 +42566,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
42436
42566
|
}
|
|
42437
42567
|
async function updateOvernightParkingRequestById(id, value, session) {
|
|
42438
42568
|
try {
|
|
42439
|
-
const _id =
|
|
42569
|
+
const _id = toObjectId15(id);
|
|
42440
42570
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
42441
42571
|
const data = await collection.updateOne(
|
|
42442
42572
|
{ _id },
|
|
@@ -42462,7 +42592,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
42462
42592
|
}
|
|
42463
42593
|
async function deleteOvernightParkingRequestById(id, session) {
|
|
42464
42594
|
try {
|
|
42465
|
-
const _id =
|
|
42595
|
+
const _id = toObjectId15(id);
|
|
42466
42596
|
const value = {
|
|
42467
42597
|
deletedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
42468
42598
|
status: "deleted" /* DELETED */
|
|
@@ -42491,7 +42621,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
42491
42621
|
}
|
|
42492
42622
|
async function updateExpiredRequests(site, session) {
|
|
42493
42623
|
try {
|
|
42494
|
-
const _site =
|
|
42624
|
+
const _site = toObjectId15(site);
|
|
42495
42625
|
const value = {
|
|
42496
42626
|
status: "expired" /* EXPIRED */
|
|
42497
42627
|
};
|
|
@@ -44258,7 +44388,6 @@ import { useAtlas as useAtlas108 } from "@7365admin1/node-server-utils";
|
|
|
44258
44388
|
import { ObjectId as ObjectId116 } from "mongodb";
|
|
44259
44389
|
import moment5 from "moment-timezone";
|
|
44260
44390
|
async function manpowerEvents(io) {
|
|
44261
|
-
console.log("Manpower events initialized");
|
|
44262
44391
|
let intervalId = null;
|
|
44263
44392
|
let activeConnections = 0;
|
|
44264
44393
|
const { getAttendanceDataCount: _getAttendanceDataCount } = useHrmLabsAttendanceSrvc();
|
|
@@ -45082,6 +45211,239 @@ function useRedDotPaymentController() {
|
|
|
45082
45211
|
getMerchantDetailsById
|
|
45083
45212
|
};
|
|
45084
45213
|
}
|
|
45214
|
+
|
|
45215
|
+
// src/models/verification-v2.model.ts
|
|
45216
|
+
import { BadRequestError as BadRequestError194 } from "@7365admin1/node-server-utils";
|
|
45217
|
+
import { ObjectId as ObjectId121 } from "mongodb";
|
|
45218
|
+
var VerificationType = /* @__PURE__ */ ((VerificationType2) => {
|
|
45219
|
+
VerificationType2["USER_SIGN_UP"] = "user-sign-up";
|
|
45220
|
+
VerificationType2["FORGET_PASSWORD"] = "forget-password";
|
|
45221
|
+
VerificationType2["USER_INVITE"] = "user-invite";
|
|
45222
|
+
VerificationType2["MEMBER_INVITE"] = "member-invite";
|
|
45223
|
+
return VerificationType2;
|
|
45224
|
+
})(VerificationType || {});
|
|
45225
|
+
var MVerificationV2 = class {
|
|
45226
|
+
constructor(value) {
|
|
45227
|
+
this._id = value._id ?? new ObjectId121();
|
|
45228
|
+
this.type = value.type ?? "";
|
|
45229
|
+
this.email = value.email ?? "";
|
|
45230
|
+
if (value.metadata?.role) {
|
|
45231
|
+
try {
|
|
45232
|
+
value.metadata.role = new ObjectId121(value.metadata.role);
|
|
45233
|
+
} catch (error) {
|
|
45234
|
+
throw new BadRequestError194("Invalid role ID format.");
|
|
45235
|
+
}
|
|
45236
|
+
}
|
|
45237
|
+
if (value.metadata?.org) {
|
|
45238
|
+
try {
|
|
45239
|
+
value.metadata.org = new ObjectId121(value.metadata.org);
|
|
45240
|
+
} catch (error) {
|
|
45241
|
+
throw new BadRequestError194("Invalid org ID format.");
|
|
45242
|
+
}
|
|
45243
|
+
}
|
|
45244
|
+
if (value.metadata?.siteId) {
|
|
45245
|
+
try {
|
|
45246
|
+
value.metadata.siteId = new ObjectId121(value.metadata.siteId);
|
|
45247
|
+
} catch (error) {
|
|
45248
|
+
throw new BadRequestError194("Invalid site ID format.");
|
|
45249
|
+
}
|
|
45250
|
+
}
|
|
45251
|
+
if (value.metadata?.serviceProviderOrgId) {
|
|
45252
|
+
try {
|
|
45253
|
+
value.metadata.serviceProviderOrgId = new ObjectId121(
|
|
45254
|
+
value.metadata.serviceProviderOrgId
|
|
45255
|
+
);
|
|
45256
|
+
} catch (error) {
|
|
45257
|
+
throw new BadRequestError194("Invalid service provider ID format.");
|
|
45258
|
+
}
|
|
45259
|
+
}
|
|
45260
|
+
this.metadata = { ...value.metadata };
|
|
45261
|
+
this.status = value.status ?? "pending";
|
|
45262
|
+
this.createdAt = value.createdAt ?? /* @__PURE__ */ new Date();
|
|
45263
|
+
this.updatedAt = value.updatedAt ?? null;
|
|
45264
|
+
this.expireAt = value.expireAt ?? new Date(Date.now() + 3600 * 1e3);
|
|
45265
|
+
}
|
|
45266
|
+
};
|
|
45267
|
+
|
|
45268
|
+
// src/repositories/verification-v2.repo.ts
|
|
45269
|
+
import {
|
|
45270
|
+
InternalServerError as InternalServerError68,
|
|
45271
|
+
logger as logger175,
|
|
45272
|
+
useAtlas as useAtlas111,
|
|
45273
|
+
useCache as useCache66
|
|
45274
|
+
} from "@7365admin1/node-server-utils";
|
|
45275
|
+
function useVerificationRepoV2() {
|
|
45276
|
+
const db = useAtlas111.getDb();
|
|
45277
|
+
if (!db) {
|
|
45278
|
+
throw new InternalServerError68("Unable to connect to server.");
|
|
45279
|
+
}
|
|
45280
|
+
const namespace_collection = "verifications";
|
|
45281
|
+
const collection = db.collection(namespace_collection);
|
|
45282
|
+
async function createIndex() {
|
|
45283
|
+
try {
|
|
45284
|
+
await collection.createIndex([
|
|
45285
|
+
{ email: 1 },
|
|
45286
|
+
{ type: 1 },
|
|
45287
|
+
{ status: 1 },
|
|
45288
|
+
{ "metadata.org": 1 }
|
|
45289
|
+
]);
|
|
45290
|
+
} catch (error) {
|
|
45291
|
+
throw new InternalServerError68("Failed to create index.");
|
|
45292
|
+
}
|
|
45293
|
+
}
|
|
45294
|
+
async function createTextIndex() {
|
|
45295
|
+
try {
|
|
45296
|
+
await collection.createIndex({
|
|
45297
|
+
email: "text"
|
|
45298
|
+
});
|
|
45299
|
+
} catch (error) {
|
|
45300
|
+
throw new InternalServerError68("Failed to create text index on email.");
|
|
45301
|
+
}
|
|
45302
|
+
}
|
|
45303
|
+
const { delNamespace, setCache, getCache, delCache } = useCache66(namespace_collection);
|
|
45304
|
+
async function add(value, session) {
|
|
45305
|
+
value = new MVerificationV2(value);
|
|
45306
|
+
try {
|
|
45307
|
+
const res = await collection.insertOne(value, { session });
|
|
45308
|
+
delNamespace().then(() => {
|
|
45309
|
+
logger175.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
45310
|
+
}).catch((err) => {
|
|
45311
|
+
logger175.error(
|
|
45312
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
45313
|
+
err
|
|
45314
|
+
);
|
|
45315
|
+
});
|
|
45316
|
+
return res.insertedId;
|
|
45317
|
+
} catch (error) {
|
|
45318
|
+
logger175.log({
|
|
45319
|
+
level: "info",
|
|
45320
|
+
message: String(error)
|
|
45321
|
+
});
|
|
45322
|
+
throw new InternalServerError68("Server internal error.");
|
|
45323
|
+
}
|
|
45324
|
+
}
|
|
45325
|
+
return {
|
|
45326
|
+
createIndex,
|
|
45327
|
+
createTextIndex,
|
|
45328
|
+
add
|
|
45329
|
+
};
|
|
45330
|
+
}
|
|
45331
|
+
|
|
45332
|
+
// src/services/verification-v2.service.ts
|
|
45333
|
+
import {
|
|
45334
|
+
useMailer as useMailer4,
|
|
45335
|
+
compileHandlebar as compileHandlebar4,
|
|
45336
|
+
logger as logger176,
|
|
45337
|
+
getDirectory as getDirectory4,
|
|
45338
|
+
BadRequestError as BadRequestError196,
|
|
45339
|
+
hashPassword as hashPassword4
|
|
45340
|
+
} from "@7365admin1/node-server-utils";
|
|
45341
|
+
function useVerificationServiceV2() {
|
|
45342
|
+
const MailerConfig = {
|
|
45343
|
+
host: MAILER_TRANSPORT_HOST,
|
|
45344
|
+
port: MAILER_TRANSPORT_PORT,
|
|
45345
|
+
secure: MAILER_TRANSPORT_SECURE,
|
|
45346
|
+
email: MAILER_EMAIL,
|
|
45347
|
+
password: MAILER_PASSWORD
|
|
45348
|
+
};
|
|
45349
|
+
const mailer = new useMailer4(MailerConfig);
|
|
45350
|
+
const { add } = useVerificationRepoV2();
|
|
45351
|
+
const { getUserByEmail } = useUserRepo();
|
|
45352
|
+
async function signUp({
|
|
45353
|
+
email,
|
|
45354
|
+
metadata
|
|
45355
|
+
}) {
|
|
45356
|
+
try {
|
|
45357
|
+
const user = await getUserByEmail(email);
|
|
45358
|
+
if (user) {
|
|
45359
|
+
throw new BadRequestError196(
|
|
45360
|
+
`Email ${email} is already registered, please login to continue.`
|
|
45361
|
+
);
|
|
45362
|
+
}
|
|
45363
|
+
metadata.password = await hashPassword4(metadata.password);
|
|
45364
|
+
const value = {
|
|
45365
|
+
type: "user-sign-up" /* USER_SIGN_UP */,
|
|
45366
|
+
email,
|
|
45367
|
+
metadata,
|
|
45368
|
+
expireAt: new Date((/* @__PURE__ */ new Date()).getTime() + 5 * 60 * 1e3).toISOString(),
|
|
45369
|
+
// 5mins from now
|
|
45370
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
45371
|
+
};
|
|
45372
|
+
const res = await add(value);
|
|
45373
|
+
const dir = __dirname;
|
|
45374
|
+
const filePath = getDirectory4(dir, "./public/handlebars/sign-up");
|
|
45375
|
+
const emailContent = compileHandlebar4({
|
|
45376
|
+
context: {
|
|
45377
|
+
email,
|
|
45378
|
+
validity: "5 minutes",
|
|
45379
|
+
link: `${APP_MAIN}/sign-up/${res}`
|
|
45380
|
+
},
|
|
45381
|
+
filePath
|
|
45382
|
+
});
|
|
45383
|
+
mailer.sendMail({
|
|
45384
|
+
to: email,
|
|
45385
|
+
subject: "Sign Up Verification",
|
|
45386
|
+
html: emailContent,
|
|
45387
|
+
sender: "iService365"
|
|
45388
|
+
}).catch((error) => {
|
|
45389
|
+
logger176.log({
|
|
45390
|
+
level: "error",
|
|
45391
|
+
message: `Error sending user invite email: ${error}`
|
|
45392
|
+
});
|
|
45393
|
+
});
|
|
45394
|
+
return res;
|
|
45395
|
+
} catch (error) {
|
|
45396
|
+
throw error;
|
|
45397
|
+
}
|
|
45398
|
+
}
|
|
45399
|
+
return {
|
|
45400
|
+
signUp
|
|
45401
|
+
};
|
|
45402
|
+
}
|
|
45403
|
+
|
|
45404
|
+
// src/controllers/auth-v2.controller.ts
|
|
45405
|
+
import Joi125 from "joi";
|
|
45406
|
+
import { BadRequestError as BadRequestError197, logger as logger177 } from "@7365admin1/node-server-utils";
|
|
45407
|
+
function useAuthControllerV2() {
|
|
45408
|
+
const { signUp: _signUp } = useVerificationServiceV2();
|
|
45409
|
+
async function signUp(req, res, next) {
|
|
45410
|
+
const validation = Joi125.object({
|
|
45411
|
+
email: Joi125.string().email().lowercase().trim().required(),
|
|
45412
|
+
password: Joi125.string().trim().required(),
|
|
45413
|
+
country: Joi125.string().min(3).required(),
|
|
45414
|
+
orgName: Joi125.string().min(1).required()
|
|
45415
|
+
});
|
|
45416
|
+
const { error, value } = validation.validate(req.body, {
|
|
45417
|
+
abortEarly: false
|
|
45418
|
+
});
|
|
45419
|
+
if (error) {
|
|
45420
|
+
const messages = error.details.map((d) => d.message);
|
|
45421
|
+
logger177.log({ level: "error", message: messages.join(", ") });
|
|
45422
|
+
next(new BadRequestError197(messages.join(", ")));
|
|
45423
|
+
return;
|
|
45424
|
+
}
|
|
45425
|
+
const { email, password, country, orgName } = value;
|
|
45426
|
+
try {
|
|
45427
|
+
const message = await _signUp({
|
|
45428
|
+
email,
|
|
45429
|
+
metadata: {
|
|
45430
|
+
password,
|
|
45431
|
+
country,
|
|
45432
|
+
orgName
|
|
45433
|
+
}
|
|
45434
|
+
});
|
|
45435
|
+
res.json({ message });
|
|
45436
|
+
return;
|
|
45437
|
+
} catch (error2) {
|
|
45438
|
+
logger177.log({ level: "error", message: error2.message });
|
|
45439
|
+
next(error2);
|
|
45440
|
+
return;
|
|
45441
|
+
}
|
|
45442
|
+
}
|
|
45443
|
+
return {
|
|
45444
|
+
signUp
|
|
45445
|
+
};
|
|
45446
|
+
}
|
|
45085
45447
|
export {
|
|
45086
45448
|
ANPRMode,
|
|
45087
45449
|
AccessTypeProps,
|
|
@@ -45157,6 +45519,7 @@ export {
|
|
|
45157
45519
|
MVehicle,
|
|
45158
45520
|
MVehicleTransaction,
|
|
45159
45521
|
MVerification,
|
|
45522
|
+
MVerificationV2,
|
|
45160
45523
|
MVisitorTransaction,
|
|
45161
45524
|
MWorkOrder,
|
|
45162
45525
|
OrgNature,
|
|
@@ -45165,6 +45528,7 @@ export {
|
|
|
45165
45528
|
PERSON_TYPES,
|
|
45166
45529
|
PMDashboardCollection,
|
|
45167
45530
|
Period,
|
|
45531
|
+
PersonStatus,
|
|
45168
45532
|
PersonTypes,
|
|
45169
45533
|
SiteCategories,
|
|
45170
45534
|
SiteStatus,
|
|
@@ -45177,6 +45541,7 @@ export {
|
|
|
45177
45541
|
VehicleSort,
|
|
45178
45542
|
VehicleStatus,
|
|
45179
45543
|
VehicleType,
|
|
45544
|
+
VerificationType,
|
|
45180
45545
|
VisitorSort,
|
|
45181
45546
|
VisitorStatus,
|
|
45182
45547
|
addressSchema,
|
|
@@ -45301,6 +45666,7 @@ export {
|
|
|
45301
45666
|
useAttendanceSettingsRepository,
|
|
45302
45667
|
useAttendanceSettingsService,
|
|
45303
45668
|
useAuthController,
|
|
45669
|
+
useAuthControllerV2,
|
|
45304
45670
|
useAuthService,
|
|
45305
45671
|
useBuildingController,
|
|
45306
45672
|
useBuildingRepo,
|
|
@@ -45454,7 +45820,9 @@ export {
|
|
|
45454
45820
|
useVehicleService,
|
|
45455
45821
|
useVerificationController,
|
|
45456
45822
|
useVerificationRepo,
|
|
45823
|
+
useVerificationRepoV2,
|
|
45457
45824
|
useVerificationService,
|
|
45825
|
+
useVerificationServiceV2,
|
|
45458
45826
|
useVisitorTransactionController,
|
|
45459
45827
|
useVisitorTransactionRepo,
|
|
45460
45828
|
useVisitorTransactionService,
|