@7365admin1/core 2.66.0 → 2.67.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +130 -25
- package/dist/index.js +661 -97
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +663 -99
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4211,7 +4211,7 @@ function useOrgRepo() {
|
|
|
4211
4211
|
}
|
|
4212
4212
|
async function createUniqueIndex() {
|
|
4213
4213
|
try {
|
|
4214
|
-
await collection.createIndex({ email: 1 }
|
|
4214
|
+
await collection.createIndex({ email: 1 });
|
|
4215
4215
|
} catch (error) {
|
|
4216
4216
|
throw new InternalServerError9("Failed to create unique index on name.");
|
|
4217
4217
|
}
|
|
@@ -4403,7 +4403,6 @@ function useOrgRepo() {
|
|
|
4403
4403
|
}
|
|
4404
4404
|
async function getOrgsByEmail(email) {
|
|
4405
4405
|
const cacheKey = makeCacheKey8(namespace_collection, {
|
|
4406
|
-
type: "many",
|
|
4407
4406
|
email
|
|
4408
4407
|
});
|
|
4409
4408
|
const cachedData = await getCache(cacheKey);
|
|
@@ -31371,26 +31370,31 @@ var schemaDocumentManagement = Joi74.object({
|
|
|
31371
31370
|
_id: Joi74.string().hex().optional().allow("", null),
|
|
31372
31371
|
name: Joi74.string().required(),
|
|
31373
31372
|
type: Joi74.string().optional().allow("", null),
|
|
31374
|
-
attachment: Joi74.string().
|
|
31375
|
-
|
|
31376
|
-
|
|
31373
|
+
attachment: Joi74.when("isFolder", { is: true, then: Joi74.forbidden(), otherwise: Joi74.string().optional().allow("", null) }),
|
|
31374
|
+
remarks: Joi74.string().optional().allow("", null),
|
|
31375
|
+
isFolder: Joi74.boolean().optional().default(false),
|
|
31377
31376
|
org: Joi74.string().hex().optional().allow("", null),
|
|
31378
31377
|
site: Joi74.string().hex().optional().allow("", null),
|
|
31378
|
+
parentId: Joi74.string().hex().optional().allow("", null),
|
|
31379
|
+
createdBy: Joi74.string().hex().required(),
|
|
31379
31380
|
updatedBy: Joi74.string().hex().optional().allow("", null),
|
|
31380
31381
|
createdAt: Joi74.date().optional().allow("", null),
|
|
31381
|
-
updatedAt: Joi74.date().optional().allow("", null)
|
|
31382
|
+
updatedAt: Joi74.date().optional().allow("", null),
|
|
31383
|
+
status: Joi74.string().optional().allow("", null).default("active")
|
|
31382
31384
|
});
|
|
31383
31385
|
var schemaUpdateDocumentManagement = Joi74.object({
|
|
31384
31386
|
_id: Joi74.string().hex().required(),
|
|
31385
31387
|
name: Joi74.string().optional().allow("", null),
|
|
31386
31388
|
type: Joi74.string().optional().allow("", null),
|
|
31387
|
-
attachment: Joi74.string().optional(),
|
|
31388
|
-
|
|
31389
|
+
attachment: Joi74.when("isFolder", { is: true, then: Joi74.forbidden(), otherwise: Joi74.string().optional().allow("", null) }),
|
|
31390
|
+
remarks: Joi74.string().optional().allow("", null),
|
|
31391
|
+
isFolder: Joi74.boolean().optional(),
|
|
31389
31392
|
org: Joi74.string().hex().optional().allow("", null),
|
|
31390
31393
|
site: Joi74.string().hex().optional().allow("", null),
|
|
31394
|
+
parentId: Joi74.string().hex().optional().allow("", null),
|
|
31391
31395
|
updatedBy: Joi74.string().hex().optional().allow("", null),
|
|
31392
|
-
|
|
31393
|
-
|
|
31396
|
+
updatedAt: Joi74.date().optional().allow("", null),
|
|
31397
|
+
status: Joi74.string().optional().allow("", null)
|
|
31394
31398
|
});
|
|
31395
31399
|
function MDocumentManagement(value) {
|
|
31396
31400
|
const { error } = schemaDocumentManagement.validate(value);
|
|
@@ -31418,18 +31422,31 @@ function MDocumentManagement(value) {
|
|
|
31418
31422
|
throw new Error("Invalid site ID.");
|
|
31419
31423
|
}
|
|
31420
31424
|
}
|
|
31425
|
+
if (value.parentId && typeof value.parentId === "string") {
|
|
31426
|
+
try {
|
|
31427
|
+
value.parentId = new ObjectId76(value.parentId);
|
|
31428
|
+
} catch (error2) {
|
|
31429
|
+
throw new Error("Invalid parentId.");
|
|
31430
|
+
}
|
|
31431
|
+
}
|
|
31432
|
+
if (value.isFolder) {
|
|
31433
|
+
value.attachment = void 0;
|
|
31434
|
+
}
|
|
31421
31435
|
return {
|
|
31422
31436
|
_id: value._id,
|
|
31423
31437
|
name: value.name,
|
|
31424
31438
|
type: value.type,
|
|
31425
31439
|
attachment: value.attachment,
|
|
31426
|
-
|
|
31440
|
+
remarks: value.remarks ?? "",
|
|
31441
|
+
isFolder: value.isFolder ?? false,
|
|
31427
31442
|
org: value.org,
|
|
31428
31443
|
site: value.site,
|
|
31444
|
+
...value.parentId ? { parentId: value.parentId } : {},
|
|
31429
31445
|
createdBy: value.createdBy,
|
|
31430
31446
|
updatedBy: value.updatedBy,
|
|
31431
31447
|
createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
31432
|
-
updatedAt: value.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
31448
|
+
updatedAt: value.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
31449
|
+
status: value.status ?? "active"
|
|
31433
31450
|
};
|
|
31434
31451
|
}
|
|
31435
31452
|
|
|
@@ -31453,11 +31470,22 @@ function useDocumentManagementRepo() {
|
|
|
31453
31470
|
const namespace_collection = "documents";
|
|
31454
31471
|
const collection = db.collection(namespace_collection);
|
|
31455
31472
|
const { delNamespace, getCache, setCache } = useCache40(namespace_collection);
|
|
31473
|
+
async function createIndex() {
|
|
31474
|
+
try {
|
|
31475
|
+
await collection.createIndexes([
|
|
31476
|
+
{ key: { site: 1 } },
|
|
31477
|
+
{ key: { isFolder: 1 } },
|
|
31478
|
+
{ key: { parentId: 1 } }
|
|
31479
|
+
]);
|
|
31480
|
+
} catch (error) {
|
|
31481
|
+
throw new InternalServerError41("Failed to create index on document.");
|
|
31482
|
+
}
|
|
31483
|
+
}
|
|
31456
31484
|
async function createTextIndex() {
|
|
31457
31485
|
try {
|
|
31458
31486
|
await collection.createIndex({
|
|
31459
31487
|
name: "text",
|
|
31460
|
-
|
|
31488
|
+
remarks: "text"
|
|
31461
31489
|
});
|
|
31462
31490
|
} catch (error) {
|
|
31463
31491
|
throw new InternalServerError41("Failed to create text index on document.");
|
|
@@ -31491,7 +31519,8 @@ function useDocumentManagementRepo() {
|
|
|
31491
31519
|
sort = {},
|
|
31492
31520
|
status = "active",
|
|
31493
31521
|
org = "",
|
|
31494
|
-
site = ""
|
|
31522
|
+
site = "",
|
|
31523
|
+
parentId = ""
|
|
31495
31524
|
}) {
|
|
31496
31525
|
page = page > 0 ? page - 1 : 0;
|
|
31497
31526
|
try {
|
|
@@ -31510,14 +31539,24 @@ function useDocumentManagementRepo() {
|
|
|
31510
31539
|
const query = {
|
|
31511
31540
|
...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } }
|
|
31512
31541
|
};
|
|
31513
|
-
if (
|
|
31514
|
-
query.
|
|
31515
|
-
cacheOptions.
|
|
31542
|
+
if (org) {
|
|
31543
|
+
query.org = new ObjectId77(org);
|
|
31544
|
+
cacheOptions.org = org.toString();
|
|
31545
|
+
}
|
|
31546
|
+
if (parentId) {
|
|
31547
|
+
try {
|
|
31548
|
+
query.parentId = new ObjectId77(parentId);
|
|
31549
|
+
cacheOptions.parentId = parentId.toString();
|
|
31550
|
+
} catch (error) {
|
|
31551
|
+
throw new BadRequestError124("Invalid parentId format.");
|
|
31552
|
+
}
|
|
31553
|
+
} else {
|
|
31554
|
+
query.parentId = { $in: [null, ""] };
|
|
31516
31555
|
}
|
|
31517
31556
|
if (search) {
|
|
31518
31557
|
query.$or = [
|
|
31519
31558
|
{ name: { $regex: search, $options: "i" } },
|
|
31520
|
-
{
|
|
31559
|
+
{ remarks: { $regex: search, $options: "i" } }
|
|
31521
31560
|
];
|
|
31522
31561
|
cacheOptions.search = search;
|
|
31523
31562
|
}
|
|
@@ -31539,6 +31578,9 @@ function useDocumentManagementRepo() {
|
|
|
31539
31578
|
type: 1,
|
|
31540
31579
|
status: 1,
|
|
31541
31580
|
attachment: 1,
|
|
31581
|
+
parentId: 1,
|
|
31582
|
+
isFolder: 1,
|
|
31583
|
+
remarks: 1,
|
|
31542
31584
|
createdAt: 1,
|
|
31543
31585
|
updatedAt: 1
|
|
31544
31586
|
}
|
|
@@ -31710,6 +31752,7 @@ function useDocumentManagementRepo() {
|
|
|
31710
31752
|
}
|
|
31711
31753
|
}
|
|
31712
31754
|
return {
|
|
31755
|
+
createIndex,
|
|
31713
31756
|
createTextIndex,
|
|
31714
31757
|
add,
|
|
31715
31758
|
getAll,
|
|
@@ -31727,7 +31770,7 @@ import {
|
|
|
31727
31770
|
NotFoundError as NotFoundError29
|
|
31728
31771
|
} from "@7365admin1/node-server-utils";
|
|
31729
31772
|
function useDocumentManagementService() {
|
|
31730
|
-
const { add: _add
|
|
31773
|
+
const { add: _add } = useDocumentManagementRepo();
|
|
31731
31774
|
const { updateStatusById } = useFileRepo();
|
|
31732
31775
|
async function createDocument(value) {
|
|
31733
31776
|
const session = useAtlas65.getClient()?.startSession();
|
|
@@ -31757,32 +31800,8 @@ function useDocumentManagementService() {
|
|
|
31757
31800
|
session?.endSession();
|
|
31758
31801
|
}
|
|
31759
31802
|
}
|
|
31760
|
-
async function getDocuments({
|
|
31761
|
-
search,
|
|
31762
|
-
page,
|
|
31763
|
-
limit,
|
|
31764
|
-
sort,
|
|
31765
|
-
status,
|
|
31766
|
-
org,
|
|
31767
|
-
site
|
|
31768
|
-
}) {
|
|
31769
|
-
try {
|
|
31770
|
-
return await _getAll({
|
|
31771
|
-
search,
|
|
31772
|
-
page,
|
|
31773
|
-
limit,
|
|
31774
|
-
sort,
|
|
31775
|
-
status,
|
|
31776
|
-
org,
|
|
31777
|
-
site
|
|
31778
|
-
});
|
|
31779
|
-
} catch (error) {
|
|
31780
|
-
throw error;
|
|
31781
|
-
}
|
|
31782
|
-
}
|
|
31783
31803
|
return {
|
|
31784
|
-
createDocument
|
|
31785
|
-
getDocuments
|
|
31804
|
+
createDocument
|
|
31786
31805
|
};
|
|
31787
31806
|
}
|
|
31788
31807
|
|
|
@@ -31790,8 +31809,9 @@ function useDocumentManagementService() {
|
|
|
31790
31809
|
import { BadRequestError as BadRequestError126, logger as logger104 } from "@7365admin1/node-server-utils";
|
|
31791
31810
|
import Joi75 from "joi";
|
|
31792
31811
|
function useDocumentManagementController() {
|
|
31793
|
-
const { createDocument: _add
|
|
31812
|
+
const { createDocument: _add } = useDocumentManagementService();
|
|
31794
31813
|
const {
|
|
31814
|
+
getAll: _getDocuments,
|
|
31795
31815
|
getDocumentById: _getDocumentById,
|
|
31796
31816
|
updateDocumentById: _updateDocumentById,
|
|
31797
31817
|
deleteDocumentById: _deleteDocumentById,
|
|
@@ -31809,8 +31829,12 @@ function useDocumentManagementController() {
|
|
|
31809
31829
|
createdBy = req.body.createdBy;
|
|
31810
31830
|
}
|
|
31811
31831
|
const payload = { ...req.body, createdBy };
|
|
31812
|
-
if (payload.
|
|
31832
|
+
if (payload.isFolder) {
|
|
31833
|
+
delete payload.attachment;
|
|
31834
|
+
} else if (Array.isArray(payload.attachment)) {
|
|
31813
31835
|
payload.attachment = payload.attachment[0];
|
|
31836
|
+
} else if (!payload.attachment) {
|
|
31837
|
+
payload.attachment = "";
|
|
31814
31838
|
}
|
|
31815
31839
|
const { error } = schemaDocumentManagement.validate(payload, {
|
|
31816
31840
|
abortEarly: false
|
|
@@ -31838,7 +31862,8 @@ function useDocumentManagementController() {
|
|
|
31838
31862
|
limit: Joi75.number().integer().min(1).max(100).allow("", null).default(10),
|
|
31839
31863
|
status: Joi75.string().required(),
|
|
31840
31864
|
org: Joi75.string().hex().optional().allow("", null),
|
|
31841
|
-
site: Joi75.string().hex().optional().allow("", null)
|
|
31865
|
+
site: Joi75.string().hex().optional().allow("", null),
|
|
31866
|
+
parentId: Joi75.string().hex().optional().allow("", null)
|
|
31842
31867
|
});
|
|
31843
31868
|
const query = { ...req.query };
|
|
31844
31869
|
query.status = req.query.status;
|
|
@@ -31854,6 +31879,7 @@ function useDocumentManagementController() {
|
|
|
31854
31879
|
const status = req.query.status ?? "active";
|
|
31855
31880
|
const org = req.query.org ?? "";
|
|
31856
31881
|
const site = req.query.site ?? "";
|
|
31882
|
+
const parentId = req.query.parentId ?? "";
|
|
31857
31883
|
try {
|
|
31858
31884
|
const data = await _getDocuments({
|
|
31859
31885
|
search,
|
|
@@ -31861,7 +31887,8 @@ function useDocumentManagementController() {
|
|
|
31861
31887
|
limit,
|
|
31862
31888
|
status,
|
|
31863
31889
|
org,
|
|
31864
|
-
site
|
|
31890
|
+
site,
|
|
31891
|
+
parentId
|
|
31865
31892
|
});
|
|
31866
31893
|
res.json(data);
|
|
31867
31894
|
return;
|
|
@@ -31917,8 +31944,12 @@ function useDocumentManagementController() {
|
|
|
31917
31944
|
}
|
|
31918
31945
|
const _id = req.params.id;
|
|
31919
31946
|
const payload = { ...req.body, updatedBy };
|
|
31920
|
-
if (payload.
|
|
31947
|
+
if (payload.isFolder) {
|
|
31948
|
+
delete payload.attachment;
|
|
31949
|
+
} else if (Array.isArray(payload.attachment)) {
|
|
31921
31950
|
payload.attachment = payload.attachment[0];
|
|
31951
|
+
} else if (!payload.attachment) {
|
|
31952
|
+
payload.attachment = "";
|
|
31922
31953
|
}
|
|
31923
31954
|
const { error } = validation.validate({ _id, ...payload });
|
|
31924
31955
|
if (error) {
|
|
@@ -55075,50 +55106,287 @@ function usePostPrelovedController() {
|
|
|
55075
55106
|
};
|
|
55076
55107
|
}
|
|
55077
55108
|
|
|
55078
|
-
// src/models/
|
|
55109
|
+
// src/models/category-preloved.model.ts
|
|
55079
55110
|
import Joi134 from "joi";
|
|
55080
55111
|
import { ObjectId as ObjectId131 } from "mongodb";
|
|
55112
|
+
var schemaCategoryPreloved = Joi134.object({
|
|
55113
|
+
name: Joi134.string().required(),
|
|
55114
|
+
createdBy: Joi134.string().hex().optional().allow("", null),
|
|
55115
|
+
site: Joi134.string().hex().optional().allow("", null)
|
|
55116
|
+
});
|
|
55117
|
+
var schemaUpdateCategoryPreloved = Joi134.object({
|
|
55118
|
+
name: Joi134.string().optional().allow("", null),
|
|
55119
|
+
site: Joi134.string().hex().optional().allow("", null)
|
|
55120
|
+
});
|
|
55121
|
+
function MCategoryPreloved(value) {
|
|
55122
|
+
const { error } = schemaCategoryPreloved.validate(value);
|
|
55123
|
+
if (error) {
|
|
55124
|
+
throw new Error(error.details[0].message);
|
|
55125
|
+
}
|
|
55126
|
+
if (value.createdBy && typeof value.createdBy === "string") {
|
|
55127
|
+
try {
|
|
55128
|
+
value.createdBy = new ObjectId131(value.createdBy);
|
|
55129
|
+
} catch {
|
|
55130
|
+
throw new Error("Invalid createdBy ID.");
|
|
55131
|
+
}
|
|
55132
|
+
}
|
|
55133
|
+
if (value.site && typeof value.site === "string") {
|
|
55134
|
+
try {
|
|
55135
|
+
value.site = new ObjectId131(value.site);
|
|
55136
|
+
} catch {
|
|
55137
|
+
throw new Error("Invalid site ID.");
|
|
55138
|
+
}
|
|
55139
|
+
}
|
|
55140
|
+
return {
|
|
55141
|
+
name: value.name ?? "",
|
|
55142
|
+
createdBy: value.createdBy ?? "",
|
|
55143
|
+
site: value.site ?? null,
|
|
55144
|
+
createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
55145
|
+
updatedAt: value.updatedAt ?? null
|
|
55146
|
+
};
|
|
55147
|
+
}
|
|
55148
|
+
|
|
55149
|
+
// src/repositories/category-preloved.repo.ts
|
|
55150
|
+
import {
|
|
55151
|
+
BadRequestError as BadRequestError212,
|
|
55152
|
+
InternalServerError as InternalServerError75,
|
|
55153
|
+
useAtlas as useAtlas118
|
|
55154
|
+
} from "@7365admin1/node-server-utils";
|
|
55155
|
+
import { ObjectId as ObjectId132 } from "mongodb";
|
|
55156
|
+
function useCategoryPrelovedRepo() {
|
|
55157
|
+
const db = useAtlas118.getDb();
|
|
55158
|
+
if (!db) {
|
|
55159
|
+
throw new InternalServerError75("Unable to connect to server.");
|
|
55160
|
+
}
|
|
55161
|
+
const CATEGORY_COLLECTION = "category-preloved";
|
|
55162
|
+
const collection = db.collection(CATEGORY_COLLECTION);
|
|
55163
|
+
async function getAll({
|
|
55164
|
+
search = "",
|
|
55165
|
+
site
|
|
55166
|
+
} = {}) {
|
|
55167
|
+
if (site) {
|
|
55168
|
+
try {
|
|
55169
|
+
site = new ObjectId132(site);
|
|
55170
|
+
} catch {
|
|
55171
|
+
throw new BadRequestError212("Invalid site ID format.");
|
|
55172
|
+
}
|
|
55173
|
+
}
|
|
55174
|
+
const query = {
|
|
55175
|
+
...site && { site },
|
|
55176
|
+
...search && { name: { $regex: search, $options: "i" } }
|
|
55177
|
+
};
|
|
55178
|
+
try {
|
|
55179
|
+
return await collection.find(query).sort({ name: 1 }).toArray();
|
|
55180
|
+
} catch (error) {
|
|
55181
|
+
console.error("Error in category-preloved getAll:", error);
|
|
55182
|
+
throw error;
|
|
55183
|
+
}
|
|
55184
|
+
}
|
|
55185
|
+
return { getAll };
|
|
55186
|
+
}
|
|
55187
|
+
|
|
55188
|
+
// src/controllers/category-preloved.controller.ts
|
|
55189
|
+
import { BadRequestError as BadRequestError213, logger as logger187 } from "@7365admin1/node-server-utils";
|
|
55190
|
+
import Joi135 from "joi";
|
|
55191
|
+
function useCategoryPrelovedController() {
|
|
55192
|
+
const { getAll: _getAll } = useCategoryPrelovedRepo();
|
|
55193
|
+
async function getAll(req, res, next) {
|
|
55194
|
+
const schema2 = Joi135.object({
|
|
55195
|
+
search: Joi135.string().optional().allow("", null),
|
|
55196
|
+
site: Joi135.string().hex().length(24).optional().allow("", null)
|
|
55197
|
+
});
|
|
55198
|
+
const { error, value } = schema2.validate(req.query, { abortEarly: false });
|
|
55199
|
+
if (error) {
|
|
55200
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
55201
|
+
logger187.log({ level: "error", message: messages });
|
|
55202
|
+
next(new BadRequestError213(messages));
|
|
55203
|
+
return;
|
|
55204
|
+
}
|
|
55205
|
+
try {
|
|
55206
|
+
const data = await _getAll(value);
|
|
55207
|
+
res.status(200).json({ data });
|
|
55208
|
+
return;
|
|
55209
|
+
} catch (error2) {
|
|
55210
|
+
logger187.log({ level: "error", message: error2.message });
|
|
55211
|
+
next(error2);
|
|
55212
|
+
return;
|
|
55213
|
+
}
|
|
55214
|
+
}
|
|
55215
|
+
return { getAll };
|
|
55216
|
+
}
|
|
55217
|
+
|
|
55218
|
+
// src/models/subcategory-preloved.model.ts
|
|
55219
|
+
import Joi136 from "joi";
|
|
55220
|
+
import { ObjectId as ObjectId133 } from "mongodb";
|
|
55221
|
+
var schemaSubcategoryPreloved = Joi136.object({
|
|
55222
|
+
name: Joi136.string().required(),
|
|
55223
|
+
createdBy: Joi136.string().hex().optional().allow("", null),
|
|
55224
|
+
site: Joi136.string().hex().optional().allow("", null),
|
|
55225
|
+
category_id: Joi136.string().hex().required()
|
|
55226
|
+
});
|
|
55227
|
+
var schemaUpdateSubcategoryPreloved = Joi136.object({
|
|
55228
|
+
name: Joi136.string().optional().allow("", null),
|
|
55229
|
+
site: Joi136.string().hex().optional().allow("", null),
|
|
55230
|
+
category_id: Joi136.string().hex().optional().allow("", null)
|
|
55231
|
+
});
|
|
55232
|
+
function MSubcategoryPreloved(value) {
|
|
55233
|
+
const { error } = schemaSubcategoryPreloved.validate(value);
|
|
55234
|
+
if (error) {
|
|
55235
|
+
throw new Error(error.details[0].message);
|
|
55236
|
+
}
|
|
55237
|
+
if (value.createdBy && typeof value.createdBy === "string") {
|
|
55238
|
+
try {
|
|
55239
|
+
value.createdBy = new ObjectId133(value.createdBy);
|
|
55240
|
+
} catch {
|
|
55241
|
+
throw new Error("Invalid createdBy ID.");
|
|
55242
|
+
}
|
|
55243
|
+
}
|
|
55244
|
+
if (value.site && typeof value.site === "string") {
|
|
55245
|
+
try {
|
|
55246
|
+
value.site = new ObjectId133(value.site);
|
|
55247
|
+
} catch {
|
|
55248
|
+
throw new Error("Invalid site ID.");
|
|
55249
|
+
}
|
|
55250
|
+
}
|
|
55251
|
+
if (value.category_id && typeof value.category_id === "string") {
|
|
55252
|
+
try {
|
|
55253
|
+
value.category_id = new ObjectId133(value.category_id);
|
|
55254
|
+
} catch {
|
|
55255
|
+
throw new Error("Invalid category ID.");
|
|
55256
|
+
}
|
|
55257
|
+
}
|
|
55258
|
+
return {
|
|
55259
|
+
name: value.name ?? "",
|
|
55260
|
+
createdBy: value.createdBy ?? "",
|
|
55261
|
+
site: value.site ?? null,
|
|
55262
|
+
category_id: value.category_id ?? "",
|
|
55263
|
+
createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
55264
|
+
updatedAt: value.updatedAt ?? null
|
|
55265
|
+
};
|
|
55266
|
+
}
|
|
55267
|
+
|
|
55268
|
+
// src/repositories/subcategory-preloved.repo.ts
|
|
55269
|
+
import {
|
|
55270
|
+
BadRequestError as BadRequestError214,
|
|
55271
|
+
InternalServerError as InternalServerError76,
|
|
55272
|
+
useAtlas as useAtlas119
|
|
55273
|
+
} from "@7365admin1/node-server-utils";
|
|
55274
|
+
import { ObjectId as ObjectId134 } from "mongodb";
|
|
55275
|
+
function useSubcategoryPrelovedRepo() {
|
|
55276
|
+
const db = useAtlas119.getDb();
|
|
55277
|
+
if (!db) {
|
|
55278
|
+
throw new InternalServerError76("Unable to connect to server.");
|
|
55279
|
+
}
|
|
55280
|
+
const SUBCATEGORY_COLLECTION = "subcategory-preloved";
|
|
55281
|
+
const collection = db.collection(SUBCATEGORY_COLLECTION);
|
|
55282
|
+
async function getAll({
|
|
55283
|
+
search = "",
|
|
55284
|
+
site,
|
|
55285
|
+
category_id
|
|
55286
|
+
} = {}) {
|
|
55287
|
+
if (site) {
|
|
55288
|
+
try {
|
|
55289
|
+
site = new ObjectId134(site);
|
|
55290
|
+
} catch {
|
|
55291
|
+
throw new BadRequestError214("Invalid site ID format.");
|
|
55292
|
+
}
|
|
55293
|
+
}
|
|
55294
|
+
if (category_id) {
|
|
55295
|
+
try {
|
|
55296
|
+
category_id = new ObjectId134(category_id);
|
|
55297
|
+
} catch {
|
|
55298
|
+
throw new BadRequestError214("Invalid category ID format.");
|
|
55299
|
+
}
|
|
55300
|
+
}
|
|
55301
|
+
const query = {
|
|
55302
|
+
...site && { site },
|
|
55303
|
+
...category_id && { category_id },
|
|
55304
|
+
...search && { name: { $regex: search, $options: "i" } }
|
|
55305
|
+
};
|
|
55306
|
+
try {
|
|
55307
|
+
return await collection.find(query).sort({ name: 1 }).toArray();
|
|
55308
|
+
} catch (error) {
|
|
55309
|
+
throw error;
|
|
55310
|
+
}
|
|
55311
|
+
}
|
|
55312
|
+
return { getAll };
|
|
55313
|
+
}
|
|
55314
|
+
|
|
55315
|
+
// src/controllers/subcategory-preloved.controller.ts
|
|
55316
|
+
import { BadRequestError as BadRequestError215, logger as logger188 } from "@7365admin1/node-server-utils";
|
|
55317
|
+
import Joi137 from "joi";
|
|
55318
|
+
function useSubcategoryPrelovedController() {
|
|
55319
|
+
const { getAll: _getAll } = useSubcategoryPrelovedRepo();
|
|
55320
|
+
async function getAll(req, res, next) {
|
|
55321
|
+
const schema2 = Joi137.object({
|
|
55322
|
+
search: Joi137.string().optional().allow("", null),
|
|
55323
|
+
site: Joi137.string().hex().length(24).optional().allow("", null),
|
|
55324
|
+
category_id: Joi137.string().hex().length(24).optional().allow("", null)
|
|
55325
|
+
});
|
|
55326
|
+
const { error, value } = schema2.validate(req.query, { abortEarly: false });
|
|
55327
|
+
if (error) {
|
|
55328
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
55329
|
+
logger188.log({ level: "error", message: messages });
|
|
55330
|
+
next(new BadRequestError215(messages));
|
|
55331
|
+
return;
|
|
55332
|
+
}
|
|
55333
|
+
try {
|
|
55334
|
+
const data = await _getAll(value);
|
|
55335
|
+
res.status(200).json({ data });
|
|
55336
|
+
return;
|
|
55337
|
+
} catch (error2) {
|
|
55338
|
+
logger188.log({ level: "error", message: error2.message });
|
|
55339
|
+
next(error2);
|
|
55340
|
+
return;
|
|
55341
|
+
}
|
|
55342
|
+
}
|
|
55343
|
+
return { getAll };
|
|
55344
|
+
}
|
|
55345
|
+
|
|
55346
|
+
// src/models/online-forms-v2.model.ts
|
|
55347
|
+
import Joi138 from "joi";
|
|
55348
|
+
import { ObjectId as ObjectId135 } from "mongodb";
|
|
55081
55349
|
var FormEntryStatus = /* @__PURE__ */ ((FormEntryStatus2) => {
|
|
55082
55350
|
FormEntryStatus2["ACTIVE"] = "active";
|
|
55083
55351
|
FormEntryStatus2["INACTIVE"] = "inactive";
|
|
55084
55352
|
FormEntryStatus2["DELETED"] = "deleted";
|
|
55085
55353
|
return FormEntryStatus2;
|
|
55086
55354
|
})(FormEntryStatus || {});
|
|
55087
|
-
var schemaFormEntry =
|
|
55088
|
-
_id:
|
|
55089
|
-
formType:
|
|
55090
|
-
fields:
|
|
55091
|
-
|
|
55092
|
-
|
|
55093
|
-
|
|
55094
|
-
|
|
55095
|
-
|
|
55096
|
-
|
|
55355
|
+
var schemaFormEntry = Joi138.object({
|
|
55356
|
+
_id: Joi138.string().hex().optional().allow("", null),
|
|
55357
|
+
formType: Joi138.string().required(),
|
|
55358
|
+
fields: Joi138.object().pattern(
|
|
55359
|
+
Joi138.string(),
|
|
55360
|
+
Joi138.alternatives().try(
|
|
55361
|
+
Joi138.string(),
|
|
55362
|
+
Joi138.number(),
|
|
55363
|
+
Joi138.boolean(),
|
|
55364
|
+
Joi138.valid(null)
|
|
55097
55365
|
)
|
|
55098
55366
|
).required(),
|
|
55099
|
-
status:
|
|
55100
|
-
org:
|
|
55101
|
-
site:
|
|
55102
|
-
createdAt:
|
|
55103
|
-
updatedAt:
|
|
55104
|
-
deletedAt:
|
|
55367
|
+
status: Joi138.string().optional().allow("", null),
|
|
55368
|
+
org: Joi138.string().hex().optional().allow("", null),
|
|
55369
|
+
site: Joi138.string().hex().optional().allow("", null),
|
|
55370
|
+
createdAt: Joi138.date().optional().allow("", null),
|
|
55371
|
+
updatedAt: Joi138.date().optional().allow("", null),
|
|
55372
|
+
deletedAt: Joi138.date().optional().allow("", null)
|
|
55105
55373
|
});
|
|
55106
|
-
var schemaUpdateFormEntry =
|
|
55107
|
-
_id:
|
|
55108
|
-
formType:
|
|
55109
|
-
fields:
|
|
55110
|
-
|
|
55111
|
-
|
|
55112
|
-
|
|
55113
|
-
|
|
55114
|
-
|
|
55115
|
-
|
|
55374
|
+
var schemaUpdateFormEntry = Joi138.object({
|
|
55375
|
+
_id: Joi138.string().hex().required(),
|
|
55376
|
+
formType: Joi138.string().optional().allow("", null),
|
|
55377
|
+
fields: Joi138.object().pattern(
|
|
55378
|
+
Joi138.string(),
|
|
55379
|
+
Joi138.alternatives().try(
|
|
55380
|
+
Joi138.string(),
|
|
55381
|
+
Joi138.number(),
|
|
55382
|
+
Joi138.boolean(),
|
|
55383
|
+
Joi138.valid(null)
|
|
55116
55384
|
)
|
|
55117
55385
|
).optional(),
|
|
55118
|
-
status:
|
|
55119
|
-
createdAt:
|
|
55120
|
-
updatedAt:
|
|
55121
|
-
deletedAt:
|
|
55386
|
+
status: Joi138.string().optional().allow("", null),
|
|
55387
|
+
createdAt: Joi138.date().optional().allow("", null),
|
|
55388
|
+
updatedAt: Joi138.date().optional().allow("", null),
|
|
55389
|
+
deletedAt: Joi138.date().optional().allow("", null)
|
|
55122
55390
|
});
|
|
55123
55391
|
function MFormEntry(value) {
|
|
55124
55392
|
const { error } = schemaFormEntry.validate(value);
|
|
@@ -55127,21 +55395,21 @@ function MFormEntry(value) {
|
|
|
55127
55395
|
}
|
|
55128
55396
|
if (value._id && typeof value._id === "string") {
|
|
55129
55397
|
try {
|
|
55130
|
-
value._id = new
|
|
55398
|
+
value._id = new ObjectId135(value._id);
|
|
55131
55399
|
} catch {
|
|
55132
55400
|
throw new Error("Invalid ID.");
|
|
55133
55401
|
}
|
|
55134
55402
|
}
|
|
55135
55403
|
if (value.org && typeof value.org === "string") {
|
|
55136
55404
|
try {
|
|
55137
|
-
value.org = new
|
|
55405
|
+
value.org = new ObjectId135(value.org);
|
|
55138
55406
|
} catch {
|
|
55139
55407
|
throw new Error("Invalid org ID.");
|
|
55140
55408
|
}
|
|
55141
55409
|
}
|
|
55142
55410
|
if (value.site && typeof value.site === "string") {
|
|
55143
55411
|
try {
|
|
55144
|
-
value.site = new
|
|
55412
|
+
value.site = new ObjectId135(value.site);
|
|
55145
55413
|
} catch {
|
|
55146
55414
|
throw new Error("Invalid site ID.");
|
|
55147
55415
|
}
|
|
@@ -55161,17 +55429,17 @@ function MFormEntry(value) {
|
|
|
55161
55429
|
|
|
55162
55430
|
// src/repositories/online-forms-v2.repository.ts
|
|
55163
55431
|
import {
|
|
55164
|
-
BadRequestError as
|
|
55165
|
-
InternalServerError as
|
|
55166
|
-
logger as
|
|
55167
|
-
useAtlas as
|
|
55432
|
+
BadRequestError as BadRequestError216,
|
|
55433
|
+
InternalServerError as InternalServerError77,
|
|
55434
|
+
logger as logger189,
|
|
55435
|
+
useAtlas as useAtlas120,
|
|
55168
55436
|
useCache as useCache69
|
|
55169
55437
|
} from "@7365admin1/node-server-utils";
|
|
55170
55438
|
var online_forms_namespace_collection = "online-forms";
|
|
55171
55439
|
function useFormEntryRepo() {
|
|
55172
|
-
const db =
|
|
55440
|
+
const db = useAtlas120.getDb();
|
|
55173
55441
|
if (!db) {
|
|
55174
|
-
throw new
|
|
55442
|
+
throw new InternalServerError77("Unable to connect to server.");
|
|
55175
55443
|
}
|
|
55176
55444
|
const collection = db.collection(online_forms_namespace_collection);
|
|
55177
55445
|
const { delNamespace, getCache, setCache } = useCache69(
|
|
@@ -55183,7 +55451,7 @@ function useFormEntryRepo() {
|
|
|
55183
55451
|
name: "text"
|
|
55184
55452
|
});
|
|
55185
55453
|
} catch (error) {
|
|
55186
|
-
throw new
|
|
55454
|
+
throw new InternalServerError77(
|
|
55187
55455
|
"Failed to create text index on online form."
|
|
55188
55456
|
);
|
|
55189
55457
|
}
|
|
@@ -55193,11 +55461,11 @@ function useFormEntryRepo() {
|
|
|
55193
55461
|
value = MFormEntry(value);
|
|
55194
55462
|
const res = await collection.insertOne(value, { session });
|
|
55195
55463
|
delNamespace().then(() => {
|
|
55196
|
-
|
|
55464
|
+
logger189.info(
|
|
55197
55465
|
`Cache cleared for namespace: ${online_forms_namespace_collection}`
|
|
55198
55466
|
);
|
|
55199
55467
|
}).catch((err) => {
|
|
55200
|
-
|
|
55468
|
+
logger189.error(
|
|
55201
55469
|
`Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
|
|
55202
55470
|
err
|
|
55203
55471
|
);
|
|
@@ -55206,7 +55474,7 @@ function useFormEntryRepo() {
|
|
|
55206
55474
|
} catch (error) {
|
|
55207
55475
|
const isDuplicated = error.message.includes("duplicate");
|
|
55208
55476
|
if (isDuplicated) {
|
|
55209
|
-
throw new
|
|
55477
|
+
throw new BadRequestError216("Online Form already exists.");
|
|
55210
55478
|
}
|
|
55211
55479
|
throw error;
|
|
55212
55480
|
}
|
|
@@ -55218,7 +55486,7 @@ function useFormEntryRepo() {
|
|
|
55218
55486
|
}
|
|
55219
55487
|
|
|
55220
55488
|
// src/controllers/online-forms-v2.controller.ts
|
|
55221
|
-
import { BadRequestError as
|
|
55489
|
+
import { BadRequestError as BadRequestError217, logger as logger190 } from "@7365admin1/node-server-utils";
|
|
55222
55490
|
import ExcelJS3 from "exceljs";
|
|
55223
55491
|
import fs5 from "fs";
|
|
55224
55492
|
function useFormEntryController() {
|
|
@@ -55236,14 +55504,14 @@ function useFormEntryController() {
|
|
|
55236
55504
|
async function uploadFormEntrys(req, res, next) {
|
|
55237
55505
|
try {
|
|
55238
55506
|
if (!req.file) {
|
|
55239
|
-
next(new
|
|
55507
|
+
next(new BadRequestError217("Excel file is required."));
|
|
55240
55508
|
return;
|
|
55241
55509
|
}
|
|
55242
55510
|
const workbook = new ExcelJS3.Workbook();
|
|
55243
55511
|
await workbook.xlsx.readFile(req.file.path);
|
|
55244
55512
|
const worksheet = workbook.worksheets[0];
|
|
55245
55513
|
if (!worksheet) {
|
|
55246
|
-
next(new
|
|
55514
|
+
next(new BadRequestError217("No worksheet found in uploaded Excel file."));
|
|
55247
55515
|
return;
|
|
55248
55516
|
}
|
|
55249
55517
|
const headerRow = worksheet.getRow(1);
|
|
@@ -55264,8 +55532,8 @@ function useFormEntryController() {
|
|
|
55264
55532
|
});
|
|
55265
55533
|
if (error) {
|
|
55266
55534
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
55267
|
-
|
|
55268
|
-
next(new
|
|
55535
|
+
logger190.log({ level: "error", message: messages });
|
|
55536
|
+
next(new BadRequestError217(messages));
|
|
55269
55537
|
return;
|
|
55270
55538
|
}
|
|
55271
55539
|
const result = await _add(value);
|
|
@@ -55273,7 +55541,7 @@ function useFormEntryController() {
|
|
|
55273
55541
|
fs5.unlink(req.file.path, () => {
|
|
55274
55542
|
});
|
|
55275
55543
|
} catch (error) {
|
|
55276
|
-
|
|
55544
|
+
logger190.log({ level: "error", message: error.message });
|
|
55277
55545
|
next(error);
|
|
55278
55546
|
}
|
|
55279
55547
|
}
|
|
@@ -55281,10 +55549,290 @@ function useFormEntryController() {
|
|
|
55281
55549
|
uploadFormEntrys
|
|
55282
55550
|
};
|
|
55283
55551
|
}
|
|
55552
|
+
|
|
55553
|
+
// src/models/building-level.model.ts
|
|
55554
|
+
import { BadRequestError as BadRequestError218 } from "@7365admin1/node-server-utils";
|
|
55555
|
+
import { ObjectId as ObjectId136 } from "mongodb";
|
|
55556
|
+
import Joi139 from "joi";
|
|
55557
|
+
import { logger as logger191 } from "@7365admin1/node-server-utils";
|
|
55558
|
+
var BuildingLevelStatus = /* @__PURE__ */ ((BuildingLevelStatus2) => {
|
|
55559
|
+
BuildingLevelStatus2["ACTIVE"] = "active";
|
|
55560
|
+
BuildingLevelStatus2["DELETED"] = "deleted";
|
|
55561
|
+
return BuildingLevelStatus2;
|
|
55562
|
+
})(BuildingLevelStatus || {});
|
|
55563
|
+
var schemaBuildingLevel = Joi139.object({
|
|
55564
|
+
org: Joi139.string().hex().optional(),
|
|
55565
|
+
site: Joi139.string().hex().optional(),
|
|
55566
|
+
blockId: Joi139.string().hex().optional(),
|
|
55567
|
+
name: Joi139.string().optional(),
|
|
55568
|
+
status: Joi139.string().valid(...Object.values(BuildingLevelStatus)).optional(),
|
|
55569
|
+
createdAt: Joi139.date().optional(),
|
|
55570
|
+
updatedAt: Joi139.date().optional().allow(null),
|
|
55571
|
+
deletedAt: Joi139.date().optional().allow(null)
|
|
55572
|
+
});
|
|
55573
|
+
function MBuildingLevel(value) {
|
|
55574
|
+
const { error } = schemaBuildingLevel.validate(value);
|
|
55575
|
+
if (error) {
|
|
55576
|
+
logger191.info(`Building Level Model: ${error.message}`);
|
|
55577
|
+
throw new BadRequestError218(error.message);
|
|
55578
|
+
}
|
|
55579
|
+
if (value.org && typeof value.org === "string") {
|
|
55580
|
+
try {
|
|
55581
|
+
value.org = new ObjectId136(value.org);
|
|
55582
|
+
} catch {
|
|
55583
|
+
throw new BadRequestError218("Invalid org ID format");
|
|
55584
|
+
}
|
|
55585
|
+
}
|
|
55586
|
+
if (value.site && typeof value.site === "string") {
|
|
55587
|
+
try {
|
|
55588
|
+
value.site = new ObjectId136(value.site);
|
|
55589
|
+
} catch {
|
|
55590
|
+
throw new BadRequestError218("Invalid site ID format");
|
|
55591
|
+
}
|
|
55592
|
+
}
|
|
55593
|
+
if (value.blockId && typeof value.blockId === "string") {
|
|
55594
|
+
try {
|
|
55595
|
+
value.blockId = new ObjectId136(value.blockId);
|
|
55596
|
+
} catch {
|
|
55597
|
+
throw new BadRequestError218("Invalid block ID format");
|
|
55598
|
+
}
|
|
55599
|
+
}
|
|
55600
|
+
return {
|
|
55601
|
+
_id: new ObjectId136(),
|
|
55602
|
+
org: value.org ?? void 0,
|
|
55603
|
+
site: value.site ?? void 0,
|
|
55604
|
+
blockId: value.blockId ?? void 0,
|
|
55605
|
+
name: value.name ?? "",
|
|
55606
|
+
status: value.status ?? "active" /* ACTIVE */,
|
|
55607
|
+
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
55608
|
+
updatedAt: value.updatedAt ?? null,
|
|
55609
|
+
deletedAt: value.deletedAt ?? null
|
|
55610
|
+
};
|
|
55611
|
+
}
|
|
55612
|
+
|
|
55613
|
+
// src/repositories/building-level.repository.ts
|
|
55614
|
+
import {
|
|
55615
|
+
AppError as AppError29,
|
|
55616
|
+
BadRequestError as BadRequestError219,
|
|
55617
|
+
logger as logger192,
|
|
55618
|
+
makeCacheKey as makeCacheKey66,
|
|
55619
|
+
paginate as paginate61,
|
|
55620
|
+
toObjectId as toObjectId20,
|
|
55621
|
+
useAtlas as useAtlas121,
|
|
55622
|
+
useCache as useCache70
|
|
55623
|
+
} from "@7365admin1/node-server-utils";
|
|
55624
|
+
var building_level_namespace_collection = "building-levels";
|
|
55625
|
+
function useBuildingLevelRepo() {
|
|
55626
|
+
const db = useAtlas121.getDb();
|
|
55627
|
+
if (!db) {
|
|
55628
|
+
throw new Error("Unable to connect to server.");
|
|
55629
|
+
}
|
|
55630
|
+
const collection = db.collection(building_level_namespace_collection);
|
|
55631
|
+
const { getCache, setCache, delNamespace, delCache } = useCache70(
|
|
55632
|
+
building_level_namespace_collection
|
|
55633
|
+
);
|
|
55634
|
+
function delCachedData() {
|
|
55635
|
+
delNamespace().then(() => {
|
|
55636
|
+
logger192.log({
|
|
55637
|
+
level: "info",
|
|
55638
|
+
message: `Cache namespace cleared for ${building_level_namespace_collection}`
|
|
55639
|
+
});
|
|
55640
|
+
}).catch((err) => {
|
|
55641
|
+
logger192.log({
|
|
55642
|
+
level: "error",
|
|
55643
|
+
message: `Failed to clear cache namespace for ${building_level_namespace_collection}: ${err.message}`
|
|
55644
|
+
});
|
|
55645
|
+
});
|
|
55646
|
+
}
|
|
55647
|
+
async function add(value, session) {
|
|
55648
|
+
try {
|
|
55649
|
+
value = MBuildingLevel(value);
|
|
55650
|
+
const res = await collection.insertOne(value, { session });
|
|
55651
|
+
delCachedData();
|
|
55652
|
+
return res.insertedId;
|
|
55653
|
+
} catch (error) {
|
|
55654
|
+
logger192.log({
|
|
55655
|
+
level: "error",
|
|
55656
|
+
message: error.message
|
|
55657
|
+
});
|
|
55658
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
55659
|
+
if (isDuplicated) {
|
|
55660
|
+
throw new BadRequestError219("Building unit already exists.");
|
|
55661
|
+
}
|
|
55662
|
+
if (error instanceof AppError29) {
|
|
55663
|
+
throw error;
|
|
55664
|
+
} else {
|
|
55665
|
+
throw new Error("Failed to create building unit.");
|
|
55666
|
+
}
|
|
55667
|
+
}
|
|
55668
|
+
}
|
|
55669
|
+
async function getAll({
|
|
55670
|
+
search = "",
|
|
55671
|
+
page = 1,
|
|
55672
|
+
limit = 10,
|
|
55673
|
+
sort = {},
|
|
55674
|
+
site = "",
|
|
55675
|
+
status = "active"
|
|
55676
|
+
} = {}) {
|
|
55677
|
+
page = page > 0 ? page - 1 : 0;
|
|
55678
|
+
const query = {
|
|
55679
|
+
status,
|
|
55680
|
+
...search && { $text: { $search: search } },
|
|
55681
|
+
...site && { site: toObjectId20(site) }
|
|
55682
|
+
};
|
|
55683
|
+
const cacheParams = {
|
|
55684
|
+
page,
|
|
55685
|
+
limit,
|
|
55686
|
+
sort: JSON.stringify(sort),
|
|
55687
|
+
...search && { search },
|
|
55688
|
+
...site && { site },
|
|
55689
|
+
...status && { status }
|
|
55690
|
+
};
|
|
55691
|
+
const cacheKey = makeCacheKey66(
|
|
55692
|
+
building_level_namespace_collection,
|
|
55693
|
+
cacheParams
|
|
55694
|
+
);
|
|
55695
|
+
logger192.log({
|
|
55696
|
+
level: "info",
|
|
55697
|
+
message: `Cache key for getAll building units: ${cacheKey}`
|
|
55698
|
+
});
|
|
55699
|
+
try {
|
|
55700
|
+
const cached = await getCache(cacheKey);
|
|
55701
|
+
if (cached) {
|
|
55702
|
+
logger192.log({
|
|
55703
|
+
level: "info",
|
|
55704
|
+
message: `Cache hit for getAll building units: ${cacheKey}`
|
|
55705
|
+
});
|
|
55706
|
+
return cached;
|
|
55707
|
+
}
|
|
55708
|
+
const sortStage = Object.keys(sort).length > 0 ? { $sort: sort } : { $sort: { latestDate: -1 } };
|
|
55709
|
+
const items = await collection.aggregate([
|
|
55710
|
+
{ $match: query },
|
|
55711
|
+
{
|
|
55712
|
+
$addFields: {
|
|
55713
|
+
latestDate: { $max: ["$updatedAt", "$createdAt"] }
|
|
55714
|
+
}
|
|
55715
|
+
},
|
|
55716
|
+
sortStage,
|
|
55717
|
+
{ $unset: "latestDate" },
|
|
55718
|
+
{ $skip: page * limit },
|
|
55719
|
+
{ $limit: limit }
|
|
55720
|
+
]).toArray();
|
|
55721
|
+
const length = await collection.countDocuments(query);
|
|
55722
|
+
const data = paginate61(items, page, limit, length);
|
|
55723
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
55724
|
+
logger192.log({
|
|
55725
|
+
level: "info",
|
|
55726
|
+
message: `Cache set for getAll building units: ${cacheKey}`
|
|
55727
|
+
});
|
|
55728
|
+
}).catch((err) => {
|
|
55729
|
+
logger192.log({
|
|
55730
|
+
level: "error",
|
|
55731
|
+
message: `Failed to set cache for getAll building units: ${err.message}`
|
|
55732
|
+
});
|
|
55733
|
+
});
|
|
55734
|
+
return data;
|
|
55735
|
+
} catch (error) {
|
|
55736
|
+
console.log(error);
|
|
55737
|
+
logger192.log({ level: "error", message: `${error}` });
|
|
55738
|
+
throw error;
|
|
55739
|
+
}
|
|
55740
|
+
}
|
|
55741
|
+
return {
|
|
55742
|
+
// createIndexes,
|
|
55743
|
+
add,
|
|
55744
|
+
getAll
|
|
55745
|
+
};
|
|
55746
|
+
}
|
|
55747
|
+
|
|
55748
|
+
// src/services/building-level.service.ts
|
|
55749
|
+
import { useAtlas as useAtlas122 } from "@7365admin1/node-server-utils";
|
|
55750
|
+
function useBuildingLevelService() {
|
|
55751
|
+
const { add: _add } = useBuildingLevelRepo();
|
|
55752
|
+
async function add(value) {
|
|
55753
|
+
const session = useAtlas122.getClient()?.startSession();
|
|
55754
|
+
try {
|
|
55755
|
+
session?.startTransaction();
|
|
55756
|
+
await _add(value, session);
|
|
55757
|
+
await session?.commitTransaction();
|
|
55758
|
+
return "Successfully added building level.";
|
|
55759
|
+
} catch (error) {
|
|
55760
|
+
await session?.abortTransaction();
|
|
55761
|
+
throw error;
|
|
55762
|
+
} finally {
|
|
55763
|
+
session?.endSession();
|
|
55764
|
+
}
|
|
55765
|
+
}
|
|
55766
|
+
return {
|
|
55767
|
+
add
|
|
55768
|
+
};
|
|
55769
|
+
}
|
|
55770
|
+
|
|
55771
|
+
// src/controllers/building-level.controller.ts
|
|
55772
|
+
import { BadRequestError as BadRequestError220, logger as logger193 } from "@7365admin1/node-server-utils";
|
|
55773
|
+
import Joi140 from "joi";
|
|
55774
|
+
function useBuildingLevelController() {
|
|
55775
|
+
const { add: _add } = useBuildingLevelService();
|
|
55776
|
+
const { getAll: _getAll } = useBuildingLevelRepo();
|
|
55777
|
+
async function add(req, res, next) {
|
|
55778
|
+
try {
|
|
55779
|
+
const { error, value } = schemaBuildingLevel.validate(req.body, {
|
|
55780
|
+
abortEarly: false
|
|
55781
|
+
});
|
|
55782
|
+
if (error) {
|
|
55783
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
55784
|
+
logger193.log({ level: "error", message: messages });
|
|
55785
|
+
next(new BadRequestError220(messages));
|
|
55786
|
+
return;
|
|
55787
|
+
}
|
|
55788
|
+
const result = await _add(value);
|
|
55789
|
+
res.status(201).json(result);
|
|
55790
|
+
} catch (error) {
|
|
55791
|
+
next(error);
|
|
55792
|
+
}
|
|
55793
|
+
}
|
|
55794
|
+
async function getAll(req, res, next) {
|
|
55795
|
+
try {
|
|
55796
|
+
const validation = Joi140.object({
|
|
55797
|
+
page: Joi140.number().min(1).optional().default(1),
|
|
55798
|
+
limit: Joi140.number().min(1).optional().default(20),
|
|
55799
|
+
search: Joi140.string().optional().allow("", null),
|
|
55800
|
+
site: Joi140.string().hex().length(24).optional().allow("", null),
|
|
55801
|
+
status: Joi140.string().valid(...Object.values(BuildingLevelStatus)).default("active" /* ACTIVE */)
|
|
55802
|
+
});
|
|
55803
|
+
const { error, value } = validation.validate(req.query, {
|
|
55804
|
+
abortEarly: false
|
|
55805
|
+
});
|
|
55806
|
+
if (error) {
|
|
55807
|
+
const messages = error.details.map((d) => d.message);
|
|
55808
|
+
logger193.log({ level: "error", message: messages.join(", ") });
|
|
55809
|
+
next(new BadRequestError220(messages.join(", ")));
|
|
55810
|
+
return;
|
|
55811
|
+
}
|
|
55812
|
+
const { page, limit, status, site, search } = value;
|
|
55813
|
+
const result = await _getAll({
|
|
55814
|
+
page,
|
|
55815
|
+
limit,
|
|
55816
|
+
status,
|
|
55817
|
+
site,
|
|
55818
|
+
search
|
|
55819
|
+
});
|
|
55820
|
+
res.json(result);
|
|
55821
|
+
return;
|
|
55822
|
+
} catch (error) {
|
|
55823
|
+
next(error);
|
|
55824
|
+
}
|
|
55825
|
+
}
|
|
55826
|
+
return {
|
|
55827
|
+
add,
|
|
55828
|
+
getAll
|
|
55829
|
+
};
|
|
55830
|
+
}
|
|
55284
55831
|
export {
|
|
55285
55832
|
ANPRMode,
|
|
55286
55833
|
AccessTypeProps,
|
|
55287
55834
|
AppServiceType,
|
|
55835
|
+
BuildingLevelStatus,
|
|
55288
55836
|
BuildingStatus,
|
|
55289
55837
|
BulletinOrder,
|
|
55290
55838
|
BulletinRecipient,
|
|
@@ -55318,9 +55866,11 @@ export {
|
|
|
55318
55866
|
MBillingConfiguration,
|
|
55319
55867
|
MBillingItem,
|
|
55320
55868
|
MBuilding,
|
|
55869
|
+
MBuildingLevel,
|
|
55321
55870
|
MBuildingUnit,
|
|
55322
55871
|
MBulletinBoard,
|
|
55323
55872
|
MBulletinVideo,
|
|
55873
|
+
MCategoryPreloved,
|
|
55324
55874
|
MChat,
|
|
55325
55875
|
MCustomer,
|
|
55326
55876
|
MCustomerSite,
|
|
@@ -55366,6 +55916,7 @@ export {
|
|
|
55366
55916
|
MSiteFacility,
|
|
55367
55917
|
MSiteFacilityBooking,
|
|
55368
55918
|
MStatementOfAccount,
|
|
55919
|
+
MSubcategoryPreloved,
|
|
55369
55920
|
MSubscription,
|
|
55370
55921
|
MUnitBilling,
|
|
55371
55922
|
MUser,
|
|
@@ -55413,6 +55964,7 @@ export {
|
|
|
55413
55964
|
allowedNatures,
|
|
55414
55965
|
attendanceSchema,
|
|
55415
55966
|
attendanceSettingsSchema,
|
|
55967
|
+
building_level_namespace_collection,
|
|
55416
55968
|
building_units_namespace_collection,
|
|
55417
55969
|
buildings_namespace_collection,
|
|
55418
55970
|
bulletin_boards_namespace_collection,
|
|
@@ -55457,10 +56009,12 @@ export {
|
|
|
55457
56009
|
schemaBillingConfiguration,
|
|
55458
56010
|
schemaBillingItem,
|
|
55459
56011
|
schemaBuilding,
|
|
56012
|
+
schemaBuildingLevel,
|
|
55460
56013
|
schemaBuildingUnit,
|
|
55461
56014
|
schemaBuildingUpdateOptions,
|
|
55462
56015
|
schemaBulletinBoard,
|
|
55463
56016
|
schemaBulletinVideo,
|
|
56017
|
+
schemaCategoryPreloved,
|
|
55464
56018
|
schemaCustomerSite,
|
|
55465
56019
|
schemaDocumentManagement,
|
|
55466
56020
|
schemaEntryPassSettings,
|
|
@@ -55491,9 +56045,11 @@ export {
|
|
|
55491
56045
|
schemaSiteFacility,
|
|
55492
56046
|
schemaSiteFacilityBooking,
|
|
55493
56047
|
schemaStatementOfAccount,
|
|
56048
|
+
schemaSubcategoryPreloved,
|
|
55494
56049
|
schemaUnitBilling,
|
|
55495
56050
|
schemaUpdateBulletinBoard,
|
|
55496
56051
|
schemaUpdateBulletinVideo,
|
|
56052
|
+
schemaUpdateCategoryPreloved,
|
|
55497
56053
|
schemaUpdateDocumentManagement,
|
|
55498
56054
|
schemaUpdateEntryPassSettings,
|
|
55499
56055
|
schemaUpdateEventManagement,
|
|
@@ -55519,6 +56075,7 @@ export {
|
|
|
55519
56075
|
schemaUpdateSiteFacilityBooking,
|
|
55520
56076
|
schemaUpdateSiteUnitBilling,
|
|
55521
56077
|
schemaUpdateStatementOfAccount,
|
|
56078
|
+
schemaUpdateSubcategoryPreloved,
|
|
55522
56079
|
schemaUpdateVisTrans,
|
|
55523
56080
|
schemaVehicleTransaction,
|
|
55524
56081
|
schemaVisitorTransaction,
|
|
@@ -55544,6 +56101,9 @@ export {
|
|
|
55544
56101
|
useAuthService,
|
|
55545
56102
|
useAuthServiceV2,
|
|
55546
56103
|
useBuildingController,
|
|
56104
|
+
useBuildingLevelController,
|
|
56105
|
+
useBuildingLevelRepo,
|
|
56106
|
+
useBuildingLevelService,
|
|
55547
56107
|
useBuildingRepo,
|
|
55548
56108
|
useBuildingService,
|
|
55549
56109
|
useBuildingUnitController,
|
|
@@ -55555,6 +56115,8 @@ export {
|
|
|
55555
56115
|
useBulletinVideoController,
|
|
55556
56116
|
useBulletinVideoRepo,
|
|
55557
56117
|
useBulletinVideoService,
|
|
56118
|
+
useCategoryPrelovedController,
|
|
56119
|
+
useCategoryPrelovedRepo,
|
|
55558
56120
|
useChatController,
|
|
55559
56121
|
useChatRepo,
|
|
55560
56122
|
useCounterModel,
|
|
@@ -55692,6 +56254,8 @@ export {
|
|
|
55692
56254
|
useSiteUnitBillingService,
|
|
55693
56255
|
useStatementOfAccountController,
|
|
55694
56256
|
useStatementOfAccountRepo,
|
|
56257
|
+
useSubcategoryPrelovedController,
|
|
56258
|
+
useSubcategoryPrelovedRepo,
|
|
55695
56259
|
useSubscriptionController,
|
|
55696
56260
|
useSubscriptionRepo,
|
|
55697
56261
|
useSubscriptionService,
|