@7365admin1/core 3.13.0 → 3.15.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 +15 -2
- package/dist/index.js +780 -552
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +678 -452
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -536,13 +536,13 @@ var require_logger = __commonJS({
|
|
|
536
536
|
"use strict";
|
|
537
537
|
exports.__esModule = true;
|
|
538
538
|
var _utils = require_utils();
|
|
539
|
-
var
|
|
539
|
+
var logger201 = {
|
|
540
540
|
methodMap: ["debug", "info", "warn", "error"],
|
|
541
541
|
level: "info",
|
|
542
542
|
// Maps a given level value to the `methodMap` indexes above.
|
|
543
543
|
lookupLevel: function lookupLevel(level) {
|
|
544
544
|
if (typeof level === "string") {
|
|
545
|
-
var levelMap = _utils.indexOf(
|
|
545
|
+
var levelMap = _utils.indexOf(logger201.methodMap, level.toLowerCase());
|
|
546
546
|
if (levelMap >= 0) {
|
|
547
547
|
level = levelMap;
|
|
548
548
|
} else {
|
|
@@ -553,9 +553,9 @@ var require_logger = __commonJS({
|
|
|
553
553
|
},
|
|
554
554
|
// Can be overridden in the host environment
|
|
555
555
|
log: function log(level) {
|
|
556
|
-
level =
|
|
557
|
-
if (typeof console !== "undefined" &&
|
|
558
|
-
var method =
|
|
556
|
+
level = logger201.lookupLevel(level);
|
|
557
|
+
if (typeof console !== "undefined" && logger201.lookupLevel(logger201.level) <= level) {
|
|
558
|
+
var method = logger201.methodMap[level];
|
|
559
559
|
if (!console[method]) {
|
|
560
560
|
method = "log";
|
|
561
561
|
}
|
|
@@ -566,7 +566,7 @@ var require_logger = __commonJS({
|
|
|
566
566
|
}
|
|
567
567
|
}
|
|
568
568
|
};
|
|
569
|
-
exports["default"] =
|
|
569
|
+
exports["default"] = logger201;
|
|
570
570
|
module2.exports = exports["default"];
|
|
571
571
|
}
|
|
572
572
|
});
|
|
@@ -6036,6 +6036,7 @@ __export(src_exports, {
|
|
|
6036
6036
|
building_units_namespace_collection: () => building_units_namespace_collection,
|
|
6037
6037
|
buildings_namespace_collection: () => buildings_namespace_collection,
|
|
6038
6038
|
bulletin_boards_namespace_collection: () => bulletin_boards_namespace_collection,
|
|
6039
|
+
chatPrelovedEvents: () => chatPrelovedEvents,
|
|
6039
6040
|
chatSchema: () => chatSchema,
|
|
6040
6041
|
createManpowerRemarksDaily: () => createManpowerRemarksDaily,
|
|
6041
6042
|
customerSchema: () => customerSchema,
|
|
@@ -6191,6 +6192,7 @@ __export(src_exports, {
|
|
|
6191
6192
|
useAuthServiceV2: () => useAuthServiceV2,
|
|
6192
6193
|
useBidPrelovedController: () => useBidPrelovedController,
|
|
6193
6194
|
useBidPrelovedRepo: () => useBidPrelovedRepo,
|
|
6195
|
+
useBidPrelovedService: () => useBidPrelovedService,
|
|
6194
6196
|
useBuildingController: () => useBuildingController,
|
|
6195
6197
|
useBuildingLevelController: () => useBuildingLevelController,
|
|
6196
6198
|
useBuildingLevelRepo: () => useBuildingLevelRepo,
|
|
@@ -8742,12 +8744,6 @@ function useUserRepo() {
|
|
|
8742
8744
|
throw new import_node_server_utils10.BadRequestError("Invalid user ID format.");
|
|
8743
8745
|
}
|
|
8744
8746
|
try {
|
|
8745
|
-
const cacheKey = (0, import_node_server_utils10.makeCacheKey)(namespace_collection, { _id });
|
|
8746
|
-
const cachedData = await getCache(cacheKey);
|
|
8747
|
-
if (cachedData) {
|
|
8748
|
-
import_node_server_utils10.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
8749
|
-
return cachedData;
|
|
8750
|
-
}
|
|
8751
8747
|
const results = await collection.aggregate([
|
|
8752
8748
|
{ $match: { _id } },
|
|
8753
8749
|
{
|
|
@@ -8771,17 +8767,42 @@ function useUserRepo() {
|
|
|
8771
8767
|
],
|
|
8772
8768
|
as: "serviceProviders"
|
|
8773
8769
|
}
|
|
8774
|
-
}
|
|
8770
|
+
},
|
|
8771
|
+
{
|
|
8772
|
+
$lookup: {
|
|
8773
|
+
from: "buildings",
|
|
8774
|
+
localField: "block",
|
|
8775
|
+
foreignField: "_id",
|
|
8776
|
+
pipeline: [{ $project: { _id: 0, name: 1, block: 1 } }],
|
|
8777
|
+
as: "blockInfo"
|
|
8778
|
+
}
|
|
8779
|
+
},
|
|
8780
|
+
{ $unwind: { path: "$blockInfo", preserveNullAndEmptyArrays: true } },
|
|
8781
|
+
{
|
|
8782
|
+
$lookup: {
|
|
8783
|
+
from: "building-levels",
|
|
8784
|
+
localField: "level",
|
|
8785
|
+
foreignField: "_id",
|
|
8786
|
+
pipeline: [{ $project: { _id: 0, name: 1 } }],
|
|
8787
|
+
as: "levelInfo"
|
|
8788
|
+
}
|
|
8789
|
+
},
|
|
8790
|
+
{ $unwind: { path: "$levelInfo", preserveNullAndEmptyArrays: true } },
|
|
8791
|
+
{
|
|
8792
|
+
$lookup: {
|
|
8793
|
+
from: "building-units",
|
|
8794
|
+
localField: "unitId",
|
|
8795
|
+
foreignField: "_id",
|
|
8796
|
+
pipeline: [{ $project: { _id: 0, name: 1 } }],
|
|
8797
|
+
as: "unitInfo"
|
|
8798
|
+
}
|
|
8799
|
+
},
|
|
8800
|
+
{ $unwind: { path: "$unitInfo", preserveNullAndEmptyArrays: true } }
|
|
8775
8801
|
]).toArray();
|
|
8776
8802
|
const data = results.length > 0 ? results[0] : null;
|
|
8777
8803
|
if (!data) {
|
|
8778
8804
|
throw new import_node_server_utils10.NotFoundError("User not found.");
|
|
8779
8805
|
}
|
|
8780
|
-
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
8781
|
-
import_node_server_utils10.logger.info(`Cache set for key: ${cacheKey}`);
|
|
8782
|
-
}).catch((err) => {
|
|
8783
|
-
import_node_server_utils10.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
8784
|
-
});
|
|
8785
8806
|
return data;
|
|
8786
8807
|
} catch (error) {
|
|
8787
8808
|
if (error instanceof import_node_server_utils10.AppError) {
|
|
@@ -9171,6 +9192,7 @@ var APP_POOL_MAINTENANCE = process.env.APP_POOL_MAINTENANCE ?? "http://localhost
|
|
|
9171
9192
|
var ENCRYPTION_KEY = process.env.ENCRYPTION_KEY ?? "";
|
|
9172
9193
|
var DOMAIN = process.env.DOMAIN ?? "localhost";
|
|
9173
9194
|
var OPEN_AI_API_KEY = process.env.OPEN_AI_API_KEY;
|
|
9195
|
+
var ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY;
|
|
9174
9196
|
var STORAGE_API = process.env.STORAGE_API;
|
|
9175
9197
|
|
|
9176
9198
|
// src/services/auth.service.ts
|
|
@@ -9661,59 +9683,41 @@ function useMemberRepo() {
|
|
|
9661
9683
|
try {
|
|
9662
9684
|
const items = await collection.aggregate([
|
|
9663
9685
|
{ $match: query },
|
|
9664
|
-
{ $sort: { _id: -1 } },
|
|
9665
|
-
{ $skip: page * limit },
|
|
9666
|
-
{ $limit: limit },
|
|
9667
9686
|
{
|
|
9668
9687
|
$lookup: {
|
|
9669
9688
|
from: "organizations",
|
|
9670
9689
|
localField: "org",
|
|
9671
9690
|
foreignField: "_id",
|
|
9672
|
-
as: "
|
|
9673
|
-
}
|
|
9674
|
-
},
|
|
9675
|
-
{
|
|
9676
|
-
$unwind: {
|
|
9677
|
-
path: "$orgData",
|
|
9678
|
-
preserveNullAndEmptyArrays: true
|
|
9679
|
-
}
|
|
9680
|
-
},
|
|
9681
|
-
{
|
|
9682
|
-
$lookup: {
|
|
9683
|
-
from: "organizations",
|
|
9684
|
-
localField: "org",
|
|
9685
|
-
foreignField: "_id",
|
|
9686
|
-
as: "defaultSite"
|
|
9691
|
+
as: "org"
|
|
9687
9692
|
}
|
|
9688
9693
|
},
|
|
9689
9694
|
{
|
|
9690
9695
|
$unwind: {
|
|
9691
|
-
path: "$
|
|
9696
|
+
path: "$org",
|
|
9692
9697
|
preserveNullAndEmptyArrays: true
|
|
9693
9698
|
}
|
|
9694
9699
|
},
|
|
9695
9700
|
{
|
|
9696
9701
|
$group: {
|
|
9697
|
-
_id: "$org",
|
|
9698
|
-
text: { $first: "$
|
|
9699
|
-
value: { $first: "$org" },
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9703
|
-
},
|
|
9704
|
-
|
|
9705
|
-
$first: "$orgData.onboardingCompleted"
|
|
9706
|
-
},
|
|
9707
|
-
onboardingCompletedAt: {
|
|
9708
|
-
$first: "$orgData.onboardingCompletedAt"
|
|
9709
|
-
}
|
|
9702
|
+
_id: "$org._id",
|
|
9703
|
+
text: { $first: "$org.name" },
|
|
9704
|
+
value: { $first: "$org._id" },
|
|
9705
|
+
type: { $first: "$org.type" },
|
|
9706
|
+
defaultSite: { $first: "$org.defaultSite" },
|
|
9707
|
+
onboardingRequired: { $first: "$org.onboardingRequired" },
|
|
9708
|
+
onboardingCompleted: { $first: "$org.onboardingCompleted" },
|
|
9709
|
+
onboardingCompletedAt: { $first: "$org.onboardingCompletedAt" }
|
|
9710
9710
|
}
|
|
9711
9711
|
},
|
|
9712
|
+
{ $sort: { _id: -1 } },
|
|
9713
|
+
{ $skip: page * limit },
|
|
9714
|
+
{ $limit: limit },
|
|
9712
9715
|
{
|
|
9713
9716
|
$project: {
|
|
9714
9717
|
_id: 0,
|
|
9715
9718
|
text: 1,
|
|
9716
9719
|
value: 1,
|
|
9720
|
+
type: 1,
|
|
9717
9721
|
defaultSite: 1,
|
|
9718
9722
|
onboardingRequired: 1,
|
|
9719
9723
|
onboardingCompleted: 1,
|
|
@@ -11563,21 +11567,10 @@ function useSiteRepo() {
|
|
|
11563
11567
|
throw new import_node_server_utils19.BadRequestError("Invalid site ID format.");
|
|
11564
11568
|
}
|
|
11565
11569
|
try {
|
|
11566
|
-
const cacheKey = (0, import_node_server_utils19.makeCacheKey)(namespace_collection, { _id });
|
|
11567
|
-
const cachedData = await getCache(cacheKey);
|
|
11568
|
-
if (cachedData) {
|
|
11569
|
-
import_node_server_utils19.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
11570
|
-
return cachedData;
|
|
11571
|
-
}
|
|
11572
11570
|
const data = await collection.aggregate([{ $match: { _id, status: { $ne: "deleted" } } }]).toArray();
|
|
11573
11571
|
if (!data || !data.length) {
|
|
11574
11572
|
throw new import_node_server_utils19.NotFoundError("Site not found.");
|
|
11575
11573
|
}
|
|
11576
|
-
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
11577
|
-
import_node_server_utils19.logger.info(`Cache set for key: ${cacheKey}`);
|
|
11578
|
-
}).catch((err) => {
|
|
11579
|
-
import_node_server_utils19.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
11580
|
-
});
|
|
11581
11574
|
return data[0];
|
|
11582
11575
|
} catch (error) {
|
|
11583
11576
|
throw error;
|
|
@@ -25841,6 +25834,22 @@ function useBuildingUnitRepo() {
|
|
|
25841
25834
|
}
|
|
25842
25835
|
return [level];
|
|
25843
25836
|
}
|
|
25837
|
+
function escapeRegExp(value) {
|
|
25838
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
25839
|
+
}
|
|
25840
|
+
function makeFlexibleRegex(value) {
|
|
25841
|
+
const pattern = value.trim().split(/\s+/).map(escapeRegExp).join("\\s*");
|
|
25842
|
+
return pattern ? new RegExp(pattern, "i") : null;
|
|
25843
|
+
}
|
|
25844
|
+
function getSearchParts(searchText) {
|
|
25845
|
+
const levelMatch = searchText.match(/\b(?:lvl|level)\s*([a-z0-9]+)\b/i);
|
|
25846
|
+
const levelSearch = levelMatch?.[0] ?? "";
|
|
25847
|
+
const unitSearch = levelSearch ? searchText.replace(levelSearch, "").trim() : "";
|
|
25848
|
+
return {
|
|
25849
|
+
levelRegex: makeFlexibleRegex(levelSearch),
|
|
25850
|
+
unitRegex: makeFlexibleRegex(unitSearch)
|
|
25851
|
+
};
|
|
25852
|
+
}
|
|
25844
25853
|
async function add(value, session) {
|
|
25845
25854
|
try {
|
|
25846
25855
|
value = MBuildingUnit(value);
|
|
@@ -25966,9 +25975,11 @@ function useBuildingUnitRepo() {
|
|
|
25966
25975
|
status = "active"
|
|
25967
25976
|
} = {}) {
|
|
25968
25977
|
page = page > 0 ? page - 1 : 0;
|
|
25978
|
+
const searchText = search.trim();
|
|
25979
|
+
const searchRegex = makeFlexibleRegex(searchText);
|
|
25980
|
+
const { levelRegex, unitRegex } = getSearchParts(searchText);
|
|
25969
25981
|
const query = {
|
|
25970
25982
|
status,
|
|
25971
|
-
...search && { $text: { $search: search } },
|
|
25972
25983
|
...site && { site: (0, import_node_server_utils76.toObjectId)(site) },
|
|
25973
25984
|
...building && { building: (0, import_node_server_utils76.toObjectId)(building) }
|
|
25974
25985
|
};
|
|
@@ -25977,7 +25988,7 @@ function useBuildingUnitRepo() {
|
|
|
25977
25988
|
page,
|
|
25978
25989
|
limit,
|
|
25979
25990
|
sort: JSON.stringify(sort),
|
|
25980
|
-
...
|
|
25991
|
+
...searchText && { search: searchText },
|
|
25981
25992
|
...site && { site },
|
|
25982
25993
|
...building && { building },
|
|
25983
25994
|
...status && { status }
|
|
@@ -25999,8 +26010,45 @@ function useBuildingUnitRepo() {
|
|
|
25999
26010
|
});
|
|
26000
26011
|
return cached;
|
|
26001
26012
|
}
|
|
26002
|
-
const
|
|
26013
|
+
const pipeline = [
|
|
26003
26014
|
{ $match: query },
|
|
26015
|
+
{
|
|
26016
|
+
$lookup: {
|
|
26017
|
+
from: "building-levels",
|
|
26018
|
+
localField: "level",
|
|
26019
|
+
foreignField: "_id",
|
|
26020
|
+
pipeline: [{ $project: { name: 1 } }],
|
|
26021
|
+
as: "level"
|
|
26022
|
+
}
|
|
26023
|
+
},
|
|
26024
|
+
{ $set: { level: { $first: "$level" } } },
|
|
26025
|
+
...searchRegex ? [
|
|
26026
|
+
{
|
|
26027
|
+
$match: {
|
|
26028
|
+
$or: [
|
|
26029
|
+
{ name: searchRegex },
|
|
26030
|
+
{ buildingName: searchRegex },
|
|
26031
|
+
{ "level.name": searchRegex },
|
|
26032
|
+
...levelRegex && unitRegex ? [
|
|
26033
|
+
{
|
|
26034
|
+
$and: [
|
|
26035
|
+
{
|
|
26036
|
+
$or: [
|
|
26037
|
+
{ name: unitRegex },
|
|
26038
|
+
{ buildingName: unitRegex }
|
|
26039
|
+
]
|
|
26040
|
+
},
|
|
26041
|
+
{ "level.name": levelRegex }
|
|
26042
|
+
]
|
|
26043
|
+
}
|
|
26044
|
+
] : []
|
|
26045
|
+
]
|
|
26046
|
+
}
|
|
26047
|
+
}
|
|
26048
|
+
] : []
|
|
26049
|
+
];
|
|
26050
|
+
const items = await collection.aggregate([
|
|
26051
|
+
...pipeline,
|
|
26004
26052
|
{
|
|
26005
26053
|
$lookup: {
|
|
26006
26054
|
from: "sites",
|
|
@@ -26026,22 +26074,13 @@ function useBuildingUnitRepo() {
|
|
|
26026
26074
|
as: "site"
|
|
26027
26075
|
}
|
|
26028
26076
|
},
|
|
26029
|
-
{
|
|
26030
|
-
$lookup: {
|
|
26031
|
-
from: "building-levels",
|
|
26032
|
-
localField: "level",
|
|
26033
|
-
foreignField: "_id",
|
|
26034
|
-
pipeline: [{ $project: { name: 1 } }],
|
|
26035
|
-
as: "level"
|
|
26036
|
-
}
|
|
26037
|
-
},
|
|
26038
|
-
{ $set: { level: { $first: "$level" } } },
|
|
26039
26077
|
{ $set: { site: { $first: "$site" } } },
|
|
26040
26078
|
{ $sort: sort },
|
|
26041
26079
|
{ $skip: page * limit },
|
|
26042
26080
|
{ $limit: limit }
|
|
26043
26081
|
]).toArray();
|
|
26044
|
-
const
|
|
26082
|
+
const total = await collection.aggregate([...pipeline, { $count: "length" }]).toArray();
|
|
26083
|
+
const length = total[0]?.length ?? 0;
|
|
26045
26084
|
const data = (0, import_node_server_utils76.paginate)(items, page, limit, length);
|
|
26046
26085
|
setCache(cacheKey, data, 600).then(() => {
|
|
26047
26086
|
import_node_server_utils76.logger.log({
|
|
@@ -28130,6 +28169,7 @@ function useBuildingRepo() {
|
|
|
28130
28169
|
{ key: { name: "text" }, name: "text-index" },
|
|
28131
28170
|
// { key: { name: 1 }, unique: true, name: "unique-name-index" },
|
|
28132
28171
|
{ key: { site: 1 } },
|
|
28172
|
+
{ key: { block: 1 }, name: "block-index" },
|
|
28133
28173
|
{ key: { createdAt: 1 } },
|
|
28134
28174
|
{
|
|
28135
28175
|
key: { site: 1, block: 1 },
|
|
@@ -28232,17 +28272,25 @@ function useBuildingRepo() {
|
|
|
28232
28272
|
throw new import_node_server_utils83.BadRequestError("Invalid site ID.");
|
|
28233
28273
|
}
|
|
28234
28274
|
}
|
|
28275
|
+
const searchText = search.trim();
|
|
28276
|
+
const blockSearch = Number(searchText);
|
|
28277
|
+
const canSearchBlock = searchText !== "" && Number.isFinite(blockSearch);
|
|
28235
28278
|
const query = {
|
|
28236
28279
|
status,
|
|
28237
|
-
...
|
|
28238
|
-
...
|
|
28280
|
+
...siteId && { site: siteId },
|
|
28281
|
+
...searchText && {
|
|
28282
|
+
$or: [
|
|
28283
|
+
{ $text: { $search: searchText } },
|
|
28284
|
+
...canSearchBlock ? [{ block: blockSearch }] : []
|
|
28285
|
+
]
|
|
28286
|
+
}
|
|
28239
28287
|
};
|
|
28240
28288
|
sort = Object.keys(sort).length ? sort : { _id: -1 };
|
|
28241
28289
|
const cacheParams = {
|
|
28242
28290
|
page,
|
|
28243
28291
|
limit,
|
|
28244
28292
|
sort: JSON.stringify(sort),
|
|
28245
|
-
...
|
|
28293
|
+
...searchText && { search: searchText },
|
|
28246
28294
|
...site && { site },
|
|
28247
28295
|
...status && { status }
|
|
28248
28296
|
};
|
|
@@ -30003,6 +30051,24 @@ function useBuildingUnitController() {
|
|
|
30003
30051
|
getAllLevelsWithUnits: _getAllLevelsWithUnits
|
|
30004
30052
|
} = useBuildingUnitRepo();
|
|
30005
30053
|
const { add: _add, updateById: _updateById } = useBuildingUnitService();
|
|
30054
|
+
function normalizeQueryString(value) {
|
|
30055
|
+
if (Array.isArray(value)) {
|
|
30056
|
+
for (const item of value) {
|
|
30057
|
+
const normalized = normalizeQueryString(item);
|
|
30058
|
+
if (normalized)
|
|
30059
|
+
return normalized;
|
|
30060
|
+
}
|
|
30061
|
+
return "";
|
|
30062
|
+
}
|
|
30063
|
+
if (value && typeof value === "object") {
|
|
30064
|
+
for (const item of Object.values(value)) {
|
|
30065
|
+
const normalized = normalizeQueryString(item);
|
|
30066
|
+
if (normalized)
|
|
30067
|
+
return normalized;
|
|
30068
|
+
}
|
|
30069
|
+
}
|
|
30070
|
+
return typeof value === "string" ? value : "";
|
|
30071
|
+
}
|
|
30006
30072
|
async function add(req, res, next) {
|
|
30007
30073
|
const data = req.body;
|
|
30008
30074
|
const validation = import_joi47.default.object({
|
|
@@ -30076,7 +30142,11 @@ function useBuildingUnitController() {
|
|
|
30076
30142
|
sort: import_joi47.default.string().valid(...Object.values(SortFields)).default("_id" /* ID */),
|
|
30077
30143
|
order: import_joi47.default.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */)
|
|
30078
30144
|
});
|
|
30079
|
-
const
|
|
30145
|
+
const query = {
|
|
30146
|
+
...req.query,
|
|
30147
|
+
search: normalizeQueryString(req.query.search)
|
|
30148
|
+
};
|
|
30149
|
+
const { error, value } = validation.validate(query, {
|
|
30080
30150
|
abortEarly: false
|
|
30081
30151
|
});
|
|
30082
30152
|
if (error) {
|
|
@@ -30237,7 +30307,11 @@ function useBuildingUnitController() {
|
|
|
30237
30307
|
order: import_joi47.default.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */),
|
|
30238
30308
|
level: import_joi47.default.string().hex().length(24).optional().allow(null, "")
|
|
30239
30309
|
});
|
|
30240
|
-
const
|
|
30310
|
+
const query = {
|
|
30311
|
+
...req.query,
|
|
30312
|
+
search: normalizeQueryString(req.query.search)
|
|
30313
|
+
};
|
|
30314
|
+
const { error, value } = validation.validate(query, {
|
|
30241
30315
|
abortEarly: false
|
|
30242
30316
|
});
|
|
30243
30317
|
if (error) {
|
|
@@ -45294,6 +45368,31 @@ async function getTransactions(index, url) {
|
|
|
45294
45368
|
return Promise.reject(error);
|
|
45295
45369
|
}
|
|
45296
45370
|
}
|
|
45371
|
+
function encryptPayload(payloadHex) {
|
|
45372
|
+
const buffer = Buffer.from(payloadHex, "ascii");
|
|
45373
|
+
const encrypted = import_crypto.default.publicEncrypt(
|
|
45374
|
+
{
|
|
45375
|
+
key: "testing",
|
|
45376
|
+
padding: import_crypto.default.constants.RSA_PKCS1_PADDING
|
|
45377
|
+
},
|
|
45378
|
+
buffer
|
|
45379
|
+
);
|
|
45380
|
+
return encrypted.toString("base64");
|
|
45381
|
+
}
|
|
45382
|
+
function toHex(num, length) {
|
|
45383
|
+
return num.toString(16).padStart(length * 2, "0");
|
|
45384
|
+
}
|
|
45385
|
+
function buildPayload(cardNumber, validityMinutes) {
|
|
45386
|
+
const randomHex = import_crypto.default.randomBytes(2).toString("hex");
|
|
45387
|
+
const cardHex = toHex(cardNumber, 4);
|
|
45388
|
+
const epochHex = toHex(Math.floor(Date.now() / 1e3), 4);
|
|
45389
|
+
const validityHex = toHex(validityMinutes, 2);
|
|
45390
|
+
return randomHex + cardHex + epochHex + validityHex;
|
|
45391
|
+
}
|
|
45392
|
+
function generateQrCodeData(cardNumber, validityMinutes) {
|
|
45393
|
+
const payloadHex = buildPayload(cardNumber, validityMinutes);
|
|
45394
|
+
return encryptPayload(payloadHex);
|
|
45395
|
+
}
|
|
45297
45396
|
|
|
45298
45397
|
// src/repositories/access-management.repo.ts
|
|
45299
45398
|
var import_xml2js2 = require("xml2js");
|
|
@@ -48543,6 +48642,14 @@ function useAccessManagementSvc() {
|
|
|
48543
48642
|
throw new Error(err.message);
|
|
48544
48643
|
}
|
|
48545
48644
|
};
|
|
48645
|
+
const generateQrCodeWithExpirySvc = async ({ cardNumber, validityMinutes }) => {
|
|
48646
|
+
try {
|
|
48647
|
+
const response = generateQrCodeData(cardNumber, validityMinutes);
|
|
48648
|
+
return response;
|
|
48649
|
+
} catch (error) {
|
|
48650
|
+
throw new Error(error.message);
|
|
48651
|
+
}
|
|
48652
|
+
};
|
|
48546
48653
|
return {
|
|
48547
48654
|
addPhysicalCardSvc,
|
|
48548
48655
|
addNonPhysicalCardSvc,
|
|
@@ -48585,7 +48692,8 @@ function useAccessManagementSvc() {
|
|
|
48585
48692
|
getResidentsSvc,
|
|
48586
48693
|
userAccessCardsSvc,
|
|
48587
48694
|
removeTemplateSvc,
|
|
48588
|
-
qrCodeListSvc
|
|
48695
|
+
qrCodeListSvc,
|
|
48696
|
+
generateQrCodeWithExpirySvc
|
|
48589
48697
|
};
|
|
48590
48698
|
}
|
|
48591
48699
|
|
|
@@ -48633,7 +48741,8 @@ function useAccessManagementController() {
|
|
|
48633
48741
|
getResidentsSvc,
|
|
48634
48742
|
userAccessCardsSvc,
|
|
48635
48743
|
removeTemplateSvc,
|
|
48636
|
-
qrCodeListSvc
|
|
48744
|
+
qrCodeListSvc,
|
|
48745
|
+
generateQrCodeWithExpirySvc
|
|
48637
48746
|
} = useAccessManagementSvc();
|
|
48638
48747
|
const addPhysicalCard = async (req, res) => {
|
|
48639
48748
|
try {
|
|
@@ -49745,6 +49854,23 @@ function useAccessManagementController() {
|
|
|
49745
49854
|
});
|
|
49746
49855
|
}
|
|
49747
49856
|
};
|
|
49857
|
+
const generateQrCodeWithExpiry = async (req, res) => {
|
|
49858
|
+
try {
|
|
49859
|
+
const { cardNumber, validityMinutes } = req.body;
|
|
49860
|
+
const result = await generateQrCodeWithExpirySvc({ cardNumber, validityMinutes });
|
|
49861
|
+
return res.status(200).json({
|
|
49862
|
+
message: "successful!",
|
|
49863
|
+
data: {
|
|
49864
|
+
result
|
|
49865
|
+
}
|
|
49866
|
+
});
|
|
49867
|
+
} catch (error) {
|
|
49868
|
+
return res.status(400).json({
|
|
49869
|
+
data: null,
|
|
49870
|
+
message: error.message
|
|
49871
|
+
});
|
|
49872
|
+
}
|
|
49873
|
+
};
|
|
49748
49874
|
return {
|
|
49749
49875
|
addPhysicalCard,
|
|
49750
49876
|
addNonPhysicalCard,
|
|
@@ -49785,7 +49911,8 @@ function useAccessManagementController() {
|
|
|
49785
49911
|
getResidents,
|
|
49786
49912
|
userAccessCards,
|
|
49787
49913
|
removeTemplate,
|
|
49788
|
-
qrCodeList
|
|
49914
|
+
qrCodeList,
|
|
49915
|
+
generateQrCodeWithExpiry
|
|
49789
49916
|
};
|
|
49790
49917
|
}
|
|
49791
49918
|
|
|
@@ -54580,7 +54707,7 @@ function useIncidentReportRepo() {
|
|
|
54580
54707
|
}
|
|
54581
54708
|
|
|
54582
54709
|
// src/services/incident-report.service.ts
|
|
54583
|
-
var
|
|
54710
|
+
var import_sdk = __toESM(require("@anthropic-ai/sdk"));
|
|
54584
54711
|
function useIncidentReportService() {
|
|
54585
54712
|
const {
|
|
54586
54713
|
add: _add,
|
|
@@ -54673,20 +54800,12 @@ function useIncidentReportService() {
|
|
|
54673
54800
|
}
|
|
54674
54801
|
}
|
|
54675
54802
|
async function createIncidentSummary(value) {
|
|
54676
|
-
const session = import_node_server_utils182.useAtlas.getClient()?.startSession();
|
|
54677
|
-
session?.startTransaction();
|
|
54678
54803
|
const sample = `On August 4, 2024, an incident report labeled IR10 was submitted following an earthquake that occurred between 10:00 AM and 10:30 AM at a designated test site. The report indicated that the incident was reported by a complainant named Maryam, who provided her contact information as +65-123456789. The recipient of the complaint was Rash, whose contact number is +65-987654321. The description of the complaint detailed a historical context regarding the origins of Lorem Ipsum text, an academic piece that has been referenced throughout centuries.
|
|
54679
|
-
|
|
54680
|
-
|
|
54681
|
-
|
|
54682
|
-
'
|
|
54683
|
-
|
|
54684
|
-
'
|
|
54685
|
-
' +
|
|
54686
|
-
"No authorities were called, and the incident's resolution was marked at 11:00 AM, with actions taken by Ola, the shift in charge during the incident. The management was informed of the incident at 10:08 AM, and security implications were considered but not detailed. The report remains pending and does not mention a reason for rejection or approval status. The incident is documented with attached photographs. The overall status of the report remains pending as of the latest update.`;
|
|
54687
|
-
const openai = new import_openai.default({
|
|
54688
|
-
apiKey: OPEN_AI_API_KEY
|
|
54689
|
-
});
|
|
54804
|
+
|
|
54805
|
+
The report highlighted that no individuals were directly affected or injured in the incident. However, there was damage to property associated with the incident, particularly mentioning an individual named Ruzzy, with contact +65-34567777889, who experienced property damage. The report states that this damage was also elaborated upon with historical context, reiterating similar pieces of information on the classical literature that influenced the Lorem Ipsum narrative.
|
|
54806
|
+
|
|
54807
|
+
No authorities were called, and the incident's resolution was marked at 11:00 AM, with actions taken by Ola, the shift in charge during the incident. The management was informed of the incident at 10:08 AM, and security implications were considered but not detailed. The report remains pending and does not mention a reason for rejection or approval status. The incident is documented with attached photographs. The overall status of the report remains pending as of the latest update.`;
|
|
54808
|
+
const anthropic = new import_sdk.default({ apiKey: ANTHROPIC_API_KEY });
|
|
54690
54809
|
try {
|
|
54691
54810
|
if (value?.incidentInformation?.siteInfo?.site) {
|
|
54692
54811
|
const site = await _getSiteById(
|
|
@@ -54703,19 +54822,15 @@ function useIncidentReportService() {
|
|
|
54703
54822
|
value.organization = org.name;
|
|
54704
54823
|
}
|
|
54705
54824
|
}
|
|
54706
|
-
const
|
|
54707
|
-
model: "
|
|
54708
|
-
|
|
54709
|
-
|
|
54710
|
-
|
|
54711
|
-
content: `You write a comprehensive summary for incident reports, exclude the attachment, and make it in essay format, and don't add any explaination to how the summary is about, and don't use the mongodb id number for the summary and Must include the following answers to What happened ?, Where did it happened ?, Who was involved ?, How did it happened?, Why did it happened?, Is there any security implications due to incident ?, just keep it plain since we will save it directly into the database. here's a sample: ${sample}`
|
|
54712
|
-
},
|
|
54713
|
-
{ role: "user", content: JSON.stringify(value) }
|
|
54714
|
-
]
|
|
54825
|
+
const response = await anthropic.messages.create({
|
|
54826
|
+
model: "claude-sonnet-4-6",
|
|
54827
|
+
max_tokens: 1024,
|
|
54828
|
+
system: `You write a comprehensive summary for incident reports, exclude the attachment, and make it in essay format, and don't add any explaination to how the summary is about, and don't use the mongodb id number for the summary and Must include the following answers to What happened ?, Where did it happened ?, Who was involved ?, How did it happened?, Why did it happened?, Is there any security implications due to incident ?, just keep it plain since we will save it directly into the database. here's a sample: ${sample}`,
|
|
54829
|
+
messages: [{ role: "user", content: JSON.stringify(value) }]
|
|
54715
54830
|
});
|
|
54716
|
-
const
|
|
54717
|
-
if (
|
|
54718
|
-
return
|
|
54831
|
+
const briefSummary = response.content[0].type === "text" ? response.content[0].text : null;
|
|
54832
|
+
if (briefSummary) {
|
|
54833
|
+
return briefSummary;
|
|
54719
54834
|
} else {
|
|
54720
54835
|
return "Failed to generate a summary.";
|
|
54721
54836
|
}
|
|
@@ -57084,14 +57199,14 @@ function useNewDashboardRepo() {
|
|
|
57084
57199
|
site: { $in: [siteIdObj, siteId] },
|
|
57085
57200
|
service: "Security",
|
|
57086
57201
|
createdAt: periodRange,
|
|
57087
|
-
status: { $nin: ["
|
|
57202
|
+
status: { $nin: ["Completed", "Deleted"] }
|
|
57088
57203
|
}
|
|
57089
57204
|
},
|
|
57090
57205
|
{
|
|
57091
57206
|
$facet: {
|
|
57092
57207
|
total: [{ $count: "count" }],
|
|
57093
57208
|
inProgress: [
|
|
57094
|
-
{ $match: { status: "
|
|
57209
|
+
{ $match: { status: "In-Progress" } },
|
|
57095
57210
|
{ $count: "count" }
|
|
57096
57211
|
]
|
|
57097
57212
|
}
|
|
@@ -57103,7 +57218,7 @@ function useNewDashboardRepo() {
|
|
|
57103
57218
|
site: { $in: [siteIdObj, siteId] },
|
|
57104
57219
|
service: "Security",
|
|
57105
57220
|
createdAt: { $gte: yesterday, $lte: yesterdayEnd },
|
|
57106
|
-
status: { $nin: ["
|
|
57221
|
+
status: { $nin: ["Completed", "Deleted"] }
|
|
57107
57222
|
}
|
|
57108
57223
|
},
|
|
57109
57224
|
{ $count: "count" }
|
|
@@ -57114,7 +57229,7 @@ function useNewDashboardRepo() {
|
|
|
57114
57229
|
site: { $in: [siteIdObj, siteId] },
|
|
57115
57230
|
service: "Security",
|
|
57116
57231
|
createdAt: { $gte: today, $lte: todayEnd },
|
|
57117
|
-
status: { $nin: ["
|
|
57232
|
+
status: { $nin: ["Completed", "Deleted"] }
|
|
57118
57233
|
}
|
|
57119
57234
|
},
|
|
57120
57235
|
{ $count: "count" }
|
|
@@ -57123,7 +57238,7 @@ function useNewDashboardRepo() {
|
|
|
57123
57238
|
{
|
|
57124
57239
|
$match: {
|
|
57125
57240
|
site: { $in: [siteIdObj, siteId] },
|
|
57126
|
-
status: { $in: ["pending"
|
|
57241
|
+
status: { $in: ["pending"] },
|
|
57127
57242
|
createdAt: periodRange
|
|
57128
57243
|
}
|
|
57129
57244
|
},
|
|
@@ -57133,7 +57248,7 @@ function useNewDashboardRepo() {
|
|
|
57133
57248
|
{
|
|
57134
57249
|
$match: {
|
|
57135
57250
|
site: { $in: [siteIdObj, siteId] },
|
|
57136
|
-
status: { $in: ["pending"
|
|
57251
|
+
status: { $in: ["pending"] },
|
|
57137
57252
|
createdAt: { $gte: yesterday, $lte: yesterdayEnd }
|
|
57138
57253
|
}
|
|
57139
57254
|
},
|
|
@@ -57143,7 +57258,7 @@ function useNewDashboardRepo() {
|
|
|
57143
57258
|
{
|
|
57144
57259
|
$match: {
|
|
57145
57260
|
site: { $in: [siteIdObj, siteId] },
|
|
57146
|
-
status: { $in: ["pending"
|
|
57261
|
+
status: { $in: ["pending"] },
|
|
57147
57262
|
createdAt: { $gte: today, $lte: todayEnd }
|
|
57148
57263
|
}
|
|
57149
57264
|
},
|
|
@@ -57425,11 +57540,11 @@ function useNewDashboardRepo() {
|
|
|
57425
57540
|
[
|
|
57426
57541
|
db.collection(incidents_namespace_collection).find({
|
|
57427
57542
|
site: { $in: [siteIdObj, siteId] },
|
|
57428
|
-
status: { $in: ["pending"
|
|
57543
|
+
status: { $in: ["pending"] }
|
|
57429
57544
|
}).sort({ createdAt: -1 }).toArray(),
|
|
57430
57545
|
db.collection(facility_bookings_namespace_collection2).find({
|
|
57431
57546
|
site: { $in: [siteIdObj, siteId] },
|
|
57432
|
-
status: { $in: ["Pending", "
|
|
57547
|
+
status: { $in: ["Pending", "For Review"] }
|
|
57433
57548
|
}).sort({ createdAt: -1 }).toArray()
|
|
57434
57549
|
]
|
|
57435
57550
|
);
|
|
@@ -57438,14 +57553,16 @@ function useNewDashboardRepo() {
|
|
|
57438
57553
|
const todayAttentions = [];
|
|
57439
57554
|
if (pendingIncidentCount > 0) {
|
|
57440
57555
|
todayAttentions.push({
|
|
57441
|
-
id:
|
|
57556
|
+
id: pendingIncidentDocs[0]._id.toString(),
|
|
57557
|
+
type: "incident",
|
|
57442
57558
|
title: `${pendingIncidentCount} incident${pendingIncidentCount === 1 ? "" : "s"} pending acknowledge`,
|
|
57443
57559
|
createdAt: pendingIncidentDocs[0].updatedAt || pendingIncidentDocs[0].createdAt || /* @__PURE__ */ new Date()
|
|
57444
57560
|
});
|
|
57445
57561
|
}
|
|
57446
57562
|
if (pendingFacilityBookingCount > 0) {
|
|
57447
57563
|
todayAttentions.push({
|
|
57448
|
-
id:
|
|
57564
|
+
id: pendingFacilityBookingDocs[0]._id.toString(),
|
|
57565
|
+
type: "facility-booking",
|
|
57449
57566
|
title: `${pendingFacilityBookingCount} facility booking${pendingFacilityBookingCount === 1 ? "" : "s"} need approval`,
|
|
57450
57567
|
createdAt: pendingFacilityBookingDocs[0].createdAt || /* @__PURE__ */ new Date()
|
|
57451
57568
|
});
|
|
@@ -57500,14 +57617,14 @@ function useNewDashboardRepo() {
|
|
|
57500
57617
|
$match: {
|
|
57501
57618
|
site: { $in: [siteIdObj, siteId] },
|
|
57502
57619
|
createdAt: periodRange,
|
|
57503
|
-
status: { $nin: ["
|
|
57620
|
+
status: { $nin: ["Completed", "Deleted"] }
|
|
57504
57621
|
}
|
|
57505
57622
|
},
|
|
57506
57623
|
{
|
|
57507
57624
|
$facet: {
|
|
57508
57625
|
total: [{ $count: "count" }],
|
|
57509
57626
|
inProgress: [
|
|
57510
|
-
{ $match: { status: "
|
|
57627
|
+
{ $match: { status: "In-Progress" } },
|
|
57511
57628
|
{ $count: "count" }
|
|
57512
57629
|
]
|
|
57513
57630
|
}
|
|
@@ -57518,7 +57635,7 @@ function useNewDashboardRepo() {
|
|
|
57518
57635
|
$match: {
|
|
57519
57636
|
site: { $in: [siteIdObj, siteId] },
|
|
57520
57637
|
createdAt: { $gte: yesterday, $lte: yesterdayEnd },
|
|
57521
|
-
status: { $nin: ["
|
|
57638
|
+
status: { $nin: ["Completed", "Deleted"] }
|
|
57522
57639
|
}
|
|
57523
57640
|
},
|
|
57524
57641
|
{ $count: "count" }
|
|
@@ -57528,7 +57645,7 @@ function useNewDashboardRepo() {
|
|
|
57528
57645
|
$match: {
|
|
57529
57646
|
site: { $in: [siteIdObj, siteId] },
|
|
57530
57647
|
createdAt: { $gte: today, $lte: todayEnd },
|
|
57531
|
-
status: { $nin: ["
|
|
57648
|
+
status: { $nin: ["Completed", "Deleted"] }
|
|
57532
57649
|
}
|
|
57533
57650
|
},
|
|
57534
57651
|
{ $count: "count" }
|
|
@@ -57537,7 +57654,7 @@ function useNewDashboardRepo() {
|
|
|
57537
57654
|
{
|
|
57538
57655
|
$match: {
|
|
57539
57656
|
site: { $in: [siteIdObj, siteId] },
|
|
57540
|
-
status: { $in: ["pending"
|
|
57657
|
+
status: { $in: ["pending"] },
|
|
57541
57658
|
createdAt: periodRange
|
|
57542
57659
|
}
|
|
57543
57660
|
},
|
|
@@ -57547,7 +57664,7 @@ function useNewDashboardRepo() {
|
|
|
57547
57664
|
{
|
|
57548
57665
|
$match: {
|
|
57549
57666
|
site: { $in: [siteIdObj, siteId] },
|
|
57550
|
-
status: { $in: ["pending"
|
|
57667
|
+
status: { $in: ["pending"] },
|
|
57551
57668
|
createdAt: { $gte: yesterday, $lte: yesterdayEnd }
|
|
57552
57669
|
}
|
|
57553
57670
|
},
|
|
@@ -57557,7 +57674,7 @@ function useNewDashboardRepo() {
|
|
|
57557
57674
|
{
|
|
57558
57675
|
$match: {
|
|
57559
57676
|
site: { $in: [siteIdObj, siteId] },
|
|
57560
|
-
status: { $in: ["pending"
|
|
57677
|
+
status: { $in: ["pending"] },
|
|
57561
57678
|
createdAt: { $gte: today, $lte: todayEnd }
|
|
57562
57679
|
}
|
|
57563
57680
|
},
|
|
@@ -57807,6 +57924,13 @@ function useNewDashboardRepo() {
|
|
|
57807
57924
|
const periodRange = getDateRange(period);
|
|
57808
57925
|
try {
|
|
57809
57926
|
const workOrderService = workOrderServiceMap[serviceType] ?? serviceType;
|
|
57927
|
+
const workOrderMatchQuery = {
|
|
57928
|
+
site,
|
|
57929
|
+
status: { $nin: ["Completed", "Deleted"] }
|
|
57930
|
+
};
|
|
57931
|
+
if (serviceType !== "property_management_agency") {
|
|
57932
|
+
workOrderMatchQuery.service = workOrderService;
|
|
57933
|
+
}
|
|
57810
57934
|
const [
|
|
57811
57935
|
workOrderReport,
|
|
57812
57936
|
supplyAlertReport,
|
|
@@ -57819,17 +57943,15 @@ function useNewDashboardRepo() {
|
|
|
57819
57943
|
workOrderCollection.aggregate([
|
|
57820
57944
|
{
|
|
57821
57945
|
$match: {
|
|
57822
|
-
|
|
57823
|
-
|
|
57824
|
-
createdAt: periodRange,
|
|
57825
|
-
status: { $nin: ["completed"] }
|
|
57946
|
+
...workOrderMatchQuery,
|
|
57947
|
+
createdAt: periodRange
|
|
57826
57948
|
}
|
|
57827
57949
|
},
|
|
57828
57950
|
{
|
|
57829
57951
|
$facet: {
|
|
57830
57952
|
total: [{ $count: "count" }],
|
|
57831
57953
|
inProgress: [
|
|
57832
|
-
{ $match: { status: "
|
|
57954
|
+
{ $match: { status: "In-Progress" } },
|
|
57833
57955
|
{ $count: "count" }
|
|
57834
57956
|
]
|
|
57835
57957
|
}
|
|
@@ -57860,10 +57982,8 @@ function useNewDashboardRepo() {
|
|
|
57860
57982
|
workOrderCollection.aggregate([
|
|
57861
57983
|
{
|
|
57862
57984
|
$match: {
|
|
57863
|
-
|
|
57864
|
-
|
|
57865
|
-
createdAt: { $gte: yesterday, $lte: yesterdayEnd },
|
|
57866
|
-
status: { $nin: ["completed"] }
|
|
57985
|
+
...workOrderMatchQuery,
|
|
57986
|
+
createdAt: { $gte: yesterday, $lte: yesterdayEnd }
|
|
57867
57987
|
}
|
|
57868
57988
|
},
|
|
57869
57989
|
{ $count: "count" }
|
|
@@ -57871,10 +57991,8 @@ function useNewDashboardRepo() {
|
|
|
57871
57991
|
workOrderCollection.aggregate([
|
|
57872
57992
|
{
|
|
57873
57993
|
$match: {
|
|
57874
|
-
|
|
57875
|
-
|
|
57876
|
-
createdAt: { $gte: today, $lte: todayEnd },
|
|
57877
|
-
status: { $nin: ["completed"] }
|
|
57994
|
+
...workOrderMatchQuery,
|
|
57995
|
+
createdAt: { $gte: today, $lte: todayEnd }
|
|
57878
57996
|
}
|
|
57879
57997
|
},
|
|
57880
57998
|
{ $count: "count" }
|
|
@@ -57977,10 +58095,9 @@ function useNewDashboardRepo() {
|
|
|
57977
58095
|
throw new import_node_server_utils199.BadRequestError("Invalid period.");
|
|
57978
58096
|
}
|
|
57979
58097
|
try {
|
|
57980
|
-
const
|
|
58098
|
+
const workOrderQuery = {
|
|
57981
58099
|
site,
|
|
57982
|
-
|
|
57983
|
-
status: { $nin: ["deleted", "Deleted"] },
|
|
58100
|
+
status: { $nin: ["Deleted"] },
|
|
57984
58101
|
$or: [
|
|
57985
58102
|
{ createdAt: { $gte: rangeStart, $lte: rangeEnd } },
|
|
57986
58103
|
{
|
|
@@ -57990,7 +58107,11 @@ function useNewDashboardRepo() {
|
|
|
57990
58107
|
}
|
|
57991
58108
|
}
|
|
57992
58109
|
]
|
|
57993
|
-
}
|
|
58110
|
+
};
|
|
58111
|
+
if (serviceType !== "property_management_agency") {
|
|
58112
|
+
workOrderQuery.service = workOrderService;
|
|
58113
|
+
}
|
|
58114
|
+
const workOrders = await workOrderCollection.find(workOrderQuery).project({ status: 1, createdAt: 1 }).toArray();
|
|
57994
58115
|
const chartData = labels.map((label) => ({
|
|
57995
58116
|
day: label,
|
|
57996
58117
|
label,
|
|
@@ -58087,6 +58208,7 @@ function useNewDashboardRepo() {
|
|
|
58087
58208
|
name: 1,
|
|
58088
58209
|
type: 1,
|
|
58089
58210
|
status: 1,
|
|
58211
|
+
schedule: 1,
|
|
58090
58212
|
assigneeName: { $arrayElemAt: ["$_assigneeDoc.name", 0] }
|
|
58091
58213
|
}
|
|
58092
58214
|
},
|
|
@@ -58251,7 +58373,10 @@ function useNewDashboardRepo() {
|
|
|
58251
58373
|
throw new import_node_server_utils199.BadRequestError("Invalid site ID format.");
|
|
58252
58374
|
}
|
|
58253
58375
|
const workOrderService = workOrderServiceMap[serviceType] ?? serviceType;
|
|
58254
|
-
const matchQuery = { site
|
|
58376
|
+
const matchQuery = { site };
|
|
58377
|
+
if (serviceType !== "property_management_agency") {
|
|
58378
|
+
matchQuery.service = workOrderService;
|
|
58379
|
+
}
|
|
58255
58380
|
if (period) {
|
|
58256
58381
|
matchQuery.createdAt = getDateRange(period);
|
|
58257
58382
|
}
|
|
@@ -65468,7 +65593,7 @@ function usePostFavoriteService() {
|
|
|
65468
65593
|
});
|
|
65469
65594
|
}
|
|
65470
65595
|
await session?.commitTransaction();
|
|
65471
|
-
return "Successfully added to
|
|
65596
|
+
return "Successfully added to post-preloved.";
|
|
65472
65597
|
} catch (error) {
|
|
65473
65598
|
await session?.abortTransaction();
|
|
65474
65599
|
throw error;
|
|
@@ -66861,9 +66986,112 @@ function useChatPrelovedController() {
|
|
|
66861
66986
|
return { add, updateById, deleteById };
|
|
66862
66987
|
}
|
|
66863
66988
|
|
|
66864
|
-
// src/
|
|
66865
|
-
var import_node_server_utils249 = require("@7365admin1/node-server-utils");
|
|
66989
|
+
// src/events/chat-preloved.event.ts
|
|
66866
66990
|
var import_joi144 = __toESM(require("joi"));
|
|
66991
|
+
var import_node_server_utils249 = require("@7365admin1/node-server-utils");
|
|
66992
|
+
function parseSid(cookieHeader) {
|
|
66993
|
+
const match = cookieHeader.match(/(?:^|;\s*)sid=([^;]*)/);
|
|
66994
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
66995
|
+
}
|
|
66996
|
+
var schemaSendMessage = import_joi144.default.object({
|
|
66997
|
+
receiverId: import_joi144.default.string().hex().length(24).required(),
|
|
66998
|
+
channelId: import_joi144.default.string().hex().length(24).optional().allow("", null),
|
|
66999
|
+
senderId: import_joi144.default.string().hex().length(24).required(),
|
|
67000
|
+
postId: import_joi144.default.string().hex().length(24).optional().allow("", null),
|
|
67001
|
+
message: import_joi144.default.object({
|
|
67002
|
+
text: import_joi144.default.string().required(),
|
|
67003
|
+
date: import_joi144.default.date().optional().allow(null),
|
|
67004
|
+
time: import_joi144.default.string().optional().allow("", null),
|
|
67005
|
+
senderId: import_joi144.default.string().hex().length(24).required()
|
|
67006
|
+
}).required(),
|
|
67007
|
+
readMessage: import_joi144.default.array().items(import_joi144.default.string().hex()).optional().default([]),
|
|
67008
|
+
viewMessage: import_joi144.default.array().items(import_joi144.default.string().hex()).optional().default([]),
|
|
67009
|
+
attachments: import_joi144.default.array().items(import_joi144.default.string().hex()).optional().default([]),
|
|
67010
|
+
reactions: import_joi144.default.string().optional().allow("", null).default(""),
|
|
67011
|
+
bidId: import_joi144.default.string().hex().length(24).optional().allow("", null),
|
|
67012
|
+
edited: import_joi144.default.boolean().optional().default(false)
|
|
67013
|
+
});
|
|
67014
|
+
var schemaTyping = import_joi144.default.object({
|
|
67015
|
+
receiverId: import_joi144.default.string().hex().length(24).required(),
|
|
67016
|
+
fromUserId: import_joi144.default.string().hex().length(24).required(),
|
|
67017
|
+
senderName: import_joi144.default.string().required()
|
|
67018
|
+
});
|
|
67019
|
+
var schemaChatMessageDeleted = import_joi144.default.object({
|
|
67020
|
+
messageId: import_joi144.default.string().hex().length(24).required(),
|
|
67021
|
+
receiverId: import_joi144.default.string().hex().length(24).required()
|
|
67022
|
+
});
|
|
67023
|
+
function chatPrelovedEvents(io) {
|
|
67024
|
+
const namespace = io.of(/^\/chat-channel-[0-9a-fA-F]{24}$/);
|
|
67025
|
+
namespace.use(async (socket, next) => {
|
|
67026
|
+
try {
|
|
67027
|
+
const cookieHeader = socket.handshake.headers.cookie || "";
|
|
67028
|
+
let sid = parseSid(cookieHeader);
|
|
67029
|
+
if (!sid && socket.handshake.auth?.token) {
|
|
67030
|
+
sid = socket.handshake.auth.token;
|
|
67031
|
+
}
|
|
67032
|
+
if (!sid) {
|
|
67033
|
+
return next(new Error("Unauthorized"));
|
|
67034
|
+
}
|
|
67035
|
+
const { getCache } = (0, import_node_server_utils249.useCache)("sessions");
|
|
67036
|
+
const sessionData = await getCache(`sid:${sid}`);
|
|
67037
|
+
if (!sessionData) {
|
|
67038
|
+
return next(new Error("Session expired or invalid"));
|
|
67039
|
+
}
|
|
67040
|
+
const session = sessionData;
|
|
67041
|
+
socket.data.userId = (session._id ?? sessionData).toString();
|
|
67042
|
+
next();
|
|
67043
|
+
} catch (error) {
|
|
67044
|
+
import_node_server_utils249.logger.log({ level: "error", message: `Socket auth error: ${error.message}` });
|
|
67045
|
+
next(new Error("Authentication error"));
|
|
67046
|
+
}
|
|
67047
|
+
});
|
|
67048
|
+
namespace.on("connection", (socket) => {
|
|
67049
|
+
const userId = socket.data.userId;
|
|
67050
|
+
socket.join(userId);
|
|
67051
|
+
socket.on("sendMessage", (payload) => {
|
|
67052
|
+
const { error, value } = schemaSendMessage.validate(payload, {
|
|
67053
|
+
abortEarly: false
|
|
67054
|
+
});
|
|
67055
|
+
if (error) {
|
|
67056
|
+
const message = error.details.map((d) => d.message).join(", ");
|
|
67057
|
+
socket.emit("error", { event: "sendMessage", message });
|
|
67058
|
+
return;
|
|
67059
|
+
}
|
|
67060
|
+
namespace.to(value.receiverId).emit("receiveMessage", value);
|
|
67061
|
+
});
|
|
67062
|
+
socket.on("typing", (data) => {
|
|
67063
|
+
const { error, value } = schemaTyping.validate(data, {
|
|
67064
|
+
abortEarly: false
|
|
67065
|
+
});
|
|
67066
|
+
if (error) {
|
|
67067
|
+
const message = error.details.map((d) => d.message).join(", ");
|
|
67068
|
+
socket.emit("error", { event: "typing", message });
|
|
67069
|
+
return;
|
|
67070
|
+
}
|
|
67071
|
+
namespace.to(value.receiverId).emit("TypingNow", value);
|
|
67072
|
+
});
|
|
67073
|
+
socket.on("chatMessageDeleted", (data) => {
|
|
67074
|
+
const { error, value } = schemaChatMessageDeleted.validate(data, {
|
|
67075
|
+
abortEarly: false
|
|
67076
|
+
});
|
|
67077
|
+
if (error) {
|
|
67078
|
+
const message = error.details.map((d) => d.message).join(", ");
|
|
67079
|
+
socket.emit("error", { event: "chatMessageDeleted", message });
|
|
67080
|
+
return;
|
|
67081
|
+
}
|
|
67082
|
+
namespace.to(value.receiverId).emit("chatMessageDeleted", {
|
|
67083
|
+
messageId: value.messageId
|
|
67084
|
+
});
|
|
67085
|
+
});
|
|
67086
|
+
socket.on("disconnect", () => {
|
|
67087
|
+
socket.leave(userId);
|
|
67088
|
+
});
|
|
67089
|
+
});
|
|
67090
|
+
}
|
|
67091
|
+
|
|
67092
|
+
// src/controllers/channel-preloved.controller.ts
|
|
67093
|
+
var import_node_server_utils250 = require("@7365admin1/node-server-utils");
|
|
67094
|
+
var import_joi145 = __toESM(require("joi"));
|
|
66867
67095
|
function useChannelPrelovedController() {
|
|
66868
67096
|
const {
|
|
66869
67097
|
add: _add,
|
|
@@ -66877,40 +67105,40 @@ function useChannelPrelovedController() {
|
|
|
66877
67105
|
});
|
|
66878
67106
|
if (error) {
|
|
66879
67107
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
66880
|
-
|
|
66881
|
-
next(new
|
|
67108
|
+
import_node_server_utils250.logger.log({ level: "error", message: messages });
|
|
67109
|
+
next(new import_node_server_utils250.BadRequestError(messages));
|
|
66882
67110
|
return;
|
|
66883
67111
|
}
|
|
66884
67112
|
try {
|
|
66885
67113
|
const data = await _add(value);
|
|
66886
67114
|
res.status(201).json(data);
|
|
66887
67115
|
} catch (error2) {
|
|
66888
|
-
|
|
67116
|
+
import_node_server_utils250.logger.log({ level: "error", message: error2.message });
|
|
66889
67117
|
next(error2);
|
|
66890
67118
|
}
|
|
66891
67119
|
}
|
|
66892
67120
|
async function getChannelMessages(req, res, next) {
|
|
66893
|
-
const paramsSchema =
|
|
66894
|
-
id:
|
|
67121
|
+
const paramsSchema = import_joi145.default.object({
|
|
67122
|
+
id: import_joi145.default.string().hex().length(24).required()
|
|
66895
67123
|
});
|
|
66896
|
-
const querySchema =
|
|
66897
|
-
page:
|
|
66898
|
-
limit:
|
|
66899
|
-
isLoadMore:
|
|
66900
|
-
lastMessageId:
|
|
67124
|
+
const querySchema = import_joi145.default.object({
|
|
67125
|
+
page: import_joi145.default.number().integer().min(1).default(1),
|
|
67126
|
+
limit: import_joi145.default.number().integer().min(1).max(100).default(10),
|
|
67127
|
+
isLoadMore: import_joi145.default.boolean().default(false),
|
|
67128
|
+
lastMessageId: import_joi145.default.string().hex().length(24).optional().allow("", null)
|
|
66901
67129
|
});
|
|
66902
67130
|
const { error: paramError, value: params } = paramsSchema.validate(
|
|
66903
67131
|
req.params
|
|
66904
67132
|
);
|
|
66905
67133
|
if (paramError) {
|
|
66906
|
-
|
|
66907
|
-
next(new
|
|
67134
|
+
import_node_server_utils250.logger.log({ level: "error", message: paramError.message });
|
|
67135
|
+
next(new import_node_server_utils250.BadRequestError(paramError.message));
|
|
66908
67136
|
return;
|
|
66909
67137
|
}
|
|
66910
67138
|
const { error: queryError, value: query } = querySchema.validate(req.query);
|
|
66911
67139
|
if (queryError) {
|
|
66912
|
-
|
|
66913
|
-
next(new
|
|
67140
|
+
import_node_server_utils250.logger.log({ level: "error", message: queryError.message });
|
|
67141
|
+
next(new import_node_server_utils250.BadRequestError(queryError.message));
|
|
66914
67142
|
return;
|
|
66915
67143
|
}
|
|
66916
67144
|
try {
|
|
@@ -66923,20 +67151,20 @@ function useChannelPrelovedController() {
|
|
|
66923
67151
|
);
|
|
66924
67152
|
res.status(200).json(data);
|
|
66925
67153
|
} catch (error) {
|
|
66926
|
-
|
|
67154
|
+
import_node_server_utils250.logger.log({ level: "error", message: error.message });
|
|
66927
67155
|
next(error);
|
|
66928
67156
|
}
|
|
66929
67157
|
}
|
|
66930
67158
|
async function getChannel(req, res, next) {
|
|
66931
|
-
const querySchema =
|
|
66932
|
-
postId:
|
|
66933
|
-
receiverId:
|
|
66934
|
-
senderId:
|
|
67159
|
+
const querySchema = import_joi145.default.object({
|
|
67160
|
+
postId: import_joi145.default.string().hex().length(24).required(),
|
|
67161
|
+
receiverId: import_joi145.default.string().hex().length(24).required(),
|
|
67162
|
+
senderId: import_joi145.default.string().hex().length(24).required()
|
|
66935
67163
|
});
|
|
66936
67164
|
const { error, value } = querySchema.validate(req.query);
|
|
66937
67165
|
if (error) {
|
|
66938
|
-
|
|
66939
|
-
next(new
|
|
67166
|
+
import_node_server_utils250.logger.log({ level: "error", message: error.message });
|
|
67167
|
+
next(new import_node_server_utils250.BadRequestError(error.message));
|
|
66940
67168
|
return;
|
|
66941
67169
|
}
|
|
66942
67170
|
try {
|
|
@@ -66947,21 +67175,21 @@ function useChannelPrelovedController() {
|
|
|
66947
67175
|
);
|
|
66948
67176
|
res.status(200).json(data);
|
|
66949
67177
|
} catch (error2) {
|
|
66950
|
-
|
|
67178
|
+
import_node_server_utils250.logger.log({ level: "error", message: error2.message });
|
|
66951
67179
|
next(error2);
|
|
66952
67180
|
}
|
|
66953
67181
|
}
|
|
66954
67182
|
async function getChatLists(req, res, next) {
|
|
66955
|
-
const querySchema =
|
|
66956
|
-
currentUserId:
|
|
66957
|
-
page:
|
|
66958
|
-
limit:
|
|
66959
|
-
search:
|
|
67183
|
+
const querySchema = import_joi145.default.object({
|
|
67184
|
+
currentUserId: import_joi145.default.string().hex().length(24).required(),
|
|
67185
|
+
page: import_joi145.default.number().integer().min(1).default(1),
|
|
67186
|
+
limit: import_joi145.default.number().integer().min(1).max(100).default(10),
|
|
67187
|
+
search: import_joi145.default.string().optional().allow("", null)
|
|
66960
67188
|
});
|
|
66961
67189
|
const { error, value } = querySchema.validate(req.query);
|
|
66962
67190
|
if (error) {
|
|
66963
|
-
|
|
66964
|
-
next(new
|
|
67191
|
+
import_node_server_utils250.logger.log({ level: "error", message: error.message });
|
|
67192
|
+
next(new import_node_server_utils250.BadRequestError(error.message));
|
|
66965
67193
|
return;
|
|
66966
67194
|
}
|
|
66967
67195
|
try {
|
|
@@ -66973,7 +67201,7 @@ function useChannelPrelovedController() {
|
|
|
66973
67201
|
);
|
|
66974
67202
|
res.status(200).json(data);
|
|
66975
67203
|
} catch (error2) {
|
|
66976
|
-
|
|
67204
|
+
import_node_server_utils250.logger.log({ level: "error", message: error2.message });
|
|
66977
67205
|
next(error2);
|
|
66978
67206
|
}
|
|
66979
67207
|
}
|
|
@@ -66981,7 +67209,7 @@ function useChannelPrelovedController() {
|
|
|
66981
67209
|
}
|
|
66982
67210
|
|
|
66983
67211
|
// src/models/bid-preloved.model.ts
|
|
66984
|
-
var
|
|
67212
|
+
var import_joi146 = __toESM(require("joi"));
|
|
66985
67213
|
var import_mongodb149 = require("mongodb");
|
|
66986
67214
|
var BidType = /* @__PURE__ */ ((BidType2) => {
|
|
66987
67215
|
BidType2["BID"] = "bid";
|
|
@@ -66995,21 +67223,21 @@ var BidStatus = /* @__PURE__ */ ((BidStatus3) => {
|
|
|
66995
67223
|
BidStatus3["CANCELLED"] = "cancelled";
|
|
66996
67224
|
return BidStatus3;
|
|
66997
67225
|
})(BidStatus || {});
|
|
66998
|
-
var schemaBidPreloved =
|
|
66999
|
-
type:
|
|
67000
|
-
postId:
|
|
67001
|
-
receiverId:
|
|
67002
|
-
buyerId:
|
|
67003
|
-
price:
|
|
67226
|
+
var schemaBidPreloved = import_joi146.default.object({
|
|
67227
|
+
type: import_joi146.default.string().valid(...Object.values(BidType)).required(),
|
|
67228
|
+
postId: import_joi146.default.string().hex().length(24).required(),
|
|
67229
|
+
receiverId: import_joi146.default.string().hex().length(24).required(),
|
|
67230
|
+
buyerId: import_joi146.default.string().hex().length(24).required(),
|
|
67231
|
+
price: import_joi146.default.when("type", {
|
|
67004
67232
|
is: "bid" /* BID */,
|
|
67005
|
-
then:
|
|
67006
|
-
otherwise:
|
|
67233
|
+
then: import_joi146.default.number().required(),
|
|
67234
|
+
otherwise: import_joi146.default.number().optional().allow(null)
|
|
67007
67235
|
}),
|
|
67008
|
-
message:
|
|
67009
|
-
status:
|
|
67236
|
+
message: import_joi146.default.string().optional().allow("", null),
|
|
67237
|
+
status: import_joi146.default.string().valid(...Object.values(BidStatus)).optional().default("pending" /* PENDING */)
|
|
67010
67238
|
});
|
|
67011
|
-
var schemaUpdateBidPreloved =
|
|
67012
|
-
status:
|
|
67239
|
+
var schemaUpdateBidPreloved = import_joi146.default.object({
|
|
67240
|
+
status: import_joi146.default.string().valid(...Object.values(BidStatus)).required()
|
|
67013
67241
|
});
|
|
67014
67242
|
function MBidPreloved(value) {
|
|
67015
67243
|
const { error } = schemaBidPreloved.validate(value);
|
|
@@ -67033,12 +67261,12 @@ function MBidPreloved(value) {
|
|
|
67033
67261
|
}
|
|
67034
67262
|
|
|
67035
67263
|
// src/repositories/bid-preloved.repo.ts
|
|
67036
|
-
var
|
|
67264
|
+
var import_node_server_utils251 = require("@7365admin1/node-server-utils");
|
|
67037
67265
|
var import_mongodb150 = require("mongodb");
|
|
67038
67266
|
function useBidPrelovedRepo() {
|
|
67039
|
-
const db =
|
|
67267
|
+
const db = import_node_server_utils251.useAtlas.getDb();
|
|
67040
67268
|
if (!db)
|
|
67041
|
-
throw new
|
|
67269
|
+
throw new import_node_server_utils251.InternalServerError("Unable to connect to server.");
|
|
67042
67270
|
const collection = db.collection("bid-preloved");
|
|
67043
67271
|
async function add(value, session) {
|
|
67044
67272
|
try {
|
|
@@ -67053,13 +67281,13 @@ function useBidPrelovedRepo() {
|
|
|
67053
67281
|
const objectId2 = typeof _id === "string" ? new import_mongodb150.ObjectId(_id) : _id;
|
|
67054
67282
|
const existing = await collection.findOne({ _id: objectId2 });
|
|
67055
67283
|
if (!existing)
|
|
67056
|
-
throw new
|
|
67284
|
+
throw new import_node_server_utils251.NotFoundError("Bid not found.");
|
|
67057
67285
|
const res = await collection.updateOne(
|
|
67058
67286
|
{ _id: objectId2 },
|
|
67059
67287
|
{ $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } }
|
|
67060
67288
|
);
|
|
67061
67289
|
if (res.modifiedCount === 0)
|
|
67062
|
-
throw new
|
|
67290
|
+
throw new import_node_server_utils251.InternalServerError("Unable to update bid.");
|
|
67063
67291
|
return "Bid updated successfully.";
|
|
67064
67292
|
}
|
|
67065
67293
|
async function getById(_id) {
|
|
@@ -67067,26 +67295,22 @@ function useBidPrelovedRepo() {
|
|
|
67067
67295
|
_id = new import_mongodb150.ObjectId(_id);
|
|
67068
67296
|
const result = await collection.findOne({ _id });
|
|
67069
67297
|
if (!result)
|
|
67070
|
-
throw new
|
|
67298
|
+
throw new import_node_server_utils251.NotFoundError("Bid not found.");
|
|
67071
67299
|
return result;
|
|
67072
67300
|
}
|
|
67073
67301
|
return { add, getById, updateStatus };
|
|
67074
67302
|
}
|
|
67075
67303
|
|
|
67076
|
-
// src/controllers/bid-preloved.controller.ts
|
|
67077
|
-
var import_node_server_utils252 = require("@7365admin1/node-server-utils");
|
|
67078
|
-
var import_joi146 = __toESM(require("joi"));
|
|
67079
|
-
|
|
67080
67304
|
// src/services/bid-preloved.service.ts
|
|
67081
|
-
var
|
|
67305
|
+
var import_node_server_utils252 = require("@7365admin1/node-server-utils");
|
|
67082
67306
|
function useBidPrelovedService() {
|
|
67083
67307
|
const { add: _addBid } = useBidPrelovedRepo();
|
|
67084
67308
|
const { add: _addChannel, getByParticipants: _getByParticipants } = useChannelPrelovedRepo();
|
|
67085
67309
|
const { add: _addChat } = useChatPrelovedRepo();
|
|
67086
67310
|
async function createBid(value) {
|
|
67087
|
-
const client =
|
|
67311
|
+
const client = import_node_server_utils252.useAtlas.getClient();
|
|
67088
67312
|
if (!client)
|
|
67089
|
-
throw new
|
|
67313
|
+
throw new import_node_server_utils252.InternalServerError("Unable to connect to server.");
|
|
67090
67314
|
const buyerId = value.buyerId;
|
|
67091
67315
|
const receiverId = value.receiverId;
|
|
67092
67316
|
const postId = value.postId;
|
|
@@ -67141,6 +67365,8 @@ function useBidPrelovedService() {
|
|
|
67141
67365
|
}
|
|
67142
67366
|
|
|
67143
67367
|
// src/controllers/bid-preloved.controller.ts
|
|
67368
|
+
var import_node_server_utils253 = require("@7365admin1/node-server-utils");
|
|
67369
|
+
var import_joi147 = __toESM(require("joi"));
|
|
67144
67370
|
function useBidPrelovedController() {
|
|
67145
67371
|
const { createBid: _createBid } = useBidPrelovedService();
|
|
67146
67372
|
const { getById: _getById, updateStatus: _updateStatus } = useBidPrelovedRepo();
|
|
@@ -67150,8 +67376,8 @@ function useBidPrelovedController() {
|
|
|
67150
67376
|
});
|
|
67151
67377
|
if (error) {
|
|
67152
67378
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
67153
|
-
|
|
67154
|
-
next(new
|
|
67379
|
+
import_node_server_utils253.logger.log({ level: "error", message: messages });
|
|
67380
|
+
next(new import_node_server_utils253.BadRequestError(messages));
|
|
67155
67381
|
return;
|
|
67156
67382
|
}
|
|
67157
67383
|
try {
|
|
@@ -67159,53 +67385,53 @@ function useBidPrelovedController() {
|
|
|
67159
67385
|
res.status(201).json(data);
|
|
67160
67386
|
} catch (error2) {
|
|
67161
67387
|
console.log("error", error2);
|
|
67162
|
-
|
|
67388
|
+
import_node_server_utils253.logger.log({ level: "error", message: error2.message });
|
|
67163
67389
|
next(error2);
|
|
67164
67390
|
}
|
|
67165
67391
|
}
|
|
67166
67392
|
async function updateStatus(req, res, next) {
|
|
67167
|
-
const paramsSchema =
|
|
67168
|
-
id:
|
|
67393
|
+
const paramsSchema = import_joi147.default.object({
|
|
67394
|
+
id: import_joi147.default.string().hex().length(24).required()
|
|
67169
67395
|
});
|
|
67170
67396
|
const { error: paramError, value: params } = paramsSchema.validate(
|
|
67171
67397
|
req.params
|
|
67172
67398
|
);
|
|
67173
67399
|
if (paramError) {
|
|
67174
|
-
|
|
67175
|
-
next(new
|
|
67400
|
+
import_node_server_utils253.logger.log({ level: "error", message: paramError.message });
|
|
67401
|
+
next(new import_node_server_utils253.BadRequestError(paramError.message));
|
|
67176
67402
|
return;
|
|
67177
67403
|
}
|
|
67178
67404
|
const { error: bodyError, value: body } = schemaUpdateBidPreloved.validate(
|
|
67179
67405
|
req.body
|
|
67180
67406
|
);
|
|
67181
67407
|
if (bodyError) {
|
|
67182
|
-
|
|
67183
|
-
next(new
|
|
67408
|
+
import_node_server_utils253.logger.log({ level: "error", message: bodyError.message });
|
|
67409
|
+
next(new import_node_server_utils253.BadRequestError(bodyError.message));
|
|
67184
67410
|
return;
|
|
67185
67411
|
}
|
|
67186
67412
|
try {
|
|
67187
67413
|
const data = await _updateStatus(params.id, body.status);
|
|
67188
67414
|
res.status(200).json(data);
|
|
67189
67415
|
} catch (error) {
|
|
67190
|
-
|
|
67416
|
+
import_node_server_utils253.logger.log({ level: "error", message: error.message });
|
|
67191
67417
|
next(error);
|
|
67192
67418
|
}
|
|
67193
67419
|
}
|
|
67194
67420
|
async function getById(req, res, next) {
|
|
67195
|
-
const paramsSchema =
|
|
67196
|
-
id:
|
|
67421
|
+
const paramsSchema = import_joi147.default.object({
|
|
67422
|
+
id: import_joi147.default.string().hex().length(24).required()
|
|
67197
67423
|
});
|
|
67198
67424
|
const { error, value: params } = paramsSchema.validate(req.params);
|
|
67199
67425
|
if (error) {
|
|
67200
|
-
|
|
67201
|
-
next(new
|
|
67426
|
+
import_node_server_utils253.logger.log({ level: "error", message: error.message });
|
|
67427
|
+
next(new import_node_server_utils253.BadRequestError(error.message));
|
|
67202
67428
|
return;
|
|
67203
67429
|
}
|
|
67204
67430
|
try {
|
|
67205
67431
|
const data = await _getById(params.id);
|
|
67206
67432
|
res.status(200).json(data);
|
|
67207
67433
|
} catch (error2) {
|
|
67208
|
-
|
|
67434
|
+
import_node_server_utils253.logger.log({ level: "error", message: error2.message });
|
|
67209
67435
|
next(error2);
|
|
67210
67436
|
}
|
|
67211
67437
|
}
|
|
@@ -67213,7 +67439,7 @@ function useBidPrelovedController() {
|
|
|
67213
67439
|
}
|
|
67214
67440
|
|
|
67215
67441
|
// src/models/online-forms-v2.model.ts
|
|
67216
|
-
var
|
|
67442
|
+
var import_joi148 = __toESM(require("joi"));
|
|
67217
67443
|
var import_mongodb151 = require("mongodb");
|
|
67218
67444
|
var FormEntryStatus = /* @__PURE__ */ ((FormEntryStatus2) => {
|
|
67219
67445
|
FormEntryStatus2["ACTIVE"] = "active";
|
|
@@ -67221,49 +67447,49 @@ var FormEntryStatus = /* @__PURE__ */ ((FormEntryStatus2) => {
|
|
|
67221
67447
|
FormEntryStatus2["DELETED"] = "deleted";
|
|
67222
67448
|
return FormEntryStatus2;
|
|
67223
67449
|
})(FormEntryStatus || {});
|
|
67224
|
-
var schemaFormEntry =
|
|
67225
|
-
_id:
|
|
67226
|
-
formType:
|
|
67227
|
-
block:
|
|
67228
|
-
level:
|
|
67229
|
-
unit:
|
|
67230
|
-
name:
|
|
67231
|
-
phoneNumber:
|
|
67232
|
-
createdBy:
|
|
67233
|
-
fields:
|
|
67234
|
-
|
|
67235
|
-
|
|
67236
|
-
|
|
67237
|
-
|
|
67238
|
-
|
|
67239
|
-
|
|
67450
|
+
var schemaFormEntry = import_joi148.default.object({
|
|
67451
|
+
_id: import_joi148.default.string().hex().optional().allow("", null),
|
|
67452
|
+
formType: import_joi148.default.string().required(),
|
|
67453
|
+
block: import_joi148.default.string().optional().allow(null, ""),
|
|
67454
|
+
level: import_joi148.default.string().optional().allow(null, ""),
|
|
67455
|
+
unit: import_joi148.default.string().optional().allow(null, ""),
|
|
67456
|
+
name: import_joi148.default.string().optional().allow(null, ""),
|
|
67457
|
+
phoneNumber: import_joi148.default.string().optional().allow(null, ""),
|
|
67458
|
+
createdBy: import_joi148.default.string().required(),
|
|
67459
|
+
fields: import_joi148.default.object().pattern(
|
|
67460
|
+
import_joi148.default.string(),
|
|
67461
|
+
import_joi148.default.alternatives().try(
|
|
67462
|
+
import_joi148.default.string(),
|
|
67463
|
+
import_joi148.default.number(),
|
|
67464
|
+
import_joi148.default.boolean(),
|
|
67465
|
+
import_joi148.default.valid(null)
|
|
67240
67466
|
)
|
|
67241
67467
|
).required(),
|
|
67242
|
-
status:
|
|
67243
|
-
org:
|
|
67244
|
-
site:
|
|
67245
|
-
createdAt:
|
|
67246
|
-
updatedAt:
|
|
67247
|
-
deletedAt:
|
|
67468
|
+
status: import_joi148.default.string().optional().allow("", null),
|
|
67469
|
+
org: import_joi148.default.string().hex().optional().allow("", null),
|
|
67470
|
+
site: import_joi148.default.string().hex().optional().allow("", null),
|
|
67471
|
+
createdAt: import_joi148.default.date().optional().allow("", null),
|
|
67472
|
+
updatedAt: import_joi148.default.date().optional().allow("", null),
|
|
67473
|
+
deletedAt: import_joi148.default.date().optional().allow("", null)
|
|
67248
67474
|
});
|
|
67249
|
-
var schemaUpdateFormEntry =
|
|
67250
|
-
_id:
|
|
67251
|
-
formType:
|
|
67252
|
-
block:
|
|
67253
|
-
level:
|
|
67254
|
-
unit:
|
|
67255
|
-
fields:
|
|
67256
|
-
|
|
67257
|
-
|
|
67258
|
-
|
|
67259
|
-
|
|
67260
|
-
|
|
67261
|
-
|
|
67475
|
+
var schemaUpdateFormEntry = import_joi148.default.object({
|
|
67476
|
+
_id: import_joi148.default.string().hex().required(),
|
|
67477
|
+
formType: import_joi148.default.string().optional().allow("", null),
|
|
67478
|
+
block: import_joi148.default.string().optional().allow(null, ""),
|
|
67479
|
+
level: import_joi148.default.string().optional().allow(null, ""),
|
|
67480
|
+
unit: import_joi148.default.string().optional().allow(null, ""),
|
|
67481
|
+
fields: import_joi148.default.object().pattern(
|
|
67482
|
+
import_joi148.default.string(),
|
|
67483
|
+
import_joi148.default.alternatives().try(
|
|
67484
|
+
import_joi148.default.string(),
|
|
67485
|
+
import_joi148.default.number(),
|
|
67486
|
+
import_joi148.default.boolean(),
|
|
67487
|
+
import_joi148.default.valid(null)
|
|
67262
67488
|
)
|
|
67263
67489
|
).optional(),
|
|
67264
|
-
status:
|
|
67265
|
-
updatedAt:
|
|
67266
|
-
deletedAt:
|
|
67490
|
+
status: import_joi148.default.string().optional().allow("", null),
|
|
67491
|
+
updatedAt: import_joi148.default.date().optional().allow("", null),
|
|
67492
|
+
deletedAt: import_joi148.default.date().optional().allow("", null)
|
|
67267
67493
|
});
|
|
67268
67494
|
function MFormEntry(value) {
|
|
67269
67495
|
const { error } = schemaFormEntry.validate(value);
|
|
@@ -67308,49 +67534,49 @@ function MFormEntry(value) {
|
|
|
67308
67534
|
deletedAt: value.deletedAt ?? null
|
|
67309
67535
|
};
|
|
67310
67536
|
}
|
|
67311
|
-
var residentFormEntry =
|
|
67312
|
-
_id:
|
|
67313
|
-
typeOfForm:
|
|
67314
|
-
unitNumber:
|
|
67315
|
-
fields:
|
|
67316
|
-
|
|
67317
|
-
|
|
67318
|
-
|
|
67319
|
-
|
|
67320
|
-
|
|
67321
|
-
|
|
67537
|
+
var residentFormEntry = import_joi148.default.object({
|
|
67538
|
+
_id: import_joi148.default.string().hex().optional().allow("", null),
|
|
67539
|
+
typeOfForm: import_joi148.default.string().optional().allow("", null),
|
|
67540
|
+
unitNumber: import_joi148.default.string().optional().allow(null, ""),
|
|
67541
|
+
fields: import_joi148.default.object().pattern(
|
|
67542
|
+
import_joi148.default.string(),
|
|
67543
|
+
import_joi148.default.alternatives().try(
|
|
67544
|
+
import_joi148.default.string(),
|
|
67545
|
+
import_joi148.default.number(),
|
|
67546
|
+
import_joi148.default.boolean(),
|
|
67547
|
+
import_joi148.default.valid(null)
|
|
67322
67548
|
)
|
|
67323
67549
|
).optional().allow(null, ""),
|
|
67324
|
-
status:
|
|
67325
|
-
org:
|
|
67326
|
-
site:
|
|
67327
|
-
userId:
|
|
67328
|
-
createdAt:
|
|
67329
|
-
updatedAt:
|
|
67330
|
-
deletedAt:
|
|
67331
|
-
remarks:
|
|
67332
|
-
managementValues:
|
|
67333
|
-
|
|
67334
|
-
|
|
67335
|
-
|
|
67336
|
-
|
|
67337
|
-
|
|
67338
|
-
|
|
67550
|
+
status: import_joi148.default.string().optional().allow("", null),
|
|
67551
|
+
org: import_joi148.default.string().hex().optional().allow("", null),
|
|
67552
|
+
site: import_joi148.default.string().hex().optional().allow("", null),
|
|
67553
|
+
userId: import_joi148.default.string().hex().optional().allow("", null),
|
|
67554
|
+
createdAt: import_joi148.default.date().optional().allow("", null),
|
|
67555
|
+
updatedAt: import_joi148.default.date().optional().allow("", null),
|
|
67556
|
+
deletedAt: import_joi148.default.date().optional().allow("", null),
|
|
67557
|
+
remarks: import_joi148.default.string().optional().allow("", null),
|
|
67558
|
+
managementValues: import_joi148.default.object().pattern(
|
|
67559
|
+
import_joi148.default.string(),
|
|
67560
|
+
import_joi148.default.alternatives().try(
|
|
67561
|
+
import_joi148.default.string(),
|
|
67562
|
+
import_joi148.default.number(),
|
|
67563
|
+
import_joi148.default.boolean(),
|
|
67564
|
+
import_joi148.default.valid(null)
|
|
67339
67565
|
)
|
|
67340
67566
|
).optional().allow(null, "")
|
|
67341
67567
|
});
|
|
67342
67568
|
|
|
67343
67569
|
// src/repositories/online-forms-v2.repository.ts
|
|
67344
|
-
var
|
|
67570
|
+
var import_node_server_utils254 = require("@7365admin1/node-server-utils");
|
|
67345
67571
|
var import_mongodb152 = require("mongodb");
|
|
67346
67572
|
var online_forms_namespace_collection = "online-forms";
|
|
67347
67573
|
function useFormEntryRepo() {
|
|
67348
|
-
const db =
|
|
67574
|
+
const db = import_node_server_utils254.useAtlas.getDb();
|
|
67349
67575
|
if (!db) {
|
|
67350
|
-
throw new
|
|
67576
|
+
throw new import_node_server_utils254.InternalServerError("Unable to connect to server.");
|
|
67351
67577
|
}
|
|
67352
67578
|
const collection = db.collection(online_forms_namespace_collection);
|
|
67353
|
-
const { delNamespace, getCache, setCache } = (0,
|
|
67579
|
+
const { delNamespace, getCache, setCache } = (0, import_node_server_utils254.useCache)(
|
|
67354
67580
|
online_forms_namespace_collection
|
|
67355
67581
|
);
|
|
67356
67582
|
const { getUserById } = useUserRepo();
|
|
@@ -67360,7 +67586,7 @@ function useFormEntryRepo() {
|
|
|
67360
67586
|
name: "text"
|
|
67361
67587
|
});
|
|
67362
67588
|
} catch (error) {
|
|
67363
|
-
throw new
|
|
67589
|
+
throw new import_node_server_utils254.InternalServerError(
|
|
67364
67590
|
"Failed to create text index on online form."
|
|
67365
67591
|
);
|
|
67366
67592
|
}
|
|
@@ -67373,7 +67599,7 @@ function useFormEntryRepo() {
|
|
|
67373
67599
|
} catch (error) {
|
|
67374
67600
|
const isDuplicated = error.message.includes("duplicate");
|
|
67375
67601
|
if (isDuplicated) {
|
|
67376
|
-
throw new
|
|
67602
|
+
throw new import_node_server_utils254.BadRequestError("Online Form already exists.");
|
|
67377
67603
|
}
|
|
67378
67604
|
throw error;
|
|
67379
67605
|
}
|
|
@@ -67426,7 +67652,7 @@ function useFormEntryRepo() {
|
|
|
67426
67652
|
{ $project: { user: 0 } }
|
|
67427
67653
|
]).toArray();
|
|
67428
67654
|
const length = await collection.countDocuments(query);
|
|
67429
|
-
const data = (0,
|
|
67655
|
+
const data = (0, import_node_server_utils254.paginate)(items, page, limit, length);
|
|
67430
67656
|
return data;
|
|
67431
67657
|
} catch (error) {
|
|
67432
67658
|
throw error;
|
|
@@ -67436,13 +67662,13 @@ function useFormEntryRepo() {
|
|
|
67436
67662
|
try {
|
|
67437
67663
|
_id = new import_mongodb152.ObjectId(_id);
|
|
67438
67664
|
} catch (error) {
|
|
67439
|
-
throw new
|
|
67665
|
+
throw new import_node_server_utils254.BadRequestError("Invalid online form ID format.");
|
|
67440
67666
|
}
|
|
67441
67667
|
const query = { _id, status: { $ne: "deleted" } };
|
|
67442
67668
|
try {
|
|
67443
67669
|
const [data] = await collection.aggregate([{ $match: query }]).toArray();
|
|
67444
67670
|
if (!data) {
|
|
67445
|
-
throw new
|
|
67671
|
+
throw new import_node_server_utils254.NotFoundError("Document not found.");
|
|
67446
67672
|
}
|
|
67447
67673
|
return data;
|
|
67448
67674
|
} catch (error) {
|
|
@@ -67453,7 +67679,7 @@ function useFormEntryRepo() {
|
|
|
67453
67679
|
try {
|
|
67454
67680
|
_id = new import_mongodb152.ObjectId(_id);
|
|
67455
67681
|
} catch (error) {
|
|
67456
|
-
throw new
|
|
67682
|
+
throw new import_node_server_utils254.BadRequestError("Invalid online form ID format.");
|
|
67457
67683
|
}
|
|
67458
67684
|
try {
|
|
67459
67685
|
const updateValue = {
|
|
@@ -67462,15 +67688,15 @@ function useFormEntryRepo() {
|
|
|
67462
67688
|
};
|
|
67463
67689
|
const res = await collection.updateOne({ _id }, { $set: updateValue });
|
|
67464
67690
|
if (res.modifiedCount === 0) {
|
|
67465
|
-
throw new
|
|
67691
|
+
throw new import_node_server_utils254.InternalServerError("Unable to update online form.");
|
|
67466
67692
|
}
|
|
67467
67693
|
const onlineFormRequest = await collection.findOne({ _id });
|
|
67468
67694
|
if (!onlineFormRequest) {
|
|
67469
|
-
throw new
|
|
67695
|
+
throw new import_node_server_utils254.NotFoundError("Online form not found.");
|
|
67470
67696
|
}
|
|
67471
67697
|
const user = await getUserById(onlineFormRequest.userId.toString());
|
|
67472
67698
|
if (!user || !user._id) {
|
|
67473
|
-
throw new
|
|
67699
|
+
throw new import_node_server_utils254.NotFoundError("User not found.");
|
|
67474
67700
|
}
|
|
67475
67701
|
const userId = user._id.toString();
|
|
67476
67702
|
await NotificationService.onlineFormRequestStatusUpdated({
|
|
@@ -67487,7 +67713,7 @@ function useFormEntryRepo() {
|
|
|
67487
67713
|
try {
|
|
67488
67714
|
_id = new import_mongodb152.ObjectId(_id);
|
|
67489
67715
|
} catch (error) {
|
|
67490
|
-
throw new
|
|
67716
|
+
throw new import_node_server_utils254.BadRequestError("Invalid online form ID format.");
|
|
67491
67717
|
}
|
|
67492
67718
|
try {
|
|
67493
67719
|
const updateValue = {
|
|
@@ -67501,7 +67727,7 @@ function useFormEntryRepo() {
|
|
|
67501
67727
|
{ session }
|
|
67502
67728
|
);
|
|
67503
67729
|
if (res.modifiedCount === 0) {
|
|
67504
|
-
throw new
|
|
67730
|
+
throw new import_node_server_utils254.InternalServerError("Unable to delete online form.");
|
|
67505
67731
|
}
|
|
67506
67732
|
return res.modifiedCount;
|
|
67507
67733
|
} catch (error) {
|
|
@@ -67518,7 +67744,7 @@ function useFormEntryRepo() {
|
|
|
67518
67744
|
} catch (error) {
|
|
67519
67745
|
const isDuplicated = error.message.includes("duplicate");
|
|
67520
67746
|
if (isDuplicated) {
|
|
67521
|
-
throw new
|
|
67747
|
+
throw new import_node_server_utils254.BadRequestError("Online Form already exists.");
|
|
67522
67748
|
}
|
|
67523
67749
|
throw error;
|
|
67524
67750
|
}
|
|
@@ -67557,13 +67783,13 @@ function useFormEntryRepo() {
|
|
|
67557
67783
|
{ unitNumber: { $regex: search, $options: "i" } }
|
|
67558
67784
|
];
|
|
67559
67785
|
}
|
|
67560
|
-
const cacheKey = (0,
|
|
67786
|
+
const cacheKey = (0, import_node_server_utils254.makeCacheKey)(
|
|
67561
67787
|
online_forms_namespace_collection,
|
|
67562
67788
|
cacheOptions
|
|
67563
67789
|
);
|
|
67564
67790
|
const cachedData = await getCache(cacheKey);
|
|
67565
67791
|
if (cachedData) {
|
|
67566
|
-
|
|
67792
|
+
import_node_server_utils254.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
67567
67793
|
return cachedData;
|
|
67568
67794
|
}
|
|
67569
67795
|
try {
|
|
@@ -67574,11 +67800,11 @@ function useFormEntryRepo() {
|
|
|
67574
67800
|
{ $limit: limit }
|
|
67575
67801
|
]).toArray();
|
|
67576
67802
|
const length = await collection.countDocuments(query);
|
|
67577
|
-
const data = (0,
|
|
67803
|
+
const data = (0, import_node_server_utils254.paginate)(items, page, limit, length);
|
|
67578
67804
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
67579
|
-
|
|
67805
|
+
import_node_server_utils254.logger.info(`Cache set for key: ${cacheKey}`);
|
|
67580
67806
|
}).catch((err) => {
|
|
67581
|
-
|
|
67807
|
+
import_node_server_utils254.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
67582
67808
|
});
|
|
67583
67809
|
return data;
|
|
67584
67810
|
} catch (error) {
|
|
@@ -67598,8 +67824,8 @@ function useFormEntryRepo() {
|
|
|
67598
67824
|
}
|
|
67599
67825
|
|
|
67600
67826
|
// src/controllers/online-forms-v2.controller.ts
|
|
67601
|
-
var
|
|
67602
|
-
var
|
|
67827
|
+
var import_node_server_utils255 = require("@7365admin1/node-server-utils");
|
|
67828
|
+
var import_joi149 = __toESM(require("joi"));
|
|
67603
67829
|
var import_exceljs3 = __toESM(require("exceljs"));
|
|
67604
67830
|
var import_fs7 = __toESM(require("fs"));
|
|
67605
67831
|
function useFormEntryController() {
|
|
@@ -67625,14 +67851,14 @@ function useFormEntryController() {
|
|
|
67625
67851
|
async function uploadFormEntrys(req, res, next) {
|
|
67626
67852
|
try {
|
|
67627
67853
|
if (!req.file) {
|
|
67628
|
-
next(new
|
|
67854
|
+
next(new import_node_server_utils255.BadRequestError("Excel file is required."));
|
|
67629
67855
|
return;
|
|
67630
67856
|
}
|
|
67631
67857
|
const workbook = new import_exceljs3.default.Workbook();
|
|
67632
67858
|
await workbook.xlsx.readFile(req.file.path);
|
|
67633
67859
|
const worksheet = workbook.worksheets[0];
|
|
67634
67860
|
if (!worksheet) {
|
|
67635
|
-
next(new
|
|
67861
|
+
next(new import_node_server_utils255.BadRequestError("No worksheet found in uploaded Excel file."));
|
|
67636
67862
|
return;
|
|
67637
67863
|
}
|
|
67638
67864
|
const headerRow = worksheet.getRow(1);
|
|
@@ -67660,8 +67886,8 @@ function useFormEntryController() {
|
|
|
67660
67886
|
});
|
|
67661
67887
|
if (error) {
|
|
67662
67888
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
67663
|
-
|
|
67664
|
-
next(new
|
|
67889
|
+
import_node_server_utils255.logger.log({ level: "error", message: messages });
|
|
67890
|
+
next(new import_node_server_utils255.BadRequestError(messages));
|
|
67665
67891
|
return;
|
|
67666
67892
|
}
|
|
67667
67893
|
const result = await _add(value);
|
|
@@ -67669,25 +67895,25 @@ function useFormEntryController() {
|
|
|
67669
67895
|
import_fs7.default.unlink(req.file.path, () => {
|
|
67670
67896
|
});
|
|
67671
67897
|
} catch (error) {
|
|
67672
|
-
|
|
67898
|
+
import_node_server_utils255.logger.log({ level: "error", message: error.message });
|
|
67673
67899
|
next(error);
|
|
67674
67900
|
}
|
|
67675
67901
|
}
|
|
67676
67902
|
async function getAll(req, res, next) {
|
|
67677
67903
|
try {
|
|
67678
|
-
const schema2 =
|
|
67679
|
-
search:
|
|
67680
|
-
page:
|
|
67681
|
-
limit:
|
|
67682
|
-
status:
|
|
67683
|
-
org:
|
|
67684
|
-
site:
|
|
67904
|
+
const schema2 = import_joi149.default.object({
|
|
67905
|
+
search: import_joi149.default.string().optional().allow("", null),
|
|
67906
|
+
page: import_joi149.default.number().integer().min(1).allow("", null).default(1),
|
|
67907
|
+
limit: import_joi149.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
67908
|
+
status: import_joi149.default.string().optional().allow(null, ""),
|
|
67909
|
+
org: import_joi149.default.string().hex().optional().allow("", null),
|
|
67910
|
+
site: import_joi149.default.string().hex().optional().allow("", null)
|
|
67685
67911
|
});
|
|
67686
67912
|
const { error, value } = schema2.validate(req.query);
|
|
67687
67913
|
if (error) {
|
|
67688
67914
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
67689
|
-
|
|
67690
|
-
next(new
|
|
67915
|
+
import_node_server_utils255.logger.log({ level: "error", message: messages });
|
|
67916
|
+
next(new import_node_server_utils255.BadRequestError(messages));
|
|
67691
67917
|
return;
|
|
67692
67918
|
}
|
|
67693
67919
|
const { search, page, limit, status, org, site } = value;
|
|
@@ -67695,21 +67921,21 @@ function useFormEntryController() {
|
|
|
67695
67921
|
res.json(data);
|
|
67696
67922
|
return;
|
|
67697
67923
|
} catch (error) {
|
|
67698
|
-
|
|
67924
|
+
import_node_server_utils255.logger.log({ level: "error", message: error.message });
|
|
67699
67925
|
next(error);
|
|
67700
67926
|
return;
|
|
67701
67927
|
}
|
|
67702
67928
|
}
|
|
67703
67929
|
async function getFormEntryById(req, res, next) {
|
|
67704
67930
|
try {
|
|
67705
|
-
const schema2 =
|
|
67706
|
-
_id:
|
|
67931
|
+
const schema2 = import_joi149.default.object({
|
|
67932
|
+
_id: import_joi149.default.string().hex().length(24).required()
|
|
67707
67933
|
});
|
|
67708
67934
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
67709
67935
|
if (error) {
|
|
67710
67936
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
67711
|
-
|
|
67712
|
-
next(new
|
|
67937
|
+
import_node_server_utils255.logger.log({ level: "error", message: messages });
|
|
67938
|
+
next(new import_node_server_utils255.BadRequestError(messages));
|
|
67713
67939
|
return;
|
|
67714
67940
|
}
|
|
67715
67941
|
const { _id } = value;
|
|
@@ -67717,7 +67943,7 @@ function useFormEntryController() {
|
|
|
67717
67943
|
res.json(data);
|
|
67718
67944
|
return;
|
|
67719
67945
|
} catch (error) {
|
|
67720
|
-
|
|
67946
|
+
import_node_server_utils255.logger.log({ level: "error", message: error.message });
|
|
67721
67947
|
next(error);
|
|
67722
67948
|
return;
|
|
67723
67949
|
}
|
|
@@ -67730,8 +67956,8 @@ function useFormEntryController() {
|
|
|
67730
67956
|
});
|
|
67731
67957
|
if (error) {
|
|
67732
67958
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
67733
|
-
|
|
67734
|
-
next(new
|
|
67959
|
+
import_node_server_utils255.logger.log({ level: "error", message: messages });
|
|
67960
|
+
next(new import_node_server_utils255.BadRequestError(messages));
|
|
67735
67961
|
return;
|
|
67736
67962
|
}
|
|
67737
67963
|
const { _id, ...rest } = value;
|
|
@@ -67739,26 +67965,26 @@ function useFormEntryController() {
|
|
|
67739
67965
|
res.json({ message: "Successfully updated online form." });
|
|
67740
67966
|
return;
|
|
67741
67967
|
} catch (error) {
|
|
67742
|
-
|
|
67968
|
+
import_node_server_utils255.logger.log({ level: "error", message: error.message });
|
|
67743
67969
|
next(error);
|
|
67744
67970
|
return;
|
|
67745
67971
|
}
|
|
67746
67972
|
}
|
|
67747
67973
|
async function deleteFormEntryById(req, res, next) {
|
|
67748
67974
|
try {
|
|
67749
|
-
const validation =
|
|
67975
|
+
const validation = import_joi149.default.string().hex().required();
|
|
67750
67976
|
const _id = req.params.id;
|
|
67751
67977
|
const { error } = validation.validate(_id);
|
|
67752
67978
|
if (error) {
|
|
67753
|
-
|
|
67754
|
-
next(new
|
|
67979
|
+
import_node_server_utils255.logger.log({ level: "error", message: error.message });
|
|
67980
|
+
next(new import_node_server_utils255.BadRequestError(error.message));
|
|
67755
67981
|
return;
|
|
67756
67982
|
}
|
|
67757
67983
|
await _deleteOnlineFormById(_id);
|
|
67758
67984
|
res.json({ message: "Successfully deleted online form." });
|
|
67759
67985
|
return;
|
|
67760
67986
|
} catch (error) {
|
|
67761
|
-
|
|
67987
|
+
import_node_server_utils255.logger.log({ level: "error", message: error.message });
|
|
67762
67988
|
next(error);
|
|
67763
67989
|
return;
|
|
67764
67990
|
}
|
|
@@ -67775,8 +68001,8 @@ function useFormEntryController() {
|
|
|
67775
68001
|
});
|
|
67776
68002
|
if (error) {
|
|
67777
68003
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
67778
|
-
|
|
67779
|
-
next(new
|
|
68004
|
+
import_node_server_utils255.logger.log({ level: "error", message: messages });
|
|
68005
|
+
next(new import_node_server_utils255.BadRequestError(messages));
|
|
67780
68006
|
return;
|
|
67781
68007
|
}
|
|
67782
68008
|
try {
|
|
@@ -67784,7 +68010,7 @@ function useFormEntryController() {
|
|
|
67784
68010
|
res.status(201).json({ message: data });
|
|
67785
68011
|
return;
|
|
67786
68012
|
} catch (error2) {
|
|
67787
|
-
|
|
68013
|
+
import_node_server_utils255.logger.log({ level: "error", message: error2.message });
|
|
67788
68014
|
next(error2);
|
|
67789
68015
|
return;
|
|
67790
68016
|
}
|
|
@@ -67796,8 +68022,8 @@ function useFormEntryController() {
|
|
|
67796
68022
|
});
|
|
67797
68023
|
if (error) {
|
|
67798
68024
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
67799
|
-
|
|
67800
|
-
next(new
|
|
68025
|
+
import_node_server_utils255.logger.log({ level: "error", message: messages });
|
|
68026
|
+
next(new import_node_server_utils255.BadRequestError(messages));
|
|
67801
68027
|
return;
|
|
67802
68028
|
}
|
|
67803
68029
|
try {
|
|
@@ -67805,35 +68031,35 @@ function useFormEntryController() {
|
|
|
67805
68031
|
res.status(201).json({ message: data });
|
|
67806
68032
|
return;
|
|
67807
68033
|
} catch (error2) {
|
|
67808
|
-
|
|
68034
|
+
import_node_server_utils255.logger.log({ level: "error", message: error2.message });
|
|
67809
68035
|
next(error2);
|
|
67810
68036
|
return;
|
|
67811
68037
|
}
|
|
67812
68038
|
}
|
|
67813
68039
|
async function residentForm(req, res, next) {
|
|
67814
68040
|
try {
|
|
67815
|
-
const residentFormPayload =
|
|
67816
|
-
org:
|
|
67817
|
-
site:
|
|
67818
|
-
userId:
|
|
67819
|
-
search:
|
|
67820
|
-
page:
|
|
67821
|
-
limit:
|
|
68041
|
+
const residentFormPayload = import_joi149.default.object({
|
|
68042
|
+
org: import_joi149.default.string().hex().required(),
|
|
68043
|
+
site: import_joi149.default.string().hex().required(),
|
|
68044
|
+
userId: import_joi149.default.string().hex().required(),
|
|
68045
|
+
search: import_joi149.default.string().optional().allow("", null),
|
|
68046
|
+
page: import_joi149.default.number().integer().min(1).allow("", null).default(1),
|
|
68047
|
+
limit: import_joi149.default.number().integer().min(1).max(100).allow("", null).default(10)
|
|
67822
68048
|
});
|
|
67823
68049
|
const { error, value } = residentFormPayload.validate(req.query, {
|
|
67824
68050
|
abortEarly: true
|
|
67825
68051
|
});
|
|
67826
68052
|
if (error) {
|
|
67827
68053
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
67828
|
-
|
|
67829
|
-
next(new
|
|
68054
|
+
import_node_server_utils255.logger.log({ level: "error", message: messages });
|
|
68055
|
+
next(new import_node_server_utils255.BadRequestError(messages));
|
|
67830
68056
|
return;
|
|
67831
68057
|
}
|
|
67832
68058
|
const { site, userId, org, search, page, limit } = value;
|
|
67833
68059
|
const result = await _residentForm({ userId, site, org, search, page, limit });
|
|
67834
68060
|
res.json(result);
|
|
67835
68061
|
} catch (error) {
|
|
67836
|
-
|
|
68062
|
+
import_node_server_utils255.logger.log({ level: "error", message: error.message });
|
|
67837
68063
|
next(error);
|
|
67838
68064
|
return;
|
|
67839
68065
|
}
|
|
@@ -67851,11 +68077,11 @@ function useFormEntryController() {
|
|
|
67851
68077
|
}
|
|
67852
68078
|
|
|
67853
68079
|
// src/services/building-level.service.ts
|
|
67854
|
-
var
|
|
68080
|
+
var import_node_server_utils256 = require("@7365admin1/node-server-utils");
|
|
67855
68081
|
function useBuildingLevelService() {
|
|
67856
68082
|
const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelRepo();
|
|
67857
68083
|
async function add(value) {
|
|
67858
|
-
const session =
|
|
68084
|
+
const session = import_node_server_utils256.useAtlas.getClient()?.startSession();
|
|
67859
68085
|
try {
|
|
67860
68086
|
session?.startTransaction();
|
|
67861
68087
|
await _add(value, session);
|
|
@@ -67869,7 +68095,7 @@ function useBuildingLevelService() {
|
|
|
67869
68095
|
}
|
|
67870
68096
|
}
|
|
67871
68097
|
async function updateLevelById(_id, value) {
|
|
67872
|
-
const session =
|
|
68098
|
+
const session = import_node_server_utils256.useAtlas.getClient()?.startSession();
|
|
67873
68099
|
try {
|
|
67874
68100
|
session?.startTransaction();
|
|
67875
68101
|
await _updateLevelById(_id, value, session);
|
|
@@ -67889,8 +68115,8 @@ function useBuildingLevelService() {
|
|
|
67889
68115
|
}
|
|
67890
68116
|
|
|
67891
68117
|
// src/controllers/building-level.controller.ts
|
|
67892
|
-
var
|
|
67893
|
-
var
|
|
68118
|
+
var import_node_server_utils257 = require("@7365admin1/node-server-utils");
|
|
68119
|
+
var import_joi150 = __toESM(require("joi"));
|
|
67894
68120
|
function useBuildingLevelController() {
|
|
67895
68121
|
const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelService();
|
|
67896
68122
|
const {
|
|
@@ -67907,8 +68133,8 @@ function useBuildingLevelController() {
|
|
|
67907
68133
|
});
|
|
67908
68134
|
if (error) {
|
|
67909
68135
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
67910
|
-
|
|
67911
|
-
next(new
|
|
68136
|
+
import_node_server_utils257.logger.log({ level: "error", message: messages });
|
|
68137
|
+
next(new import_node_server_utils257.BadRequestError(messages));
|
|
67912
68138
|
return;
|
|
67913
68139
|
}
|
|
67914
68140
|
const result = await _add(value);
|
|
@@ -67919,20 +68145,20 @@ function useBuildingLevelController() {
|
|
|
67919
68145
|
}
|
|
67920
68146
|
async function getAll(req, res, next) {
|
|
67921
68147
|
try {
|
|
67922
|
-
const validation =
|
|
67923
|
-
page:
|
|
67924
|
-
limit:
|
|
67925
|
-
search:
|
|
67926
|
-
site:
|
|
67927
|
-
status:
|
|
68148
|
+
const validation = import_joi150.default.object({
|
|
68149
|
+
page: import_joi150.default.number().min(1).optional().default(1),
|
|
68150
|
+
limit: import_joi150.default.number().min(1).optional().default(20),
|
|
68151
|
+
search: import_joi150.default.string().optional().allow("", null),
|
|
68152
|
+
site: import_joi150.default.string().hex().length(24).optional().allow("", null),
|
|
68153
|
+
status: import_joi150.default.string().valid(...Object.values(BuildingLevelStatus)).default("active" /* ACTIVE */)
|
|
67928
68154
|
});
|
|
67929
68155
|
const { error, value } = validation.validate(req.query, {
|
|
67930
68156
|
abortEarly: false
|
|
67931
68157
|
});
|
|
67932
68158
|
if (error) {
|
|
67933
68159
|
const messages = error.details.map((d) => d.message);
|
|
67934
|
-
|
|
67935
|
-
next(new
|
|
68160
|
+
import_node_server_utils257.logger.log({ level: "error", message: messages.join(", ") });
|
|
68161
|
+
next(new import_node_server_utils257.BadRequestError(messages.join(", ")));
|
|
67936
68162
|
return;
|
|
67937
68163
|
}
|
|
67938
68164
|
const { page, limit, status, site, search } = value;
|
|
@@ -67951,14 +68177,14 @@ function useBuildingLevelController() {
|
|
|
67951
68177
|
}
|
|
67952
68178
|
async function getById(req, res, next) {
|
|
67953
68179
|
try {
|
|
67954
|
-
const schema2 =
|
|
67955
|
-
id:
|
|
68180
|
+
const schema2 = import_joi150.default.object({
|
|
68181
|
+
id: import_joi150.default.string().hex().length(24).required()
|
|
67956
68182
|
});
|
|
67957
68183
|
const { error, value } = schema2.validate({ id: req.params.id });
|
|
67958
68184
|
if (error) {
|
|
67959
68185
|
const messages = error.details.map((d) => d.message);
|
|
67960
|
-
|
|
67961
|
-
next(new
|
|
68186
|
+
import_node_server_utils257.logger.log({ level: "error", message: messages.join(", ") });
|
|
68187
|
+
next(new import_node_server_utils257.BadRequestError(messages.join(", ")));
|
|
67962
68188
|
return;
|
|
67963
68189
|
}
|
|
67964
68190
|
const { id } = value;
|
|
@@ -67977,8 +68203,8 @@ function useBuildingLevelController() {
|
|
|
67977
68203
|
});
|
|
67978
68204
|
if (error) {
|
|
67979
68205
|
const messages = error.details.map((d) => d.message);
|
|
67980
|
-
|
|
67981
|
-
next(new
|
|
68206
|
+
import_node_server_utils257.logger.log({ level: "error", message: messages.join(", ") });
|
|
68207
|
+
next(new import_node_server_utils257.BadRequestError(messages.join(", ")));
|
|
67982
68208
|
return;
|
|
67983
68209
|
}
|
|
67984
68210
|
const { _id, ...rest } = value;
|
|
@@ -67990,14 +68216,14 @@ function useBuildingLevelController() {
|
|
|
67990
68216
|
}
|
|
67991
68217
|
async function deleteById(req, res, next) {
|
|
67992
68218
|
try {
|
|
67993
|
-
const schema2 =
|
|
67994
|
-
id:
|
|
68219
|
+
const schema2 = import_joi150.default.object({
|
|
68220
|
+
id: import_joi150.default.string().hex().required()
|
|
67995
68221
|
});
|
|
67996
68222
|
const { error, value } = schema2.validate({ id: req.params.id });
|
|
67997
68223
|
if (error) {
|
|
67998
68224
|
const messages = error.details.map((d) => d.message);
|
|
67999
|
-
|
|
68000
|
-
next(new
|
|
68225
|
+
import_node_server_utils257.logger.log({ level: "error", message: messages.join(", ") });
|
|
68226
|
+
next(new import_node_server_utils257.BadRequestError(messages.join(", ")));
|
|
68001
68227
|
return;
|
|
68002
68228
|
}
|
|
68003
68229
|
const { id } = value;
|
|
@@ -68010,19 +68236,19 @@ function useBuildingLevelController() {
|
|
|
68010
68236
|
}
|
|
68011
68237
|
async function batchUpdateByIds(req, res, next) {
|
|
68012
68238
|
try {
|
|
68013
|
-
const schema2 =
|
|
68014
|
-
|
|
68015
|
-
_id:
|
|
68016
|
-
value:
|
|
68017
|
-
name:
|
|
68239
|
+
const schema2 = import_joi150.default.array().items(
|
|
68240
|
+
import_joi150.default.object({
|
|
68241
|
+
_id: import_joi150.default.string().hex().length(24).required(),
|
|
68242
|
+
value: import_joi150.default.object({
|
|
68243
|
+
name: import_joi150.default.string().optional().allow("", null)
|
|
68018
68244
|
}).required()
|
|
68019
68245
|
})
|
|
68020
68246
|
);
|
|
68021
68247
|
const { error, value } = schema2.validate(req.body);
|
|
68022
68248
|
if (error) {
|
|
68023
68249
|
const messages = error.details.map((d) => d.message);
|
|
68024
|
-
|
|
68025
|
-
next(new
|
|
68250
|
+
import_node_server_utils257.logger.log({ level: "error", message: messages.join(", ") });
|
|
68251
|
+
next(new import_node_server_utils257.BadRequestError(messages.join(", ")));
|
|
68026
68252
|
return;
|
|
68027
68253
|
}
|
|
68028
68254
|
const updates = value.map((item) => ({
|
|
@@ -68037,9 +68263,9 @@ function useBuildingLevelController() {
|
|
|
68037
68263
|
}
|
|
68038
68264
|
async function getBuildingLevelList(req, res, next) {
|
|
68039
68265
|
try {
|
|
68040
|
-
const schema2 =
|
|
68041
|
-
site:
|
|
68042
|
-
block:
|
|
68266
|
+
const schema2 = import_joi150.default.object({
|
|
68267
|
+
site: import_joi150.default.string().hex().length(24).required(),
|
|
68268
|
+
block: import_joi150.default.string().hex().length(24).required()
|
|
68043
68269
|
});
|
|
68044
68270
|
const { error, value } = schema2.validate({
|
|
68045
68271
|
site: req.params.siteId,
|
|
@@ -68047,8 +68273,8 @@ function useBuildingLevelController() {
|
|
|
68047
68273
|
});
|
|
68048
68274
|
if (error) {
|
|
68049
68275
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
68050
|
-
|
|
68051
|
-
next(new
|
|
68276
|
+
import_node_server_utils257.logger.log({ level: "error", message: messages });
|
|
68277
|
+
next(new import_node_server_utils257.BadRequestError(messages));
|
|
68052
68278
|
return;
|
|
68053
68279
|
}
|
|
68054
68280
|
const { site, block } = value;
|
|
@@ -68071,9 +68297,9 @@ function useBuildingLevelController() {
|
|
|
68071
68297
|
}
|
|
68072
68298
|
|
|
68073
68299
|
// src/models/hid-amico.model.ts
|
|
68074
|
-
var
|
|
68300
|
+
var import_node_server_utils258 = require("@7365admin1/node-server-utils");
|
|
68075
68301
|
var import_mongodb153 = require("mongodb");
|
|
68076
|
-
var
|
|
68302
|
+
var import_joi151 = __toESM(require("joi"));
|
|
68077
68303
|
function canReadObjectId(value) {
|
|
68078
68304
|
if (value instanceof import_mongodb153.ObjectId)
|
|
68079
68305
|
return true;
|
|
@@ -68111,161 +68337,161 @@ function toObjectId23(value, label = "ID") {
|
|
|
68111
68337
|
return toObjectId23(text, label);
|
|
68112
68338
|
}
|
|
68113
68339
|
}
|
|
68114
|
-
throw new
|
|
68340
|
+
throw new import_node_server_utils258.BadRequestError(`Invalid ${label} format`);
|
|
68115
68341
|
}
|
|
68116
|
-
var objectIdSchema2 =
|
|
68342
|
+
var objectIdSchema2 = import_joi151.default.custom((value, helpers) => canReadObjectId(value) ? value : helpers.error("any.invalid"), "ObjectId").messages({
|
|
68117
68343
|
"any.invalid": "{{#label}} must be a valid ObjectId"
|
|
68118
68344
|
});
|
|
68119
|
-
var schemaHidAmicoReader =
|
|
68345
|
+
var schemaHidAmicoReader = import_joi151.default.object({
|
|
68120
68346
|
_id: objectIdSchema2.optional(),
|
|
68121
68347
|
site: objectIdSchema2.required(),
|
|
68122
|
-
name:
|
|
68123
|
-
baseUrl:
|
|
68124
|
-
username:
|
|
68125
|
-
password:
|
|
68126
|
-
location:
|
|
68127
|
-
deviceId:
|
|
68128
|
-
monitorPath:
|
|
68129
|
-
enabled:
|
|
68130
|
-
status:
|
|
68131
|
-
lastSeenAt:
|
|
68132
|
-
lastSyncAt:
|
|
68133
|
-
lastSyncStatus:
|
|
68134
|
-
lastSyncMessage:
|
|
68135
|
-
createdAt:
|
|
68136
|
-
updatedAt:
|
|
68137
|
-
deletedAt:
|
|
68348
|
+
name: import_joi151.default.string().trim().required(),
|
|
68349
|
+
baseUrl: import_joi151.default.string().uri({ scheme: ["http", "https"] }).required(),
|
|
68350
|
+
username: import_joi151.default.string().trim().required(),
|
|
68351
|
+
password: import_joi151.default.string().required(),
|
|
68352
|
+
location: import_joi151.default.string().allow(null, "").optional(),
|
|
68353
|
+
deviceId: import_joi151.default.string().allow(null, "").optional(),
|
|
68354
|
+
monitorPath: import_joi151.default.string().allow(null, "").optional(),
|
|
68355
|
+
enabled: import_joi151.default.boolean().optional(),
|
|
68356
|
+
status: import_joi151.default.string().valid("active", "inactive", "deleted", "offline").optional(),
|
|
68357
|
+
lastSeenAt: import_joi151.default.date().optional(),
|
|
68358
|
+
lastSyncAt: import_joi151.default.date().optional(),
|
|
68359
|
+
lastSyncStatus: import_joi151.default.string().valid("idle", "running", "completed", "failed").optional(),
|
|
68360
|
+
lastSyncMessage: import_joi151.default.string().allow(null, "").optional(),
|
|
68361
|
+
createdAt: import_joi151.default.date().optional(),
|
|
68362
|
+
updatedAt: import_joi151.default.date().optional(),
|
|
68363
|
+
deletedAt: import_joi151.default.date().optional()
|
|
68138
68364
|
});
|
|
68139
|
-
var schemaUpdateHidAmicoReader =
|
|
68365
|
+
var schemaUpdateHidAmicoReader = import_joi151.default.object({
|
|
68140
68366
|
site: objectIdSchema2.optional(),
|
|
68141
|
-
name:
|
|
68142
|
-
baseUrl:
|
|
68143
|
-
username:
|
|
68144
|
-
password:
|
|
68145
|
-
location:
|
|
68146
|
-
deviceId:
|
|
68147
|
-
monitorPath:
|
|
68148
|
-
enabled:
|
|
68149
|
-
status:
|
|
68150
|
-
lastSeenAt:
|
|
68151
|
-
lastSyncAt:
|
|
68152
|
-
lastSyncStatus:
|
|
68153
|
-
lastSyncMessage:
|
|
68154
|
-
deletedAt:
|
|
68367
|
+
name: import_joi151.default.string().trim().optional(),
|
|
68368
|
+
baseUrl: import_joi151.default.string().uri({ scheme: ["http", "https"] }).optional(),
|
|
68369
|
+
username: import_joi151.default.string().trim().optional(),
|
|
68370
|
+
password: import_joi151.default.string().allow(null, "").optional(),
|
|
68371
|
+
location: import_joi151.default.string().allow(null, "").optional(),
|
|
68372
|
+
deviceId: import_joi151.default.string().allow(null, "").optional(),
|
|
68373
|
+
monitorPath: import_joi151.default.string().allow(null, "").optional(),
|
|
68374
|
+
enabled: import_joi151.default.boolean().optional(),
|
|
68375
|
+
status: import_joi151.default.string().valid("active", "inactive", "deleted", "offline").optional(),
|
|
68376
|
+
lastSeenAt: import_joi151.default.date().optional(),
|
|
68377
|
+
lastSyncAt: import_joi151.default.date().optional(),
|
|
68378
|
+
lastSyncStatus: import_joi151.default.string().valid("idle", "running", "completed", "failed").optional(),
|
|
68379
|
+
lastSyncMessage: import_joi151.default.string().allow(null, "").optional(),
|
|
68380
|
+
deletedAt: import_joi151.default.date().optional()
|
|
68155
68381
|
});
|
|
68156
|
-
var schemaHidAmicoEvent =
|
|
68382
|
+
var schemaHidAmicoEvent = import_joi151.default.object({
|
|
68157
68383
|
_id: objectIdSchema2.optional(),
|
|
68158
68384
|
reader: objectIdSchema2.required(),
|
|
68159
68385
|
site: objectIdSchema2.optional(),
|
|
68160
|
-
type:
|
|
68161
|
-
payload:
|
|
68162
|
-
status:
|
|
68163
|
-
createdAt:
|
|
68386
|
+
type: import_joi151.default.string().required(),
|
|
68387
|
+
payload: import_joi151.default.object().unknown(true).required(),
|
|
68388
|
+
status: import_joi151.default.string().valid("received", "processed", "failed").optional(),
|
|
68389
|
+
createdAt: import_joi151.default.date().optional()
|
|
68164
68390
|
});
|
|
68165
|
-
var schemaHidAmicoIdentity =
|
|
68391
|
+
var schemaHidAmicoIdentity = import_joi151.default.object({
|
|
68166
68392
|
_id: objectIdSchema2.optional(),
|
|
68167
68393
|
reader: objectIdSchema2.required(),
|
|
68168
68394
|
site: objectIdSchema2.required(),
|
|
68169
|
-
hidUserId:
|
|
68170
|
-
registration:
|
|
68171
|
-
cardNo:
|
|
68395
|
+
hidUserId: import_joi151.default.alternatives(import_joi151.default.string(), import_joi151.default.number()).optional().allow(null, ""),
|
|
68396
|
+
registration: import_joi151.default.string().optional().allow(null, ""),
|
|
68397
|
+
cardNo: import_joi151.default.string().optional().allow(null, ""),
|
|
68172
68398
|
person: objectIdSchema2.optional().allow(null, ""),
|
|
68173
68399
|
user: objectIdSchema2.optional().allow(null, ""),
|
|
68174
68400
|
member: objectIdSchema2.optional().allow(null, ""),
|
|
68175
68401
|
visitor: objectIdSchema2.optional().allow(null, ""),
|
|
68176
|
-
type:
|
|
68177
|
-
status:
|
|
68178
|
-
metadata:
|
|
68179
|
-
createdAt:
|
|
68180
|
-
updatedAt:
|
|
68181
|
-
deletedAt:
|
|
68402
|
+
type: import_joi151.default.string().valid("resident", "staff", "contractor", "visitor", "admin", "unknown").required(),
|
|
68403
|
+
status: import_joi151.default.string().valid("active", "inactive", "deleted").optional(),
|
|
68404
|
+
metadata: import_joi151.default.object().unknown(true).optional(),
|
|
68405
|
+
createdAt: import_joi151.default.date().optional(),
|
|
68406
|
+
updatedAt: import_joi151.default.date().optional(),
|
|
68407
|
+
deletedAt: import_joi151.default.date().optional()
|
|
68182
68408
|
}).or("hidUserId", "registration", "cardNo");
|
|
68183
|
-
var schemaCreateHidAmicoIdentity =
|
|
68409
|
+
var schemaCreateHidAmicoIdentity = import_joi151.default.object({
|
|
68184
68410
|
site: objectIdSchema2.optional(),
|
|
68185
|
-
hidUserId:
|
|
68186
|
-
registration:
|
|
68187
|
-
cardNo:
|
|
68411
|
+
hidUserId: import_joi151.default.alternatives(import_joi151.default.string(), import_joi151.default.number()).optional().allow(null, ""),
|
|
68412
|
+
registration: import_joi151.default.string().optional().allow(null, ""),
|
|
68413
|
+
cardNo: import_joi151.default.string().optional().allow(null, ""),
|
|
68188
68414
|
person: objectIdSchema2.optional().allow(null, ""),
|
|
68189
68415
|
user: objectIdSchema2.optional().allow(null, ""),
|
|
68190
68416
|
member: objectIdSchema2.optional().allow(null, ""),
|
|
68191
68417
|
visitor: objectIdSchema2.optional().allow(null, ""),
|
|
68192
|
-
type:
|
|
68193
|
-
status:
|
|
68194
|
-
metadata:
|
|
68418
|
+
type: import_joi151.default.string().valid("resident", "staff", "contractor", "visitor", "admin", "unknown").required(),
|
|
68419
|
+
status: import_joi151.default.string().valid("active", "inactive", "deleted").optional(),
|
|
68420
|
+
metadata: import_joi151.default.object().unknown(true).optional()
|
|
68195
68421
|
}).or("hidUserId", "registration", "cardNo");
|
|
68196
|
-
var schemaUpdateHidAmicoIdentity =
|
|
68197
|
-
hidUserId:
|
|
68198
|
-
registration:
|
|
68199
|
-
cardNo:
|
|
68422
|
+
var schemaUpdateHidAmicoIdentity = import_joi151.default.object({
|
|
68423
|
+
hidUserId: import_joi151.default.alternatives(import_joi151.default.string(), import_joi151.default.number()).optional().allow(null, ""),
|
|
68424
|
+
registration: import_joi151.default.string().optional().allow(null, ""),
|
|
68425
|
+
cardNo: import_joi151.default.string().optional().allow(null, ""),
|
|
68200
68426
|
person: objectIdSchema2.optional().allow(null, ""),
|
|
68201
68427
|
user: objectIdSchema2.optional().allow(null, ""),
|
|
68202
68428
|
member: objectIdSchema2.optional().allow(null, ""),
|
|
68203
68429
|
visitor: objectIdSchema2.optional().allow(null, ""),
|
|
68204
|
-
type:
|
|
68205
|
-
status:
|
|
68206
|
-
metadata:
|
|
68207
|
-
deletedAt:
|
|
68430
|
+
type: import_joi151.default.string().valid("resident", "staff", "contractor", "visitor", "admin", "unknown").optional(),
|
|
68431
|
+
status: import_joi151.default.string().valid("active", "inactive", "deleted").optional(),
|
|
68432
|
+
metadata: import_joi151.default.object().unknown(true).optional(),
|
|
68433
|
+
deletedAt: import_joi151.default.date().optional()
|
|
68208
68434
|
});
|
|
68209
|
-
var schemaHidAmicoReaderIdParams =
|
|
68210
|
-
readerId:
|
|
68435
|
+
var schemaHidAmicoReaderIdParams = import_joi151.default.object({
|
|
68436
|
+
readerId: import_joi151.default.string().hex().length(24).required()
|
|
68211
68437
|
});
|
|
68212
|
-
var schemaHidAmicoUserImageParams =
|
|
68213
|
-
readerId:
|
|
68214
|
-
hidUserId:
|
|
68438
|
+
var schemaHidAmicoUserImageParams = import_joi151.default.object({
|
|
68439
|
+
readerId: import_joi151.default.string().hex().length(24).required(),
|
|
68440
|
+
hidUserId: import_joi151.default.alternatives().try(import_joi151.default.string(), import_joi151.default.number()).required()
|
|
68215
68441
|
});
|
|
68216
|
-
var schemaHidAmicoIdentityIdParams =
|
|
68217
|
-
identityId:
|
|
68442
|
+
var schemaHidAmicoIdentityIdParams = import_joi151.default.object({
|
|
68443
|
+
identityId: import_joi151.default.string().hex().length(24).required()
|
|
68218
68444
|
});
|
|
68219
|
-
var schemaHidAmicoReaderListQuery =
|
|
68220
|
-
site:
|
|
68221
|
-
page:
|
|
68222
|
-
limit:
|
|
68445
|
+
var schemaHidAmicoReaderListQuery = import_joi151.default.object({
|
|
68446
|
+
site: import_joi151.default.string().hex().length(24).optional(),
|
|
68447
|
+
page: import_joi151.default.number().min(1).optional(),
|
|
68448
|
+
limit: import_joi151.default.number().min(1).optional()
|
|
68223
68449
|
});
|
|
68224
|
-
var schemaHidAmicoLogQuery =
|
|
68225
|
-
page:
|
|
68226
|
-
limit:
|
|
68227
|
-
type:
|
|
68450
|
+
var schemaHidAmicoLogQuery = import_joi151.default.object({
|
|
68451
|
+
page: import_joi151.default.number().min(1).optional(),
|
|
68452
|
+
limit: import_joi151.default.number().min(1).optional(),
|
|
68453
|
+
type: import_joi151.default.string().optional()
|
|
68228
68454
|
});
|
|
68229
|
-
var schemaHidAmicoIdentityQuery =
|
|
68230
|
-
page:
|
|
68231
|
-
limit:
|
|
68232
|
-
type:
|
|
68233
|
-
status:
|
|
68234
|
-
search:
|
|
68455
|
+
var schemaHidAmicoIdentityQuery = import_joi151.default.object({
|
|
68456
|
+
page: import_joi151.default.number().min(1).optional(),
|
|
68457
|
+
limit: import_joi151.default.number().min(1).optional(),
|
|
68458
|
+
type: import_joi151.default.string().valid("resident", "staff", "contractor", "visitor", "admin", "unknown").optional(),
|
|
68459
|
+
status: import_joi151.default.string().valid("active", "inactive", "deleted").optional(),
|
|
68460
|
+
search: import_joi151.default.string().allow("").optional()
|
|
68235
68461
|
});
|
|
68236
|
-
var schemaHidAmicoSync =
|
|
68237
|
-
objects:
|
|
68238
|
-
|
|
68239
|
-
object:
|
|
68240
|
-
values:
|
|
68462
|
+
var schemaHidAmicoSync = import_joi151.default.object({
|
|
68463
|
+
objects: import_joi151.default.array().items(
|
|
68464
|
+
import_joi151.default.object({
|
|
68465
|
+
object: import_joi151.default.string().required(),
|
|
68466
|
+
values: import_joi151.default.array().items(import_joi151.default.object().unknown(true)).required()
|
|
68241
68467
|
}).unknown(true)
|
|
68242
68468
|
).optional(),
|
|
68243
|
-
users:
|
|
68244
|
-
cards:
|
|
68245
|
-
qrcodes:
|
|
68246
|
-
pins:
|
|
68469
|
+
users: import_joi151.default.array().items(import_joi151.default.object().unknown(true)).optional(),
|
|
68470
|
+
cards: import_joi151.default.array().items(import_joi151.default.object().unknown(true)).optional(),
|
|
68471
|
+
qrcodes: import_joi151.default.array().items(import_joi151.default.object().unknown(true)).optional(),
|
|
68472
|
+
pins: import_joi151.default.array().items(import_joi151.default.object().unknown(true)).optional()
|
|
68247
68473
|
}).unknown(true);
|
|
68248
|
-
var schemaHidAmicoExecuteActions =
|
|
68249
|
-
actions:
|
|
68474
|
+
var schemaHidAmicoExecuteActions = import_joi151.default.object({
|
|
68475
|
+
actions: import_joi151.default.array().items(import_joi151.default.object().unknown(true)).min(1).required()
|
|
68250
68476
|
}).unknown(true);
|
|
68251
|
-
var schemaHidAmicoConfiguration =
|
|
68252
|
-
var schemaHidAmicoSetConfiguration =
|
|
68253
|
-
var schemaHidAmicoObjectOperation =
|
|
68254
|
-
operation:
|
|
68255
|
-
object:
|
|
68256
|
-
values:
|
|
68257
|
-
|
|
68258
|
-
|
|
68477
|
+
var schemaHidAmicoConfiguration = import_joi151.default.object().pattern(import_joi151.default.string(), import_joi151.default.array().items(import_joi151.default.string())).min(1).unknown(true);
|
|
68478
|
+
var schemaHidAmicoSetConfiguration = import_joi151.default.object().unknown(true);
|
|
68479
|
+
var schemaHidAmicoObjectOperation = import_joi151.default.object({
|
|
68480
|
+
operation: import_joi151.default.string().valid("load", "create", "modify", "destroy").required(),
|
|
68481
|
+
object: import_joi151.default.string().required(),
|
|
68482
|
+
values: import_joi151.default.alternatives().try(
|
|
68483
|
+
import_joi151.default.array().items(import_joi151.default.object().unknown(true)),
|
|
68484
|
+
import_joi151.default.object().unknown(true)
|
|
68259
68485
|
).optional(),
|
|
68260
|
-
where:
|
|
68261
|
-
fields:
|
|
68262
|
-
order:
|
|
68263
|
-
limit:
|
|
68264
|
-
offset:
|
|
68486
|
+
where: import_joi151.default.object().unknown(true).optional(),
|
|
68487
|
+
fields: import_joi151.default.array().items(import_joi151.default.string()).optional(),
|
|
68488
|
+
order: import_joi151.default.array().items(import_joi151.default.string()).optional(),
|
|
68489
|
+
limit: import_joi151.default.number().integer().min(1).optional(),
|
|
68490
|
+
offset: import_joi151.default.number().integer().min(0).optional()
|
|
68265
68491
|
}).unknown(true);
|
|
68266
|
-
var schemaHidAmicoNotificationParams =
|
|
68267
|
-
readerId:
|
|
68268
|
-
type:
|
|
68492
|
+
var schemaHidAmicoNotificationParams = import_joi151.default.object({
|
|
68493
|
+
readerId: import_joi151.default.string().hex().length(24).required(),
|
|
68494
|
+
type: import_joi151.default.string().valid(
|
|
68269
68495
|
"dao",
|
|
68270
68496
|
"template",
|
|
68271
68497
|
"user_image",
|
|
@@ -68283,8 +68509,8 @@ var schemaHidAmicoNotificationParams = import_joi150.default.object({
|
|
|
68283
68509
|
function MHidAmicoReader(value) {
|
|
68284
68510
|
const { error } = schemaHidAmicoReader.validate(value);
|
|
68285
68511
|
if (error) {
|
|
68286
|
-
|
|
68287
|
-
throw new
|
|
68512
|
+
import_node_server_utils258.logger.info(`HID Amico reader: ${error.message}`);
|
|
68513
|
+
throw new import_node_server_utils258.BadRequestError(error.message);
|
|
68288
68514
|
}
|
|
68289
68515
|
return {
|
|
68290
68516
|
_id: value._id ? toObjectId23(value._id, "reader ID") : new import_mongodb153.ObjectId(),
|
|
@@ -68310,8 +68536,8 @@ function MHidAmicoReader(value) {
|
|
|
68310
68536
|
function MHidAmicoEvent(value) {
|
|
68311
68537
|
const { error } = schemaHidAmicoEvent.validate(value);
|
|
68312
68538
|
if (error) {
|
|
68313
|
-
|
|
68314
|
-
throw new
|
|
68539
|
+
import_node_server_utils258.logger.info(`HID Amico event: ${error.message}`);
|
|
68540
|
+
throw new import_node_server_utils258.BadRequestError(error.message);
|
|
68315
68541
|
}
|
|
68316
68542
|
return {
|
|
68317
68543
|
_id: value._id ? toObjectId23(value._id, "event ID") : new import_mongodb153.ObjectId(),
|
|
@@ -68329,8 +68555,8 @@ function optionalObjectId(value) {
|
|
|
68329
68555
|
function MHidAmicoIdentity(value) {
|
|
68330
68556
|
const { error } = schemaHidAmicoIdentity.validate(value);
|
|
68331
68557
|
if (error) {
|
|
68332
|
-
|
|
68333
|
-
throw new
|
|
68558
|
+
import_node_server_utils258.logger.info(`HID Amico identity: ${error.message}`);
|
|
68559
|
+
throw new import_node_server_utils258.BadRequestError(error.message);
|
|
68334
68560
|
}
|
|
68335
68561
|
return {
|
|
68336
68562
|
_id: value._id ? toObjectId23(value._id, "identity ID") : new import_mongodb153.ObjectId(),
|
|
@@ -68353,13 +68579,13 @@ function MHidAmicoIdentity(value) {
|
|
|
68353
68579
|
}
|
|
68354
68580
|
|
|
68355
68581
|
// src/repositories/hid-amico.repo.ts
|
|
68356
|
-
var
|
|
68582
|
+
var import_node_server_utils259 = require("@7365admin1/node-server-utils");
|
|
68357
68583
|
var import_mongodb154 = require("mongodb");
|
|
68358
68584
|
function useHidAmicoRepo() {
|
|
68359
68585
|
function db() {
|
|
68360
|
-
const instance =
|
|
68586
|
+
const instance = import_node_server_utils259.useAtlas.getDb();
|
|
68361
68587
|
if (!instance) {
|
|
68362
|
-
throw new
|
|
68588
|
+
throw new import_node_server_utils259.InternalServerError("Unable to connect to server.");
|
|
68363
68589
|
}
|
|
68364
68590
|
return instance;
|
|
68365
68591
|
}
|
|
@@ -68376,7 +68602,7 @@ function useHidAmicoRepo() {
|
|
|
68376
68602
|
try {
|
|
68377
68603
|
return new import_mongodb154.ObjectId(id);
|
|
68378
68604
|
} catch {
|
|
68379
|
-
throw new
|
|
68605
|
+
throw new import_node_server_utils259.BadRequestError(`Invalid ${label} format`);
|
|
68380
68606
|
}
|
|
68381
68607
|
}
|
|
68382
68608
|
function hideSecret(reader) {
|
|
@@ -68427,7 +68653,7 @@ function useHidAmicoRepo() {
|
|
|
68427
68653
|
]);
|
|
68428
68654
|
return "HID Amico indexes created.";
|
|
68429
68655
|
} catch (error) {
|
|
68430
|
-
|
|
68656
|
+
import_node_server_utils259.logger.error(error.message);
|
|
68431
68657
|
throw new Error("Failed to create HID Amico indexes.");
|
|
68432
68658
|
}
|
|
68433
68659
|
}
|
|
@@ -68438,7 +68664,7 @@ function useHidAmicoRepo() {
|
|
|
68438
68664
|
return hideSecret(doc);
|
|
68439
68665
|
} catch (error) {
|
|
68440
68666
|
if (error.message?.includes("duplicate")) {
|
|
68441
|
-
throw new
|
|
68667
|
+
throw new import_node_server_utils259.BadRequestError("HID Amico reader already exists for this site and URL.");
|
|
68442
68668
|
}
|
|
68443
68669
|
throw error;
|
|
68444
68670
|
}
|
|
@@ -68452,7 +68678,7 @@ function useHidAmicoRepo() {
|
|
|
68452
68678
|
}
|
|
68453
68679
|
const items = await readers().find(query).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
|
|
68454
68680
|
const total = await readers().countDocuments(query);
|
|
68455
|
-
return (0,
|
|
68681
|
+
return (0, import_node_server_utils259.paginate)(items.map(hideSecret), page, limit, total);
|
|
68456
68682
|
}
|
|
68457
68683
|
async function getById(id, options = {}) {
|
|
68458
68684
|
const _id = toId(id, "reader ID");
|
|
@@ -68460,14 +68686,14 @@ function useHidAmicoRepo() {
|
|
|
68460
68686
|
{ _id, status: { $ne: "deleted" } }
|
|
68461
68687
|
);
|
|
68462
68688
|
if (!reader) {
|
|
68463
|
-
throw new
|
|
68689
|
+
throw new import_node_server_utils259.BadRequestError("HID Amico reader not found.");
|
|
68464
68690
|
}
|
|
68465
68691
|
return options.includePassword ? reader : hideSecret(reader);
|
|
68466
68692
|
}
|
|
68467
68693
|
async function updateById(id, value, session) {
|
|
68468
68694
|
const { error } = schemaUpdateHidAmicoReader.validate(value);
|
|
68469
68695
|
if (error) {
|
|
68470
|
-
throw new
|
|
68696
|
+
throw new import_node_server_utils259.BadRequestError(error.message);
|
|
68471
68697
|
}
|
|
68472
68698
|
const _id = toId(id, "reader ID");
|
|
68473
68699
|
const payload = {
|
|
@@ -68486,7 +68712,7 @@ function useHidAmicoRepo() {
|
|
|
68486
68712
|
{ returnDocument: "after", session }
|
|
68487
68713
|
);
|
|
68488
68714
|
if (!updated) {
|
|
68489
|
-
throw new
|
|
68715
|
+
throw new import_node_server_utils259.BadRequestError("HID Amico reader not found.");
|
|
68490
68716
|
}
|
|
68491
68717
|
return hideSecret(updated);
|
|
68492
68718
|
}
|
|
@@ -68515,7 +68741,7 @@ function useHidAmicoRepo() {
|
|
|
68515
68741
|
}
|
|
68516
68742
|
const items = await events().find(query).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
|
|
68517
68743
|
const total = await events().countDocuments(query);
|
|
68518
|
-
return (0,
|
|
68744
|
+
return (0, import_node_server_utils259.paginate)(items, page, limit, total);
|
|
68519
68745
|
}
|
|
68520
68746
|
async function addIdentity(value, session) {
|
|
68521
68747
|
try {
|
|
@@ -68527,16 +68753,16 @@ function useHidAmicoRepo() {
|
|
|
68527
68753
|
cardNo: identity.cardNo
|
|
68528
68754
|
});
|
|
68529
68755
|
if (existing) {
|
|
68530
|
-
throw new
|
|
68756
|
+
throw new import_node_server_utils259.BadRequestError("HID Amico identity already exists for this reader.");
|
|
68531
68757
|
}
|
|
68532
68758
|
await identities().insertOne(identity, { session });
|
|
68533
68759
|
return identity;
|
|
68534
68760
|
} catch (error) {
|
|
68535
|
-
if (error instanceof
|
|
68761
|
+
if (error instanceof import_node_server_utils259.BadRequestError) {
|
|
68536
68762
|
throw error;
|
|
68537
68763
|
}
|
|
68538
68764
|
if (error.message?.includes("duplicate")) {
|
|
68539
|
-
throw new
|
|
68765
|
+
throw new import_node_server_utils259.BadRequestError("HID Amico identity already exists for this reader.");
|
|
68540
68766
|
}
|
|
68541
68767
|
throw error;
|
|
68542
68768
|
}
|
|
@@ -68561,12 +68787,12 @@ function useHidAmicoRepo() {
|
|
|
68561
68787
|
}
|
|
68562
68788
|
const items = await identities().find(query).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
|
|
68563
68789
|
const total = await identities().countDocuments(query);
|
|
68564
|
-
return (0,
|
|
68790
|
+
return (0, import_node_server_utils259.paginate)(items, page, limit, total);
|
|
68565
68791
|
}
|
|
68566
68792
|
async function updateIdentity(id, value, session) {
|
|
68567
68793
|
const { error } = schemaUpdateHidAmicoIdentity.validate(value);
|
|
68568
68794
|
if (error) {
|
|
68569
|
-
throw new
|
|
68795
|
+
throw new import_node_server_utils259.BadRequestError(error.message);
|
|
68570
68796
|
}
|
|
68571
68797
|
const payload = {
|
|
68572
68798
|
...value,
|
|
@@ -68594,7 +68820,7 @@ function useHidAmicoRepo() {
|
|
|
68594
68820
|
{ returnDocument: "after", session }
|
|
68595
68821
|
);
|
|
68596
68822
|
if (!updated) {
|
|
68597
|
-
throw new
|
|
68823
|
+
throw new import_node_server_utils259.BadRequestError("HID Amico identity not found.");
|
|
68598
68824
|
}
|
|
68599
68825
|
return updated;
|
|
68600
68826
|
}
|
|
@@ -68651,7 +68877,7 @@ function useHidAmicoRepo() {
|
|
|
68651
68877
|
// src/services/hid-amico.service.ts
|
|
68652
68878
|
var import_crypto3 = __toESM(require("crypto"));
|
|
68653
68879
|
var import_axios4 = __toESM(require("axios"));
|
|
68654
|
-
var
|
|
68880
|
+
var import_node_server_utils260 = require("@7365admin1/node-server-utils");
|
|
68655
68881
|
var PASSWORD_PREFIX = "v1";
|
|
68656
68882
|
function getSecretKey() {
|
|
68657
68883
|
const secret = process.env.HID_AMICO_SECRET || process.env.ACCESS_TOKEN_SECRET || "iservice365-hid-amico";
|
|
@@ -68695,7 +68921,7 @@ function toHidRequestError(error, path5) {
|
|
|
68695
68921
|
status ? `status ${status}` : "",
|
|
68696
68922
|
payload ? `response ${payload}` : error.message
|
|
68697
68923
|
].filter(Boolean).join(" - ");
|
|
68698
|
-
return new
|
|
68924
|
+
return new import_node_server_utils260.BadRequestError(detail);
|
|
68699
68925
|
}
|
|
68700
68926
|
return error;
|
|
68701
68927
|
}
|
|
@@ -68737,7 +68963,7 @@ var HidAmicoClient = class {
|
|
|
68737
68963
|
password: decryptSecret(this.reader.password)
|
|
68738
68964
|
});
|
|
68739
68965
|
if (!res.data?.session) {
|
|
68740
|
-
throw new
|
|
68966
|
+
throw new import_node_server_utils260.BadRequestError("HID Amico login failed: missing session.");
|
|
68741
68967
|
}
|
|
68742
68968
|
this.session = res.data.session;
|
|
68743
68969
|
return this.session;
|
|
@@ -68761,7 +68987,7 @@ var HidAmicoClient = class {
|
|
|
68761
68987
|
const payload = JSON.parse(buffer.toString("utf8"));
|
|
68762
68988
|
const image = payload.image || payload.photo || payload.data?.image || payload.data?.photo;
|
|
68763
68989
|
if (!image) {
|
|
68764
|
-
throw new
|
|
68990
|
+
throw new import_node_server_utils260.BadRequestError("HID Amico user image response did not include an image.");
|
|
68765
68991
|
}
|
|
68766
68992
|
return {
|
|
68767
68993
|
contentType: payload.contentType || payload.mimeType || "image/jpeg",
|
|
@@ -68886,7 +69112,7 @@ function useHidAmicoService() {
|
|
|
68886
69112
|
async function getActiveReader(id) {
|
|
68887
69113
|
const reader = await repo.getById(id, { includePassword: true });
|
|
68888
69114
|
if (reader.enabled === false || reader.status === "inactive" || reader.status === "deleted") {
|
|
68889
|
-
throw new
|
|
69115
|
+
throw new import_node_server_utils260.BadRequestError("HID Amico reader is not active.");
|
|
68890
69116
|
}
|
|
68891
69117
|
return reader;
|
|
68892
69118
|
}
|
|
@@ -69141,13 +69367,13 @@ function useHidAmicoService() {
|
|
|
69141
69367
|
}
|
|
69142
69368
|
|
|
69143
69369
|
// src/controllers/hid-amico.controller.ts
|
|
69144
|
-
var
|
|
69370
|
+
var import_node_server_utils261 = require("@7365admin1/node-server-utils");
|
|
69145
69371
|
function useHidAmicoController() {
|
|
69146
69372
|
const service = useHidAmicoService();
|
|
69147
69373
|
async function listReaders(req, res, next) {
|
|
69148
69374
|
const { error, value } = schemaHidAmicoReaderListQuery.validate(req.query);
|
|
69149
69375
|
if (error) {
|
|
69150
|
-
next(new
|
|
69376
|
+
next(new import_node_server_utils261.BadRequestError(error.message));
|
|
69151
69377
|
return;
|
|
69152
69378
|
}
|
|
69153
69379
|
try {
|
|
@@ -69159,7 +69385,7 @@ function useHidAmicoController() {
|
|
|
69159
69385
|
async function createReader(req, res, next) {
|
|
69160
69386
|
const { error, value } = schemaHidAmicoReader.validate(req.body);
|
|
69161
69387
|
if (error) {
|
|
69162
|
-
next(new
|
|
69388
|
+
next(new import_node_server_utils261.BadRequestError(error.message));
|
|
69163
69389
|
return;
|
|
69164
69390
|
}
|
|
69165
69391
|
try {
|
|
@@ -69172,7 +69398,7 @@ function useHidAmicoController() {
|
|
|
69172
69398
|
const params = schemaHidAmicoReaderIdParams.validate(req.params);
|
|
69173
69399
|
const body = schemaUpdateHidAmicoReader.validate(req.body);
|
|
69174
69400
|
if (params.error || body.error) {
|
|
69175
|
-
next(new
|
|
69401
|
+
next(new import_node_server_utils261.BadRequestError(params.error?.message || body.error?.message));
|
|
69176
69402
|
return;
|
|
69177
69403
|
}
|
|
69178
69404
|
try {
|
|
@@ -69184,7 +69410,7 @@ function useHidAmicoController() {
|
|
|
69184
69410
|
async function deleteReader(req, res, next) {
|
|
69185
69411
|
const { error, value } = schemaHidAmicoReaderIdParams.validate(req.params);
|
|
69186
69412
|
if (error) {
|
|
69187
|
-
next(new
|
|
69413
|
+
next(new import_node_server_utils261.BadRequestError(error.message));
|
|
69188
69414
|
return;
|
|
69189
69415
|
}
|
|
69190
69416
|
try {
|
|
@@ -69196,7 +69422,7 @@ function useHidAmicoController() {
|
|
|
69196
69422
|
async function testReader(req, res, next) {
|
|
69197
69423
|
const { error, value } = schemaHidAmicoReaderIdParams.validate(req.params);
|
|
69198
69424
|
if (error) {
|
|
69199
|
-
next(new
|
|
69425
|
+
next(new import_node_server_utils261.BadRequestError(error.message));
|
|
69200
69426
|
return;
|
|
69201
69427
|
}
|
|
69202
69428
|
try {
|
|
@@ -69209,7 +69435,7 @@ function useHidAmicoController() {
|
|
|
69209
69435
|
const params = schemaHidAmicoReaderIdParams.validate(req.params);
|
|
69210
69436
|
const body = schemaHidAmicoSync.validate(req.body ?? {});
|
|
69211
69437
|
if (params.error || body.error) {
|
|
69212
|
-
next(new
|
|
69438
|
+
next(new import_node_server_utils261.BadRequestError(params.error?.message || body.error?.message));
|
|
69213
69439
|
return;
|
|
69214
69440
|
}
|
|
69215
69441
|
try {
|
|
@@ -69222,7 +69448,7 @@ function useHidAmicoController() {
|
|
|
69222
69448
|
const params = schemaHidAmicoReaderIdParams.validate(req.params);
|
|
69223
69449
|
const query = schemaHidAmicoLogQuery.validate(req.query);
|
|
69224
69450
|
if (params.error || query.error) {
|
|
69225
|
-
next(new
|
|
69451
|
+
next(new import_node_server_utils261.BadRequestError(params.error?.message || query.error?.message));
|
|
69226
69452
|
return;
|
|
69227
69453
|
}
|
|
69228
69454
|
try {
|
|
@@ -69235,7 +69461,7 @@ function useHidAmicoController() {
|
|
|
69235
69461
|
const params = schemaHidAmicoReaderIdParams.validate(req.params);
|
|
69236
69462
|
const query = schemaHidAmicoIdentityQuery.validate(req.query);
|
|
69237
69463
|
if (params.error || query.error) {
|
|
69238
|
-
next(new
|
|
69464
|
+
next(new import_node_server_utils261.BadRequestError(params.error?.message || query.error?.message));
|
|
69239
69465
|
return;
|
|
69240
69466
|
}
|
|
69241
69467
|
try {
|
|
@@ -69247,13 +69473,13 @@ function useHidAmicoController() {
|
|
|
69247
69473
|
async function createIdentity(req, res, next) {
|
|
69248
69474
|
const params = schemaHidAmicoReaderIdParams.validate(req.params);
|
|
69249
69475
|
if (params.error) {
|
|
69250
|
-
next(new
|
|
69476
|
+
next(new import_node_server_utils261.BadRequestError(params.error.message));
|
|
69251
69477
|
return;
|
|
69252
69478
|
}
|
|
69253
69479
|
try {
|
|
69254
69480
|
const body = schemaCreateHidAmicoIdentity.validate(req.body);
|
|
69255
69481
|
if (body.error) {
|
|
69256
|
-
next(new
|
|
69482
|
+
next(new import_node_server_utils261.BadRequestError(body.error.message));
|
|
69257
69483
|
return;
|
|
69258
69484
|
}
|
|
69259
69485
|
res.status(201).json({ data: await service.createIdentity(params.value.readerId, body.value) });
|
|
@@ -69265,7 +69491,7 @@ function useHidAmicoController() {
|
|
|
69265
69491
|
const params = schemaHidAmicoIdentityIdParams.validate(req.params);
|
|
69266
69492
|
const body = schemaUpdateHidAmicoIdentity.validate(req.body ?? {});
|
|
69267
69493
|
if (params.error || body.error) {
|
|
69268
|
-
next(new
|
|
69494
|
+
next(new import_node_server_utils261.BadRequestError(params.error?.message || body.error?.message));
|
|
69269
69495
|
return;
|
|
69270
69496
|
}
|
|
69271
69497
|
try {
|
|
@@ -69277,7 +69503,7 @@ function useHidAmicoController() {
|
|
|
69277
69503
|
async function deleteIdentity(req, res, next) {
|
|
69278
69504
|
const { error, value } = schemaHidAmicoIdentityIdParams.validate(req.params);
|
|
69279
69505
|
if (error) {
|
|
69280
|
-
next(new
|
|
69506
|
+
next(new import_node_server_utils261.BadRequestError(error.message));
|
|
69281
69507
|
return;
|
|
69282
69508
|
}
|
|
69283
69509
|
try {
|
|
@@ -69289,7 +69515,7 @@ function useHidAmicoController() {
|
|
|
69289
69515
|
async function receiveNotification(req, res, next) {
|
|
69290
69516
|
const validation = schemaHidAmicoNotificationParams.validate(req.params);
|
|
69291
69517
|
if (validation.error) {
|
|
69292
|
-
next(new
|
|
69518
|
+
next(new import_node_server_utils261.BadRequestError(validation.error.message));
|
|
69293
69519
|
return;
|
|
69294
69520
|
}
|
|
69295
69521
|
try {
|
|
@@ -69306,7 +69532,7 @@ function useHidAmicoController() {
|
|
|
69306
69532
|
async function getDoorState(req, res, next) {
|
|
69307
69533
|
const { error, value } = schemaHidAmicoReaderIdParams.validate(req.params);
|
|
69308
69534
|
if (error) {
|
|
69309
|
-
next(new
|
|
69535
|
+
next(new import_node_server_utils261.BadRequestError(error.message));
|
|
69310
69536
|
return;
|
|
69311
69537
|
}
|
|
69312
69538
|
try {
|
|
@@ -69318,7 +69544,7 @@ function useHidAmicoController() {
|
|
|
69318
69544
|
async function getUserImage(req, res, next) {
|
|
69319
69545
|
const { error, value } = schemaHidAmicoUserImageParams.validate(req.params);
|
|
69320
69546
|
if (error) {
|
|
69321
|
-
next(new
|
|
69547
|
+
next(new import_node_server_utils261.BadRequestError(error.message));
|
|
69322
69548
|
return;
|
|
69323
69549
|
}
|
|
69324
69550
|
try {
|
|
@@ -69332,7 +69558,7 @@ function useHidAmicoController() {
|
|
|
69332
69558
|
const params = schemaHidAmicoReaderIdParams.validate(req.params);
|
|
69333
69559
|
const body = schemaHidAmicoExecuteActions.validate(req.body ?? {});
|
|
69334
69560
|
if (params.error || body.error) {
|
|
69335
|
-
next(new
|
|
69561
|
+
next(new import_node_server_utils261.BadRequestError(params.error?.message || body.error?.message));
|
|
69336
69562
|
return;
|
|
69337
69563
|
}
|
|
69338
69564
|
try {
|
|
@@ -69345,7 +69571,7 @@ function useHidAmicoController() {
|
|
|
69345
69571
|
const params = schemaHidAmicoReaderIdParams.validate(req.params);
|
|
69346
69572
|
const body = schemaHidAmicoConfiguration.validate(req.body ?? {});
|
|
69347
69573
|
if (params.error || body.error) {
|
|
69348
|
-
next(new
|
|
69574
|
+
next(new import_node_server_utils261.BadRequestError(params.error?.message || body.error?.message));
|
|
69349
69575
|
return;
|
|
69350
69576
|
}
|
|
69351
69577
|
try {
|
|
@@ -69358,7 +69584,7 @@ function useHidAmicoController() {
|
|
|
69358
69584
|
const params = schemaHidAmicoReaderIdParams.validate(req.params);
|
|
69359
69585
|
const body = schemaHidAmicoSetConfiguration.validate(req.body ?? {});
|
|
69360
69586
|
if (params.error || body.error) {
|
|
69361
|
-
next(new
|
|
69587
|
+
next(new import_node_server_utils261.BadRequestError(params.error?.message || body.error?.message));
|
|
69362
69588
|
return;
|
|
69363
69589
|
}
|
|
69364
69590
|
try {
|
|
@@ -69371,20 +69597,20 @@ function useHidAmicoController() {
|
|
|
69371
69597
|
const params = schemaHidAmicoReaderIdParams.validate(req.params);
|
|
69372
69598
|
const body = schemaHidAmicoObjectOperation.validate(req.body ?? {});
|
|
69373
69599
|
if (params.error || body.error) {
|
|
69374
|
-
next(new
|
|
69600
|
+
next(new import_node_server_utils261.BadRequestError(params.error?.message || body.error?.message));
|
|
69375
69601
|
return;
|
|
69376
69602
|
}
|
|
69377
69603
|
const { operation, ...payload } = body.value;
|
|
69378
69604
|
if (operation === "create" && !Array.isArray(payload.values)) {
|
|
69379
|
-
next(new
|
|
69605
|
+
next(new import_node_server_utils261.BadRequestError("values array is required for HID object create operations."));
|
|
69380
69606
|
return;
|
|
69381
69607
|
}
|
|
69382
69608
|
if (operation === "modify" && (!payload.values || Array.isArray(payload.values) || !payload.where)) {
|
|
69383
|
-
next(new
|
|
69609
|
+
next(new import_node_server_utils261.BadRequestError("values object and where are required for HID object modify operations."));
|
|
69384
69610
|
return;
|
|
69385
69611
|
}
|
|
69386
69612
|
if (operation === "destroy" && !payload.where) {
|
|
69387
|
-
next(new
|
|
69613
|
+
next(new import_node_server_utils261.BadRequestError("where is required for HID object destroy operations."));
|
|
69388
69614
|
return;
|
|
69389
69615
|
}
|
|
69390
69616
|
try {
|
|
@@ -69563,6 +69789,7 @@ function useHidAmicoController() {
|
|
|
69563
69789
|
building_units_namespace_collection,
|
|
69564
69790
|
buildings_namespace_collection,
|
|
69565
69791
|
bulletin_boards_namespace_collection,
|
|
69792
|
+
chatPrelovedEvents,
|
|
69566
69793
|
chatSchema,
|
|
69567
69794
|
createManpowerRemarksDaily,
|
|
69568
69795
|
customerSchema,
|
|
@@ -69718,6 +69945,7 @@ function useHidAmicoController() {
|
|
|
69718
69945
|
useAuthServiceV2,
|
|
69719
69946
|
useBidPrelovedController,
|
|
69720
69947
|
useBidPrelovedRepo,
|
|
69948
|
+
useBidPrelovedService,
|
|
69721
69949
|
useBuildingController,
|
|
69722
69950
|
useBuildingLevelController,
|
|
69723
69951
|
useBuildingLevelRepo,
|