@7365admin1/core 2.81.0 → 2.83.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 +41 -4
- package/dist/index.js +456 -149
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +453 -147
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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 logger198 = {
|
|
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(logger198.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 = logger198.lookupLevel(level);
|
|
557
|
+
if (typeof console !== "undefined" && logger198.lookupLevel(logger198.level) <= level) {
|
|
558
|
+
var method = logger198.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"] = logger198;
|
|
570
570
|
module2.exports = exports["default"];
|
|
571
571
|
}
|
|
572
572
|
});
|
|
@@ -5931,6 +5931,7 @@ __export(src_exports, {
|
|
|
5931
5931
|
MBulletinBoard: () => MBulletinBoard,
|
|
5932
5932
|
MBulletinVideo: () => MBulletinVideo,
|
|
5933
5933
|
MCategoryPreloved: () => MCategoryPreloved,
|
|
5934
|
+
MChannelPreloved: () => MChannelPreloved,
|
|
5934
5935
|
MChat: () => MChat,
|
|
5935
5936
|
MChatPreloved: () => MChatPreloved,
|
|
5936
5937
|
MCustomer: () => MCustomer,
|
|
@@ -6077,6 +6078,7 @@ __export(src_exports, {
|
|
|
6077
6078
|
schemaBulletinBoard: () => schemaBulletinBoard,
|
|
6078
6079
|
schemaBulletinVideo: () => schemaBulletinVideo,
|
|
6079
6080
|
schemaCategoryPreloved: () => schemaCategoryPreloved,
|
|
6081
|
+
schemaChannelPreloved: () => schemaChannelPreloved,
|
|
6080
6082
|
schemaChatPreloved: () => schemaChatPreloved,
|
|
6081
6083
|
schemaCustomerSite: () => schemaCustomerSite,
|
|
6082
6084
|
schemaDocumentManagement: () => schemaDocumentManagement,
|
|
@@ -6185,6 +6187,8 @@ __export(src_exports, {
|
|
|
6185
6187
|
useBulletinVideoService: () => useBulletinVideoService,
|
|
6186
6188
|
useCategoryPrelovedController: () => useCategoryPrelovedController,
|
|
6187
6189
|
useCategoryPrelovedRepo: () => useCategoryPrelovedRepo,
|
|
6190
|
+
useChannelPrelovedController: () => useChannelPrelovedController,
|
|
6191
|
+
useChannelPrelovedRepo: () => useChannelPrelovedRepo,
|
|
6188
6192
|
useChatController: () => useChatController,
|
|
6189
6193
|
useChatPrelovedController: () => useChatPrelovedController,
|
|
6190
6194
|
useChatPrelovedRepo: () => useChatPrelovedRepo,
|
|
@@ -9477,27 +9481,23 @@ function useMemberRepo() {
|
|
|
9477
9481
|
limit = 10,
|
|
9478
9482
|
user = "",
|
|
9479
9483
|
org = "",
|
|
9484
|
+
siteId = "",
|
|
9480
9485
|
type = "",
|
|
9481
9486
|
status = ""
|
|
9482
9487
|
}) {
|
|
9483
9488
|
limit = limit > 0 ? limit : 10;
|
|
9484
9489
|
search = search || "";
|
|
9485
9490
|
page = page > 0 ? page - 1 : 0;
|
|
9486
|
-
const query = {
|
|
9491
|
+
const query = {
|
|
9492
|
+
type,
|
|
9493
|
+
status
|
|
9494
|
+
};
|
|
9487
9495
|
const cacheOptions = {
|
|
9488
9496
|
page,
|
|
9489
9497
|
limit,
|
|
9490
9498
|
type,
|
|
9491
9499
|
status
|
|
9492
9500
|
};
|
|
9493
|
-
if (user) {
|
|
9494
|
-
try {
|
|
9495
|
-
query.user = new import_mongodb11.ObjectId(user);
|
|
9496
|
-
cacheOptions.user = user.toString();
|
|
9497
|
-
} catch (error) {
|
|
9498
|
-
throw new import_node_server_utils12.BadRequestError("Invalid user ID format.");
|
|
9499
|
-
}
|
|
9500
|
-
}
|
|
9501
9501
|
if (org) {
|
|
9502
9502
|
try {
|
|
9503
9503
|
query.org = new import_mongodb11.ObjectId(org);
|
|
@@ -9506,6 +9506,22 @@ function useMemberRepo() {
|
|
|
9506
9506
|
throw new import_node_server_utils12.BadRequestError("Invalid organization ID format.");
|
|
9507
9507
|
}
|
|
9508
9508
|
}
|
|
9509
|
+
if (siteId) {
|
|
9510
|
+
try {
|
|
9511
|
+
query.siteId = new import_mongodb11.ObjectId(siteId);
|
|
9512
|
+
cacheOptions.siteId = siteId.toString();
|
|
9513
|
+
} catch (error) {
|
|
9514
|
+
throw new import_node_server_utils12.BadRequestError("Invalid site ID format.");
|
|
9515
|
+
}
|
|
9516
|
+
}
|
|
9517
|
+
if (user) {
|
|
9518
|
+
try {
|
|
9519
|
+
query.user = new import_mongodb11.ObjectId(user);
|
|
9520
|
+
cacheOptions.user = user.toString();
|
|
9521
|
+
} catch (error) {
|
|
9522
|
+
throw new import_node_server_utils12.BadRequestError("Invalid user ID format.");
|
|
9523
|
+
}
|
|
9524
|
+
}
|
|
9509
9525
|
if (search) {
|
|
9510
9526
|
query.$text = { $search: search };
|
|
9511
9527
|
cacheOptions.search = search;
|
|
@@ -14413,6 +14429,7 @@ function useMemberController() {
|
|
|
14413
14429
|
limit: import_joi15.default.number().integer().min(1).max(50).allow("", null).default(10),
|
|
14414
14430
|
user: import_joi15.default.string().hex().optional().allow("", null),
|
|
14415
14431
|
org: import_joi15.default.string().hex().optional().allow("", null),
|
|
14432
|
+
siteId: import_joi15.default.string().hex().optional().allow("", null),
|
|
14416
14433
|
type: import_joi15.default.string().required(),
|
|
14417
14434
|
status: import_joi15.default.string().required()
|
|
14418
14435
|
});
|
|
@@ -14428,6 +14445,7 @@ function useMemberController() {
|
|
|
14428
14445
|
const limit = parseInt(req.query.limit ?? "10");
|
|
14429
14446
|
const user = req.query.user ?? "";
|
|
14430
14447
|
const org = req.query.org ?? "";
|
|
14448
|
+
const siteId = req.query.siteId ?? "";
|
|
14431
14449
|
const type = req.query.type ?? "main";
|
|
14432
14450
|
const status = req.query.status ?? "active";
|
|
14433
14451
|
try {
|
|
@@ -14437,6 +14455,7 @@ function useMemberController() {
|
|
|
14437
14455
|
limit,
|
|
14438
14456
|
user,
|
|
14439
14457
|
org,
|
|
14458
|
+
siteId,
|
|
14440
14459
|
type,
|
|
14441
14460
|
status
|
|
14442
14461
|
});
|
|
@@ -30129,12 +30148,91 @@ function useCustomerSiteRepo() {
|
|
|
30129
30148
|
} catch (error) {
|
|
30130
30149
|
}
|
|
30131
30150
|
}
|
|
30151
|
+
async function getById(id) {
|
|
30152
|
+
try {
|
|
30153
|
+
id = new import_mongodb54.ObjectId(id);
|
|
30154
|
+
} catch {
|
|
30155
|
+
throw new import_node_server_utils94.BadRequestError("Invalid ID.");
|
|
30156
|
+
}
|
|
30157
|
+
const data = await collection.findOne({
|
|
30158
|
+
_id: id
|
|
30159
|
+
});
|
|
30160
|
+
if (!data) {
|
|
30161
|
+
throw new import_node_server_utils94.BadRequestError("Customer site not found.");
|
|
30162
|
+
}
|
|
30163
|
+
return data;
|
|
30164
|
+
}
|
|
30165
|
+
async function updateCustomerSiteById(id, payload, session) {
|
|
30166
|
+
try {
|
|
30167
|
+
id = new import_mongodb54.ObjectId(id);
|
|
30168
|
+
} catch {
|
|
30169
|
+
throw new import_node_server_utils94.BadRequestError("Invalid ID.");
|
|
30170
|
+
}
|
|
30171
|
+
delete payload._id;
|
|
30172
|
+
const result = await collection.findOneAndUpdate(
|
|
30173
|
+
{ _id: id, status: "active" },
|
|
30174
|
+
{
|
|
30175
|
+
$set: {
|
|
30176
|
+
...payload,
|
|
30177
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
30178
|
+
}
|
|
30179
|
+
},
|
|
30180
|
+
{
|
|
30181
|
+
returnDocument: "after",
|
|
30182
|
+
session
|
|
30183
|
+
}
|
|
30184
|
+
);
|
|
30185
|
+
if (!result) {
|
|
30186
|
+
throw new import_node_server_utils94.BadRequestError("Customer site not found.");
|
|
30187
|
+
}
|
|
30188
|
+
delNamespace().then(() => {
|
|
30189
|
+
import_node_server_utils94.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
30190
|
+
}).catch((err) => {
|
|
30191
|
+
import_node_server_utils94.logger.error(`Failed to clear cache for namespace: ${namespace_collection}`, err);
|
|
30192
|
+
});
|
|
30193
|
+
return result;
|
|
30194
|
+
}
|
|
30195
|
+
async function deleteById(id, session) {
|
|
30196
|
+
try {
|
|
30197
|
+
id = new import_mongodb54.ObjectId(id);
|
|
30198
|
+
} catch {
|
|
30199
|
+
throw new import_node_server_utils94.BadRequestError("Invalid ID.");
|
|
30200
|
+
}
|
|
30201
|
+
const result = await collection.findOneAndUpdate(
|
|
30202
|
+
{
|
|
30203
|
+
_id: id,
|
|
30204
|
+
status: { $ne: "deleted" }
|
|
30205
|
+
},
|
|
30206
|
+
{
|
|
30207
|
+
$set: {
|
|
30208
|
+
status: "deleted",
|
|
30209
|
+
deletedAt: /* @__PURE__ */ new Date()
|
|
30210
|
+
}
|
|
30211
|
+
},
|
|
30212
|
+
{
|
|
30213
|
+
returnDocument: "after",
|
|
30214
|
+
session
|
|
30215
|
+
}
|
|
30216
|
+
);
|
|
30217
|
+
if (!result) {
|
|
30218
|
+
throw new import_node_server_utils94.BadRequestError("Customer site not found.");
|
|
30219
|
+
}
|
|
30220
|
+
delNamespace().then(() => {
|
|
30221
|
+
import_node_server_utils94.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
30222
|
+
}).catch((err) => {
|
|
30223
|
+
import_node_server_utils94.logger.error(`Failed to clear cache for namespace: ${namespace_collection}`, err);
|
|
30224
|
+
});
|
|
30225
|
+
return result;
|
|
30226
|
+
}
|
|
30132
30227
|
return {
|
|
30133
30228
|
createIndexes,
|
|
30134
30229
|
add,
|
|
30135
30230
|
getAll,
|
|
30136
30231
|
getByName,
|
|
30137
|
-
getBySiteAsServiceProvider
|
|
30232
|
+
getBySiteAsServiceProvider,
|
|
30233
|
+
getById,
|
|
30234
|
+
updateCustomerSiteById,
|
|
30235
|
+
deleteById
|
|
30138
30236
|
};
|
|
30139
30237
|
}
|
|
30140
30238
|
|
|
@@ -30142,12 +30240,13 @@ function useCustomerSiteRepo() {
|
|
|
30142
30240
|
var import_node_server_utils95 = require("@7365admin1/node-server-utils");
|
|
30143
30241
|
var import_fast_levenshtein = __toESM(require("fast-levenshtein"));
|
|
30144
30242
|
function useCustomerSiteService() {
|
|
30145
|
-
const { add: _add } = useCustomerSiteRepo();
|
|
30243
|
+
const { add: _add, updateCustomerSiteById, getById: _getById } = useCustomerSiteRepo();
|
|
30146
30244
|
const {
|
|
30147
30245
|
getByName: getSiteByName,
|
|
30148
30246
|
getByExactName: getSiteByExactName,
|
|
30149
30247
|
createSite,
|
|
30150
|
-
getSiteById
|
|
30248
|
+
getSiteById,
|
|
30249
|
+
updateSiteById
|
|
30151
30250
|
} = useSiteRepo();
|
|
30152
30251
|
const {
|
|
30153
30252
|
getById: _getByOrgId,
|
|
@@ -30278,9 +30377,47 @@ function useCustomerSiteService() {
|
|
|
30278
30377
|
session?.endSession();
|
|
30279
30378
|
}
|
|
30280
30379
|
}
|
|
30380
|
+
async function updateCusSiteById(customerSiteId, payload) {
|
|
30381
|
+
const session = import_node_server_utils95.useAtlas.getClient()?.startSession();
|
|
30382
|
+
session?.startTransaction();
|
|
30383
|
+
try {
|
|
30384
|
+
const customerSite = await _getById(customerSiteId);
|
|
30385
|
+
if (!customerSite) {
|
|
30386
|
+
throw new import_node_server_utils95.NotFoundError("Customer site not found.");
|
|
30387
|
+
}
|
|
30388
|
+
const siteId = customerSite.site;
|
|
30389
|
+
await updateSiteById(
|
|
30390
|
+
siteId,
|
|
30391
|
+
{
|
|
30392
|
+
...payload.name !== void 0 && { name: payload.name },
|
|
30393
|
+
...payload.address !== void 0 && { address: payload.address },
|
|
30394
|
+
...payload.category !== void 0 && { category: payload.category }
|
|
30395
|
+
},
|
|
30396
|
+
session
|
|
30397
|
+
);
|
|
30398
|
+
const safePayload = {
|
|
30399
|
+
...payload.name !== void 0 && { name: payload.name },
|
|
30400
|
+
...payload.address !== void 0 && { address: payload.address },
|
|
30401
|
+
...payload.category !== void 0 && { category: payload.category }
|
|
30402
|
+
};
|
|
30403
|
+
const result = await updateCustomerSiteById(
|
|
30404
|
+
customerSiteId,
|
|
30405
|
+
safePayload,
|
|
30406
|
+
session
|
|
30407
|
+
);
|
|
30408
|
+
await session?.commitTransaction();
|
|
30409
|
+
return result;
|
|
30410
|
+
} catch (error) {
|
|
30411
|
+
await session?.abortTransaction();
|
|
30412
|
+
throw error;
|
|
30413
|
+
} finally {
|
|
30414
|
+
await session?.endSession();
|
|
30415
|
+
}
|
|
30416
|
+
}
|
|
30281
30417
|
return {
|
|
30282
30418
|
add,
|
|
30283
|
-
addViaInvite
|
|
30419
|
+
addViaInvite,
|
|
30420
|
+
updateCusSiteById
|
|
30284
30421
|
};
|
|
30285
30422
|
}
|
|
30286
30423
|
|
|
@@ -30290,9 +30427,11 @@ var import_node_server_utils96 = require("@7365admin1/node-server-utils");
|
|
|
30290
30427
|
function useCustomerSiteController() {
|
|
30291
30428
|
const {
|
|
30292
30429
|
getAll: _getAll,
|
|
30293
|
-
getBySiteAsServiceProvider: _getBySiteAsServiceProvider
|
|
30430
|
+
getBySiteAsServiceProvider: _getBySiteAsServiceProvider,
|
|
30431
|
+
getById: _getById,
|
|
30432
|
+
deleteById: _deleteById
|
|
30294
30433
|
} = useCustomerSiteRepo();
|
|
30295
|
-
const { add: _add, addViaInvite: _addViaInvite } = useCustomerSiteService();
|
|
30434
|
+
const { add: _add, addViaInvite: _addViaInvite, updateCusSiteById: _updateCusSiteById } = useCustomerSiteService();
|
|
30296
30435
|
async function add(req, res, next) {
|
|
30297
30436
|
const { error, value } = schemaCustomerSite.validate(req.body);
|
|
30298
30437
|
if (error) {
|
|
@@ -30409,11 +30548,63 @@ function useCustomerSiteController() {
|
|
|
30409
30548
|
return;
|
|
30410
30549
|
}
|
|
30411
30550
|
}
|
|
30551
|
+
async function getById(req, res, next) {
|
|
30552
|
+
const validation = import_joi52.default.object({
|
|
30553
|
+
id: import_joi52.default.string().hex().required()
|
|
30554
|
+
});
|
|
30555
|
+
const id = req.params.id;
|
|
30556
|
+
const { error } = validation.validate({ id });
|
|
30557
|
+
if (error) {
|
|
30558
|
+
next(new import_node_server_utils96.BadRequestError(error.message));
|
|
30559
|
+
return;
|
|
30560
|
+
}
|
|
30561
|
+
try {
|
|
30562
|
+
const data = await _getById(id);
|
|
30563
|
+
res.json(data);
|
|
30564
|
+
return;
|
|
30565
|
+
} catch (error2) {
|
|
30566
|
+
next(error2);
|
|
30567
|
+
return;
|
|
30568
|
+
}
|
|
30569
|
+
}
|
|
30570
|
+
async function updateById(req, res, next) {
|
|
30571
|
+
const validation = import_joi52.default.object({
|
|
30572
|
+
id: import_joi52.default.string().hex().required()
|
|
30573
|
+
});
|
|
30574
|
+
const id = req.params.id;
|
|
30575
|
+
const { error } = validation.validate({ id });
|
|
30576
|
+
if (error) {
|
|
30577
|
+
next(new import_node_server_utils96.BadRequestError(error.message));
|
|
30578
|
+
return;
|
|
30579
|
+
}
|
|
30580
|
+
try {
|
|
30581
|
+
const data = await _updateCusSiteById(id, req.body);
|
|
30582
|
+
res.json(data);
|
|
30583
|
+
return;
|
|
30584
|
+
} catch (error2) {
|
|
30585
|
+
next(error2);
|
|
30586
|
+
return;
|
|
30587
|
+
}
|
|
30588
|
+
}
|
|
30589
|
+
async function deleteById(req, res, next) {
|
|
30590
|
+
const id = req.params.id;
|
|
30591
|
+
try {
|
|
30592
|
+
const data = await _deleteById(id);
|
|
30593
|
+
res.json(data);
|
|
30594
|
+
return;
|
|
30595
|
+
} catch (error) {
|
|
30596
|
+
next(error);
|
|
30597
|
+
return;
|
|
30598
|
+
}
|
|
30599
|
+
}
|
|
30412
30600
|
return {
|
|
30413
30601
|
add,
|
|
30414
30602
|
getAll,
|
|
30415
30603
|
addViaInvite,
|
|
30416
|
-
getBySiteAsServiceProvider
|
|
30604
|
+
getBySiteAsServiceProvider,
|
|
30605
|
+
getById,
|
|
30606
|
+
updateById,
|
|
30607
|
+
deleteById
|
|
30417
30608
|
};
|
|
30418
30609
|
}
|
|
30419
30610
|
|
|
@@ -63556,57 +63747,142 @@ function useChatPrelovedController() {
|
|
|
63556
63747
|
return { add, updateById, deleteById };
|
|
63557
63748
|
}
|
|
63558
63749
|
|
|
63559
|
-
// src/models/
|
|
63750
|
+
// src/models/channel-preloved.model.ts
|
|
63560
63751
|
var import_joi143 = __toESM(require("joi"));
|
|
63561
63752
|
var import_mongodb143 = require("mongodb");
|
|
63753
|
+
var schemaChannelPreloved = import_joi143.default.object({
|
|
63754
|
+
receiverId: import_joi143.default.string().hex().length(24).required(),
|
|
63755
|
+
senderId: import_joi143.default.string().hex().length(24).required(),
|
|
63756
|
+
postId: import_joi143.default.string().hex().length(24).required()
|
|
63757
|
+
});
|
|
63758
|
+
function toObjectId22(value, label) {
|
|
63759
|
+
if (typeof value === "string") {
|
|
63760
|
+
try {
|
|
63761
|
+
return new import_mongodb143.ObjectId(value);
|
|
63762
|
+
} catch {
|
|
63763
|
+
throw new Error(`Invalid ${label}.`);
|
|
63764
|
+
}
|
|
63765
|
+
}
|
|
63766
|
+
return value;
|
|
63767
|
+
}
|
|
63768
|
+
function MChannelPreloved(value) {
|
|
63769
|
+
const { error } = schemaChannelPreloved.validate(value);
|
|
63770
|
+
if (error)
|
|
63771
|
+
throw new Error(error.details[0].message);
|
|
63772
|
+
if (value.receiverId)
|
|
63773
|
+
value.receiverId = toObjectId22(value.receiverId, "receiver ID");
|
|
63774
|
+
if (value.senderId)
|
|
63775
|
+
value.senderId = toObjectId22(value.senderId, "sender ID");
|
|
63776
|
+
if (value.postId)
|
|
63777
|
+
value.postId = toObjectId22(value.postId, "post ID");
|
|
63778
|
+
return {
|
|
63779
|
+
_id: new import_mongodb143.ObjectId(),
|
|
63780
|
+
name: `seven365-${(/* @__PURE__ */ new Date()).getTime()}`,
|
|
63781
|
+
receiverId: value.receiverId,
|
|
63782
|
+
senderId: value.senderId,
|
|
63783
|
+
postId: value.postId,
|
|
63784
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
63785
|
+
updatedAt: null
|
|
63786
|
+
};
|
|
63787
|
+
}
|
|
63788
|
+
|
|
63789
|
+
// src/repositories/channel-preloved.repo.ts
|
|
63790
|
+
var import_node_server_utils247 = require("@7365admin1/node-server-utils");
|
|
63791
|
+
function useChannelPrelovedRepo() {
|
|
63792
|
+
const db = import_node_server_utils247.useAtlas.getDb();
|
|
63793
|
+
if (!db)
|
|
63794
|
+
throw new import_node_server_utils247.InternalServerError("Unable to connect to server.");
|
|
63795
|
+
const CHANNEL_COLLECTION = "channel-preloved";
|
|
63796
|
+
const collection = db.collection(CHANNEL_COLLECTION);
|
|
63797
|
+
async function add(value, session) {
|
|
63798
|
+
try {
|
|
63799
|
+
const doc = MChannelPreloved(value);
|
|
63800
|
+
const res = await collection.insertOne(doc, { session });
|
|
63801
|
+
return res.insertedId;
|
|
63802
|
+
} catch (error) {
|
|
63803
|
+
throw error;
|
|
63804
|
+
}
|
|
63805
|
+
}
|
|
63806
|
+
return { add };
|
|
63807
|
+
}
|
|
63808
|
+
|
|
63809
|
+
// src/controllers/channel-preloved.controller.ts
|
|
63810
|
+
var import_node_server_utils248 = require("@7365admin1/node-server-utils");
|
|
63811
|
+
function useChannelPrelovedController() {
|
|
63812
|
+
const { add: _add } = useChannelPrelovedRepo();
|
|
63813
|
+
async function add(req, res, next) {
|
|
63814
|
+
const { error, value } = schemaChannelPreloved.validate(req.body, {
|
|
63815
|
+
abortEarly: false
|
|
63816
|
+
});
|
|
63817
|
+
if (error) {
|
|
63818
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
63819
|
+
import_node_server_utils248.logger.log({ level: "error", message: messages });
|
|
63820
|
+
next(new import_node_server_utils248.BadRequestError(messages));
|
|
63821
|
+
return;
|
|
63822
|
+
}
|
|
63823
|
+
try {
|
|
63824
|
+
const data = await _add(value);
|
|
63825
|
+
res.status(201).json(data);
|
|
63826
|
+
} catch (error2) {
|
|
63827
|
+
import_node_server_utils248.logger.log({ level: "error", message: error2.message });
|
|
63828
|
+
next(error2);
|
|
63829
|
+
}
|
|
63830
|
+
}
|
|
63831
|
+
return { add };
|
|
63832
|
+
}
|
|
63833
|
+
|
|
63834
|
+
// src/models/online-forms-v2.model.ts
|
|
63835
|
+
var import_joi144 = __toESM(require("joi"));
|
|
63836
|
+
var import_mongodb144 = require("mongodb");
|
|
63562
63837
|
var FormEntryStatus = /* @__PURE__ */ ((FormEntryStatus2) => {
|
|
63563
63838
|
FormEntryStatus2["ACTIVE"] = "active";
|
|
63564
63839
|
FormEntryStatus2["INACTIVE"] = "inactive";
|
|
63565
63840
|
FormEntryStatus2["DELETED"] = "deleted";
|
|
63566
63841
|
return FormEntryStatus2;
|
|
63567
63842
|
})(FormEntryStatus || {});
|
|
63568
|
-
var schemaFormEntry =
|
|
63569
|
-
_id:
|
|
63570
|
-
formType:
|
|
63571
|
-
block:
|
|
63572
|
-
level:
|
|
63573
|
-
unit:
|
|
63574
|
-
name:
|
|
63575
|
-
phoneNumber:
|
|
63576
|
-
|
|
63577
|
-
|
|
63578
|
-
|
|
63579
|
-
|
|
63580
|
-
|
|
63581
|
-
|
|
63582
|
-
|
|
63843
|
+
var schemaFormEntry = import_joi144.default.object({
|
|
63844
|
+
_id: import_joi144.default.string().hex().optional().allow("", null),
|
|
63845
|
+
formType: import_joi144.default.string().required(),
|
|
63846
|
+
block: import_joi144.default.string().optional().allow(null, ""),
|
|
63847
|
+
level: import_joi144.default.string().optional().allow(null, ""),
|
|
63848
|
+
unit: import_joi144.default.string().optional().allow(null, ""),
|
|
63849
|
+
name: import_joi144.default.string().optional().allow(null, ""),
|
|
63850
|
+
phoneNumber: import_joi144.default.string().optional().allow(null, ""),
|
|
63851
|
+
createdBy: import_joi144.default.string().required(),
|
|
63852
|
+
fields: import_joi144.default.object().pattern(
|
|
63853
|
+
import_joi144.default.string(),
|
|
63854
|
+
import_joi144.default.alternatives().try(
|
|
63855
|
+
import_joi144.default.string(),
|
|
63856
|
+
import_joi144.default.number(),
|
|
63857
|
+
import_joi144.default.boolean(),
|
|
63858
|
+
import_joi144.default.valid(null)
|
|
63583
63859
|
)
|
|
63584
63860
|
).required(),
|
|
63585
|
-
status:
|
|
63586
|
-
org:
|
|
63587
|
-
site:
|
|
63588
|
-
createdAt:
|
|
63589
|
-
updatedAt:
|
|
63590
|
-
deletedAt:
|
|
63861
|
+
status: import_joi144.default.string().optional().allow("", null),
|
|
63862
|
+
org: import_joi144.default.string().hex().optional().allow("", null),
|
|
63863
|
+
site: import_joi144.default.string().hex().optional().allow("", null),
|
|
63864
|
+
createdAt: import_joi144.default.date().optional().allow("", null),
|
|
63865
|
+
updatedAt: import_joi144.default.date().optional().allow("", null),
|
|
63866
|
+
deletedAt: import_joi144.default.date().optional().allow("", null)
|
|
63591
63867
|
});
|
|
63592
|
-
var schemaUpdateFormEntry =
|
|
63593
|
-
_id:
|
|
63594
|
-
formType:
|
|
63595
|
-
block:
|
|
63596
|
-
level:
|
|
63597
|
-
unit:
|
|
63598
|
-
fields:
|
|
63599
|
-
|
|
63600
|
-
|
|
63601
|
-
|
|
63602
|
-
|
|
63603
|
-
|
|
63604
|
-
|
|
63868
|
+
var schemaUpdateFormEntry = import_joi144.default.object({
|
|
63869
|
+
_id: import_joi144.default.string().hex().required(),
|
|
63870
|
+
formType: import_joi144.default.string().optional().allow("", null),
|
|
63871
|
+
block: import_joi144.default.string().optional().allow(null, ""),
|
|
63872
|
+
level: import_joi144.default.string().optional().allow(null, ""),
|
|
63873
|
+
unit: import_joi144.default.string().optional().allow(null, ""),
|
|
63874
|
+
fields: import_joi144.default.object().pattern(
|
|
63875
|
+
import_joi144.default.string(),
|
|
63876
|
+
import_joi144.default.alternatives().try(
|
|
63877
|
+
import_joi144.default.string(),
|
|
63878
|
+
import_joi144.default.number(),
|
|
63879
|
+
import_joi144.default.boolean(),
|
|
63880
|
+
import_joi144.default.valid(null)
|
|
63605
63881
|
)
|
|
63606
63882
|
).optional(),
|
|
63607
|
-
status:
|
|
63608
|
-
updatedAt:
|
|
63609
|
-
deletedAt:
|
|
63883
|
+
status: import_joi144.default.string().optional().allow("", null),
|
|
63884
|
+
updatedAt: import_joi144.default.date().optional().allow("", null),
|
|
63885
|
+
deletedAt: import_joi144.default.date().optional().allow("", null)
|
|
63610
63886
|
});
|
|
63611
63887
|
function MFormEntry(value) {
|
|
63612
63888
|
const { error } = schemaFormEntry.validate(value);
|
|
@@ -63615,21 +63891,21 @@ function MFormEntry(value) {
|
|
|
63615
63891
|
}
|
|
63616
63892
|
if (value._id && typeof value._id === "string") {
|
|
63617
63893
|
try {
|
|
63618
|
-
value._id = new
|
|
63894
|
+
value._id = new import_mongodb144.ObjectId(value._id);
|
|
63619
63895
|
} catch {
|
|
63620
63896
|
throw new Error("Invalid ID.");
|
|
63621
63897
|
}
|
|
63622
63898
|
}
|
|
63623
63899
|
if (value.org && typeof value.org === "string") {
|
|
63624
63900
|
try {
|
|
63625
|
-
value.org = new
|
|
63901
|
+
value.org = new import_mongodb144.ObjectId(value.org);
|
|
63626
63902
|
} catch {
|
|
63627
63903
|
throw new Error("Invalid org ID.");
|
|
63628
63904
|
}
|
|
63629
63905
|
}
|
|
63630
63906
|
if (value.site && typeof value.site === "string") {
|
|
63631
63907
|
try {
|
|
63632
|
-
value.site = new
|
|
63908
|
+
value.site = new import_mongodb144.ObjectId(value.site);
|
|
63633
63909
|
} catch {
|
|
63634
63910
|
throw new Error("Invalid site ID.");
|
|
63635
63911
|
}
|
|
@@ -63653,16 +63929,16 @@ function MFormEntry(value) {
|
|
|
63653
63929
|
}
|
|
63654
63930
|
|
|
63655
63931
|
// src/repositories/online-forms-v2.repository.ts
|
|
63656
|
-
var
|
|
63657
|
-
var
|
|
63932
|
+
var import_node_server_utils249 = require("@7365admin1/node-server-utils");
|
|
63933
|
+
var import_mongodb145 = require("mongodb");
|
|
63658
63934
|
var online_forms_namespace_collection = "online-forms";
|
|
63659
63935
|
function useFormEntryRepo() {
|
|
63660
|
-
const db =
|
|
63936
|
+
const db = import_node_server_utils249.useAtlas.getDb();
|
|
63661
63937
|
if (!db) {
|
|
63662
|
-
throw new
|
|
63938
|
+
throw new import_node_server_utils249.InternalServerError("Unable to connect to server.");
|
|
63663
63939
|
}
|
|
63664
63940
|
const collection = db.collection(online_forms_namespace_collection);
|
|
63665
|
-
const { delNamespace, getCache, setCache } = (0,
|
|
63941
|
+
const { delNamespace, getCache, setCache } = (0, import_node_server_utils249.useCache)(
|
|
63666
63942
|
online_forms_namespace_collection
|
|
63667
63943
|
);
|
|
63668
63944
|
async function createTextIndex() {
|
|
@@ -63671,7 +63947,7 @@ function useFormEntryRepo() {
|
|
|
63671
63947
|
name: "text"
|
|
63672
63948
|
});
|
|
63673
63949
|
} catch (error) {
|
|
63674
|
-
throw new
|
|
63950
|
+
throw new import_node_server_utils249.InternalServerError(
|
|
63675
63951
|
"Failed to create text index on online form."
|
|
63676
63952
|
);
|
|
63677
63953
|
}
|
|
@@ -63681,11 +63957,11 @@ function useFormEntryRepo() {
|
|
|
63681
63957
|
value = MFormEntry(value);
|
|
63682
63958
|
const res = await collection.insertOne(value, { session });
|
|
63683
63959
|
delNamespace().then(() => {
|
|
63684
|
-
|
|
63960
|
+
import_node_server_utils249.logger.info(
|
|
63685
63961
|
`Cache cleared for namespace: ${online_forms_namespace_collection}`
|
|
63686
63962
|
);
|
|
63687
63963
|
}).catch((err) => {
|
|
63688
|
-
|
|
63964
|
+
import_node_server_utils249.logger.error(
|
|
63689
63965
|
`Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
|
|
63690
63966
|
err
|
|
63691
63967
|
);
|
|
@@ -63694,7 +63970,7 @@ function useFormEntryRepo() {
|
|
|
63694
63970
|
} catch (error) {
|
|
63695
63971
|
const isDuplicated = error.message.includes("duplicate");
|
|
63696
63972
|
if (isDuplicated) {
|
|
63697
|
-
throw new
|
|
63973
|
+
throw new import_node_server_utils249.BadRequestError("Online Form already exists.");
|
|
63698
63974
|
}
|
|
63699
63975
|
throw error;
|
|
63700
63976
|
}
|
|
@@ -63720,16 +63996,16 @@ function useFormEntryRepo() {
|
|
|
63720
63996
|
};
|
|
63721
63997
|
const query = {
|
|
63722
63998
|
...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } },
|
|
63723
|
-
...site && { site: new
|
|
63999
|
+
...site && { site: new import_mongodb145.ObjectId(site) },
|
|
63724
64000
|
...search && { search: [{ name: { $regex: search, $options: "i" } }] }
|
|
63725
64001
|
};
|
|
63726
|
-
const cacheKey = (0,
|
|
64002
|
+
const cacheKey = (0, import_node_server_utils249.makeCacheKey)(
|
|
63727
64003
|
online_forms_namespace_collection,
|
|
63728
64004
|
cacheOptions
|
|
63729
64005
|
);
|
|
63730
64006
|
const cachedData = await getCache(cacheKey);
|
|
63731
64007
|
if (cachedData) {
|
|
63732
|
-
|
|
64008
|
+
import_node_server_utils249.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
63733
64009
|
return cachedData;
|
|
63734
64010
|
}
|
|
63735
64011
|
try {
|
|
@@ -63740,11 +64016,11 @@ function useFormEntryRepo() {
|
|
|
63740
64016
|
{ $limit: limit }
|
|
63741
64017
|
]).toArray();
|
|
63742
64018
|
const length = await collection.countDocuments(query);
|
|
63743
|
-
const data = (0,
|
|
64019
|
+
const data = (0, import_node_server_utils249.paginate)(items, page, limit, length);
|
|
63744
64020
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
63745
|
-
|
|
64021
|
+
import_node_server_utils249.logger.info(`Cache set for key: ${cacheKey}`);
|
|
63746
64022
|
}).catch((err) => {
|
|
63747
|
-
|
|
64023
|
+
import_node_server_utils249.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
63748
64024
|
});
|
|
63749
64025
|
return data;
|
|
63750
64026
|
} catch (error) {
|
|
@@ -63752,27 +64028,27 @@ function useFormEntryRepo() {
|
|
|
63752
64028
|
}
|
|
63753
64029
|
}
|
|
63754
64030
|
async function getFormEntryById(_id) {
|
|
63755
|
-
const cacheKey = (0,
|
|
64031
|
+
const cacheKey = (0, import_node_server_utils249.makeCacheKey)(online_forms_namespace_collection, { _id });
|
|
63756
64032
|
const cachedData = await getCache(cacheKey);
|
|
63757
64033
|
if (cachedData) {
|
|
63758
|
-
|
|
64034
|
+
import_node_server_utils249.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
63759
64035
|
return cachedData;
|
|
63760
64036
|
}
|
|
63761
64037
|
try {
|
|
63762
|
-
_id = new
|
|
64038
|
+
_id = new import_mongodb145.ObjectId(_id);
|
|
63763
64039
|
} catch (error) {
|
|
63764
|
-
throw new
|
|
64040
|
+
throw new import_node_server_utils249.BadRequestError("Invalid online form ID format.");
|
|
63765
64041
|
}
|
|
63766
64042
|
const query = { _id, status: { $ne: "deleted" } };
|
|
63767
64043
|
try {
|
|
63768
64044
|
const [data] = await collection.aggregate([{ $match: query }]).toArray();
|
|
63769
64045
|
if (!data) {
|
|
63770
|
-
throw new
|
|
64046
|
+
throw new import_node_server_utils249.NotFoundError("Document not found.");
|
|
63771
64047
|
}
|
|
63772
64048
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
63773
|
-
|
|
64049
|
+
import_node_server_utils249.logger.info(`Cache set for key: ${cacheKey}`);
|
|
63774
64050
|
}).catch((err) => {
|
|
63775
|
-
|
|
64051
|
+
import_node_server_utils249.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
63776
64052
|
});
|
|
63777
64053
|
return data;
|
|
63778
64054
|
} catch (error) {
|
|
@@ -63781,9 +64057,9 @@ function useFormEntryRepo() {
|
|
|
63781
64057
|
}
|
|
63782
64058
|
async function updateFormEntryById(_id, value) {
|
|
63783
64059
|
try {
|
|
63784
|
-
_id = new
|
|
64060
|
+
_id = new import_mongodb145.ObjectId(_id);
|
|
63785
64061
|
} catch (error) {
|
|
63786
|
-
throw new
|
|
64062
|
+
throw new import_node_server_utils249.BadRequestError("Invalid online form ID format.");
|
|
63787
64063
|
}
|
|
63788
64064
|
try {
|
|
63789
64065
|
const updateValue = {
|
|
@@ -63792,14 +64068,14 @@ function useFormEntryRepo() {
|
|
|
63792
64068
|
};
|
|
63793
64069
|
const res = await collection.updateOne({ _id }, { $set: updateValue });
|
|
63794
64070
|
if (res.modifiedCount === 0) {
|
|
63795
|
-
throw new
|
|
64071
|
+
throw new import_node_server_utils249.InternalServerError("Unable to update online form.");
|
|
63796
64072
|
}
|
|
63797
64073
|
delNamespace().then(() => {
|
|
63798
|
-
|
|
64074
|
+
import_node_server_utils249.logger.info(
|
|
63799
64075
|
`Cache cleared for namespace: ${online_forms_namespace_collection}`
|
|
63800
64076
|
);
|
|
63801
64077
|
}).catch((err) => {
|
|
63802
|
-
|
|
64078
|
+
import_node_server_utils249.logger.error(
|
|
63803
64079
|
`Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
|
|
63804
64080
|
err
|
|
63805
64081
|
);
|
|
@@ -63811,9 +64087,9 @@ function useFormEntryRepo() {
|
|
|
63811
64087
|
}
|
|
63812
64088
|
async function deleteOnlineFormById(_id, session) {
|
|
63813
64089
|
try {
|
|
63814
|
-
_id = new
|
|
64090
|
+
_id = new import_mongodb145.ObjectId(_id);
|
|
63815
64091
|
} catch (error) {
|
|
63816
|
-
throw new
|
|
64092
|
+
throw new import_node_server_utils249.BadRequestError("Invalid online form ID format.");
|
|
63817
64093
|
}
|
|
63818
64094
|
try {
|
|
63819
64095
|
const updateValue = {
|
|
@@ -63827,12 +64103,12 @@ function useFormEntryRepo() {
|
|
|
63827
64103
|
{ session }
|
|
63828
64104
|
);
|
|
63829
64105
|
if (res.modifiedCount === 0) {
|
|
63830
|
-
throw new
|
|
64106
|
+
throw new import_node_server_utils249.InternalServerError("Unable to delete online form.");
|
|
63831
64107
|
}
|
|
63832
64108
|
delNamespace().then(() => {
|
|
63833
|
-
|
|
64109
|
+
import_node_server_utils249.logger.info(`Cache cleared for namespace: ${online_forms_namespace_collection}`);
|
|
63834
64110
|
}).catch((err) => {
|
|
63835
|
-
|
|
64111
|
+
import_node_server_utils249.logger.error(
|
|
63836
64112
|
`Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
|
|
63837
64113
|
err
|
|
63838
64114
|
);
|
|
@@ -63853,8 +64129,8 @@ function useFormEntryRepo() {
|
|
|
63853
64129
|
}
|
|
63854
64130
|
|
|
63855
64131
|
// src/controllers/online-forms-v2.controller.ts
|
|
63856
|
-
var
|
|
63857
|
-
var
|
|
64132
|
+
var import_node_server_utils250 = require("@7365admin1/node-server-utils");
|
|
64133
|
+
var import_joi145 = __toESM(require("joi"));
|
|
63858
64134
|
var import_exceljs3 = __toESM(require("exceljs"));
|
|
63859
64135
|
var import_fs7 = __toESM(require("fs"));
|
|
63860
64136
|
function useFormEntryController() {
|
|
@@ -63878,14 +64154,14 @@ function useFormEntryController() {
|
|
|
63878
64154
|
async function uploadFormEntrys(req, res, next) {
|
|
63879
64155
|
try {
|
|
63880
64156
|
if (!req.file) {
|
|
63881
|
-
next(new
|
|
64157
|
+
next(new import_node_server_utils250.BadRequestError("Excel file is required."));
|
|
63882
64158
|
return;
|
|
63883
64159
|
}
|
|
63884
64160
|
const workbook = new import_exceljs3.default.Workbook();
|
|
63885
64161
|
await workbook.xlsx.readFile(req.file.path);
|
|
63886
64162
|
const worksheet = workbook.worksheets[0];
|
|
63887
64163
|
if (!worksheet) {
|
|
63888
|
-
next(new
|
|
64164
|
+
next(new import_node_server_utils250.BadRequestError("No worksheet found in uploaded Excel file."));
|
|
63889
64165
|
return;
|
|
63890
64166
|
}
|
|
63891
64167
|
const headerRow = worksheet.getRow(1);
|
|
@@ -63913,8 +64189,8 @@ function useFormEntryController() {
|
|
|
63913
64189
|
});
|
|
63914
64190
|
if (error) {
|
|
63915
64191
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
63916
|
-
|
|
63917
|
-
next(new
|
|
64192
|
+
import_node_server_utils250.logger.log({ level: "error", message: messages });
|
|
64193
|
+
next(new import_node_server_utils250.BadRequestError(messages));
|
|
63918
64194
|
return;
|
|
63919
64195
|
}
|
|
63920
64196
|
const result = await _add(value);
|
|
@@ -63922,25 +64198,25 @@ function useFormEntryController() {
|
|
|
63922
64198
|
import_fs7.default.unlink(req.file.path, () => {
|
|
63923
64199
|
});
|
|
63924
64200
|
} catch (error) {
|
|
63925
|
-
|
|
64201
|
+
import_node_server_utils250.logger.log({ level: "error", message: error.message });
|
|
63926
64202
|
next(error);
|
|
63927
64203
|
}
|
|
63928
64204
|
}
|
|
63929
64205
|
async function getAll(req, res, next) {
|
|
63930
64206
|
try {
|
|
63931
|
-
const schema2 =
|
|
63932
|
-
search:
|
|
63933
|
-
page:
|
|
63934
|
-
limit:
|
|
63935
|
-
status:
|
|
63936
|
-
org:
|
|
63937
|
-
site:
|
|
64207
|
+
const schema2 = import_joi145.default.object({
|
|
64208
|
+
search: import_joi145.default.string().optional().allow("", null),
|
|
64209
|
+
page: import_joi145.default.number().integer().min(1).allow("", null).default(1),
|
|
64210
|
+
limit: import_joi145.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
64211
|
+
status: import_joi145.default.string().optional().allow(null, ""),
|
|
64212
|
+
org: import_joi145.default.string().hex().optional().allow("", null),
|
|
64213
|
+
site: import_joi145.default.string().hex().optional().allow("", null)
|
|
63938
64214
|
});
|
|
63939
64215
|
const { error, value } = schema2.validate(req.query);
|
|
63940
64216
|
if (error) {
|
|
63941
64217
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
63942
|
-
|
|
63943
|
-
next(new
|
|
64218
|
+
import_node_server_utils250.logger.log({ level: "error", message: messages });
|
|
64219
|
+
next(new import_node_server_utils250.BadRequestError(messages));
|
|
63944
64220
|
return;
|
|
63945
64221
|
}
|
|
63946
64222
|
const { search, page, limit, status, org, site } = value;
|
|
@@ -63948,21 +64224,21 @@ function useFormEntryController() {
|
|
|
63948
64224
|
res.json(data);
|
|
63949
64225
|
return;
|
|
63950
64226
|
} catch (error) {
|
|
63951
|
-
|
|
64227
|
+
import_node_server_utils250.logger.log({ level: "error", message: error.message });
|
|
63952
64228
|
next(error);
|
|
63953
64229
|
return;
|
|
63954
64230
|
}
|
|
63955
64231
|
}
|
|
63956
64232
|
async function getFormEntryById(req, res, next) {
|
|
63957
64233
|
try {
|
|
63958
|
-
const schema2 =
|
|
63959
|
-
_id:
|
|
64234
|
+
const schema2 = import_joi145.default.object({
|
|
64235
|
+
_id: import_joi145.default.string().hex().length(24).required()
|
|
63960
64236
|
});
|
|
63961
64237
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
63962
64238
|
if (error) {
|
|
63963
64239
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
63964
|
-
|
|
63965
|
-
next(new
|
|
64240
|
+
import_node_server_utils250.logger.log({ level: "error", message: messages });
|
|
64241
|
+
next(new import_node_server_utils250.BadRequestError(messages));
|
|
63966
64242
|
return;
|
|
63967
64243
|
}
|
|
63968
64244
|
const { _id } = value;
|
|
@@ -63970,7 +64246,7 @@ function useFormEntryController() {
|
|
|
63970
64246
|
res.json(data);
|
|
63971
64247
|
return;
|
|
63972
64248
|
} catch (error) {
|
|
63973
|
-
|
|
64249
|
+
import_node_server_utils250.logger.log({ level: "error", message: error.message });
|
|
63974
64250
|
next(error);
|
|
63975
64251
|
return;
|
|
63976
64252
|
}
|
|
@@ -63983,8 +64259,8 @@ function useFormEntryController() {
|
|
|
63983
64259
|
});
|
|
63984
64260
|
if (error) {
|
|
63985
64261
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
63986
|
-
|
|
63987
|
-
next(new
|
|
64262
|
+
import_node_server_utils250.logger.log({ level: "error", message: messages });
|
|
64263
|
+
next(new import_node_server_utils250.BadRequestError(messages));
|
|
63988
64264
|
return;
|
|
63989
64265
|
}
|
|
63990
64266
|
const { _id, ...rest } = value;
|
|
@@ -63992,31 +64268,58 @@ function useFormEntryController() {
|
|
|
63992
64268
|
res.json({ message: "Successfully updated online form." });
|
|
63993
64269
|
return;
|
|
63994
64270
|
} catch (error) {
|
|
63995
|
-
|
|
64271
|
+
import_node_server_utils250.logger.log({ level: "error", message: error.message });
|
|
63996
64272
|
next(error);
|
|
63997
64273
|
return;
|
|
63998
64274
|
}
|
|
63999
64275
|
}
|
|
64000
64276
|
async function deleteFormEntryById(req, res, next) {
|
|
64001
64277
|
try {
|
|
64002
|
-
const validation =
|
|
64278
|
+
const validation = import_joi145.default.string().hex().required();
|
|
64003
64279
|
const _id = req.params.id;
|
|
64004
64280
|
const { error } = validation.validate(_id);
|
|
64005
64281
|
if (error) {
|
|
64006
|
-
|
|
64007
|
-
next(new
|
|
64282
|
+
import_node_server_utils250.logger.log({ level: "error", message: error.message });
|
|
64283
|
+
next(new import_node_server_utils250.BadRequestError(error.message));
|
|
64008
64284
|
return;
|
|
64009
64285
|
}
|
|
64010
64286
|
await _deleteOnlineFormById(_id);
|
|
64011
64287
|
res.json({ message: "Successfully deleted online form." });
|
|
64012
64288
|
return;
|
|
64013
64289
|
} catch (error) {
|
|
64014
|
-
|
|
64290
|
+
import_node_server_utils250.logger.log({ level: "error", message: error.message });
|
|
64015
64291
|
next(error);
|
|
64016
64292
|
return;
|
|
64017
64293
|
}
|
|
64018
64294
|
}
|
|
64295
|
+
async function add(req, res, next) {
|
|
64296
|
+
const cookies = req.headers.cookie?.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
64297
|
+
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
64298
|
+
{}
|
|
64299
|
+
);
|
|
64300
|
+
const createdBy = cookies?.["user"].toString() ?? "";
|
|
64301
|
+
const payload = { ...req.body, createdBy };
|
|
64302
|
+
const { error } = schemaFormEntry.validate(payload, {
|
|
64303
|
+
abortEarly: false
|
|
64304
|
+
});
|
|
64305
|
+
if (error) {
|
|
64306
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
64307
|
+
import_node_server_utils250.logger.log({ level: "error", message: messages });
|
|
64308
|
+
next(new import_node_server_utils250.BadRequestError(messages));
|
|
64309
|
+
return;
|
|
64310
|
+
}
|
|
64311
|
+
try {
|
|
64312
|
+
const data = await _add(payload);
|
|
64313
|
+
res.status(201).json({ message: data });
|
|
64314
|
+
return;
|
|
64315
|
+
} catch (error2) {
|
|
64316
|
+
import_node_server_utils250.logger.log({ level: "error", message: error2.message });
|
|
64317
|
+
next(error2);
|
|
64318
|
+
return;
|
|
64319
|
+
}
|
|
64320
|
+
}
|
|
64019
64321
|
return {
|
|
64322
|
+
add,
|
|
64020
64323
|
uploadFormEntrys,
|
|
64021
64324
|
getAll,
|
|
64022
64325
|
getFormEntryById,
|
|
@@ -64026,11 +64329,11 @@ function useFormEntryController() {
|
|
|
64026
64329
|
}
|
|
64027
64330
|
|
|
64028
64331
|
// src/services/building-level.service.ts
|
|
64029
|
-
var
|
|
64332
|
+
var import_node_server_utils251 = require("@7365admin1/node-server-utils");
|
|
64030
64333
|
function useBuildingLevelService() {
|
|
64031
64334
|
const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelRepo();
|
|
64032
64335
|
async function add(value) {
|
|
64033
|
-
const session =
|
|
64336
|
+
const session = import_node_server_utils251.useAtlas.getClient()?.startSession();
|
|
64034
64337
|
try {
|
|
64035
64338
|
session?.startTransaction();
|
|
64036
64339
|
await _add(value, session);
|
|
@@ -64044,7 +64347,7 @@ function useBuildingLevelService() {
|
|
|
64044
64347
|
}
|
|
64045
64348
|
}
|
|
64046
64349
|
async function updateLevelById(_id, value) {
|
|
64047
|
-
const session =
|
|
64350
|
+
const session = import_node_server_utils251.useAtlas.getClient()?.startSession();
|
|
64048
64351
|
try {
|
|
64049
64352
|
session?.startTransaction();
|
|
64050
64353
|
await _updateLevelById(_id, value, session);
|
|
@@ -64064,8 +64367,8 @@ function useBuildingLevelService() {
|
|
|
64064
64367
|
}
|
|
64065
64368
|
|
|
64066
64369
|
// src/controllers/building-level.controller.ts
|
|
64067
|
-
var
|
|
64068
|
-
var
|
|
64370
|
+
var import_node_server_utils252 = require("@7365admin1/node-server-utils");
|
|
64371
|
+
var import_joi146 = __toESM(require("joi"));
|
|
64069
64372
|
function useBuildingLevelController() {
|
|
64070
64373
|
const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelService();
|
|
64071
64374
|
const {
|
|
@@ -64080,8 +64383,8 @@ function useBuildingLevelController() {
|
|
|
64080
64383
|
});
|
|
64081
64384
|
if (error) {
|
|
64082
64385
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
64083
|
-
|
|
64084
|
-
next(new
|
|
64386
|
+
import_node_server_utils252.logger.log({ level: "error", message: messages });
|
|
64387
|
+
next(new import_node_server_utils252.BadRequestError(messages));
|
|
64085
64388
|
return;
|
|
64086
64389
|
}
|
|
64087
64390
|
const result = await _add(value);
|
|
@@ -64092,20 +64395,20 @@ function useBuildingLevelController() {
|
|
|
64092
64395
|
}
|
|
64093
64396
|
async function getAll(req, res, next) {
|
|
64094
64397
|
try {
|
|
64095
|
-
const validation =
|
|
64096
|
-
page:
|
|
64097
|
-
limit:
|
|
64098
|
-
search:
|
|
64099
|
-
site:
|
|
64100
|
-
status:
|
|
64398
|
+
const validation = import_joi146.default.object({
|
|
64399
|
+
page: import_joi146.default.number().min(1).optional().default(1),
|
|
64400
|
+
limit: import_joi146.default.number().min(1).optional().default(20),
|
|
64401
|
+
search: import_joi146.default.string().optional().allow("", null),
|
|
64402
|
+
site: import_joi146.default.string().hex().length(24).optional().allow("", null),
|
|
64403
|
+
status: import_joi146.default.string().valid(...Object.values(BuildingLevelStatus)).default("active" /* ACTIVE */)
|
|
64101
64404
|
});
|
|
64102
64405
|
const { error, value } = validation.validate(req.query, {
|
|
64103
64406
|
abortEarly: false
|
|
64104
64407
|
});
|
|
64105
64408
|
if (error) {
|
|
64106
64409
|
const messages = error.details.map((d) => d.message);
|
|
64107
|
-
|
|
64108
|
-
next(new
|
|
64410
|
+
import_node_server_utils252.logger.log({ level: "error", message: messages.join(", ") });
|
|
64411
|
+
next(new import_node_server_utils252.BadRequestError(messages.join(", ")));
|
|
64109
64412
|
return;
|
|
64110
64413
|
}
|
|
64111
64414
|
const { page, limit, status, site, search } = value;
|
|
@@ -64124,14 +64427,14 @@ function useBuildingLevelController() {
|
|
|
64124
64427
|
}
|
|
64125
64428
|
async function getById(req, res, next) {
|
|
64126
64429
|
try {
|
|
64127
|
-
const schema2 =
|
|
64128
|
-
id:
|
|
64430
|
+
const schema2 = import_joi146.default.object({
|
|
64431
|
+
id: import_joi146.default.string().hex().length(24).required()
|
|
64129
64432
|
});
|
|
64130
64433
|
const { error, value } = schema2.validate({ id: req.params.id });
|
|
64131
64434
|
if (error) {
|
|
64132
64435
|
const messages = error.details.map((d) => d.message);
|
|
64133
|
-
|
|
64134
|
-
next(new
|
|
64436
|
+
import_node_server_utils252.logger.log({ level: "error", message: messages.join(", ") });
|
|
64437
|
+
next(new import_node_server_utils252.BadRequestError(messages.join(", ")));
|
|
64135
64438
|
return;
|
|
64136
64439
|
}
|
|
64137
64440
|
const { id } = value;
|
|
@@ -64150,8 +64453,8 @@ function useBuildingLevelController() {
|
|
|
64150
64453
|
});
|
|
64151
64454
|
if (error) {
|
|
64152
64455
|
const messages = error.details.map((d) => d.message);
|
|
64153
|
-
|
|
64154
|
-
next(new
|
|
64456
|
+
import_node_server_utils252.logger.log({ level: "error", message: messages.join(", ") });
|
|
64457
|
+
next(new import_node_server_utils252.BadRequestError(messages.join(", ")));
|
|
64155
64458
|
return;
|
|
64156
64459
|
}
|
|
64157
64460
|
const { _id, ...rest } = value;
|
|
@@ -64163,14 +64466,14 @@ function useBuildingLevelController() {
|
|
|
64163
64466
|
}
|
|
64164
64467
|
async function deleteById(req, res, next) {
|
|
64165
64468
|
try {
|
|
64166
|
-
const schema2 =
|
|
64167
|
-
id:
|
|
64469
|
+
const schema2 = import_joi146.default.object({
|
|
64470
|
+
id: import_joi146.default.string().hex().required()
|
|
64168
64471
|
});
|
|
64169
64472
|
const { error, value } = schema2.validate({ id: req.params.id });
|
|
64170
64473
|
if (error) {
|
|
64171
64474
|
const messages = error.details.map((d) => d.message);
|
|
64172
|
-
|
|
64173
|
-
next(new
|
|
64475
|
+
import_node_server_utils252.logger.log({ level: "error", message: messages.join(", ") });
|
|
64476
|
+
next(new import_node_server_utils252.BadRequestError(messages.join(", ")));
|
|
64174
64477
|
return;
|
|
64175
64478
|
}
|
|
64176
64479
|
const { id } = value;
|
|
@@ -64233,6 +64536,7 @@ function useBuildingLevelController() {
|
|
|
64233
64536
|
MBulletinBoard,
|
|
64234
64537
|
MBulletinVideo,
|
|
64235
64538
|
MCategoryPreloved,
|
|
64539
|
+
MChannelPreloved,
|
|
64236
64540
|
MChat,
|
|
64237
64541
|
MChatPreloved,
|
|
64238
64542
|
MCustomer,
|
|
@@ -64379,6 +64683,7 @@ function useBuildingLevelController() {
|
|
|
64379
64683
|
schemaBulletinBoard,
|
|
64380
64684
|
schemaBulletinVideo,
|
|
64381
64685
|
schemaCategoryPreloved,
|
|
64686
|
+
schemaChannelPreloved,
|
|
64382
64687
|
schemaChatPreloved,
|
|
64383
64688
|
schemaCustomerSite,
|
|
64384
64689
|
schemaDocumentManagement,
|
|
@@ -64487,6 +64792,8 @@ function useBuildingLevelController() {
|
|
|
64487
64792
|
useBulletinVideoService,
|
|
64488
64793
|
useCategoryPrelovedController,
|
|
64489
64794
|
useCategoryPrelovedRepo,
|
|
64795
|
+
useChannelPrelovedController,
|
|
64796
|
+
useChannelPrelovedRepo,
|
|
64490
64797
|
useChatController,
|
|
64491
64798
|
useChatPrelovedController,
|
|
64492
64799
|
useChatPrelovedRepo,
|