@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.mjs
CHANGED
|
@@ -537,13 +537,13 @@ var require_logger = __commonJS({
|
|
|
537
537
|
"use strict";
|
|
538
538
|
exports.__esModule = true;
|
|
539
539
|
var _utils = require_utils();
|
|
540
|
-
var
|
|
540
|
+
var logger198 = {
|
|
541
541
|
methodMap: ["debug", "info", "warn", "error"],
|
|
542
542
|
level: "info",
|
|
543
543
|
// Maps a given level value to the `methodMap` indexes above.
|
|
544
544
|
lookupLevel: function lookupLevel(level) {
|
|
545
545
|
if (typeof level === "string") {
|
|
546
|
-
var levelMap = _utils.indexOf(
|
|
546
|
+
var levelMap = _utils.indexOf(logger198.methodMap, level.toLowerCase());
|
|
547
547
|
if (levelMap >= 0) {
|
|
548
548
|
level = levelMap;
|
|
549
549
|
} else {
|
|
@@ -554,9 +554,9 @@ var require_logger = __commonJS({
|
|
|
554
554
|
},
|
|
555
555
|
// Can be overridden in the host environment
|
|
556
556
|
log: function log(level) {
|
|
557
|
-
level =
|
|
558
|
-
if (typeof console !== "undefined" &&
|
|
559
|
-
var method =
|
|
557
|
+
level = logger198.lookupLevel(level);
|
|
558
|
+
if (typeof console !== "undefined" && logger198.lookupLevel(logger198.level) <= level) {
|
|
559
|
+
var method = logger198.methodMap[level];
|
|
560
560
|
if (!console[method]) {
|
|
561
561
|
method = "log";
|
|
562
562
|
}
|
|
@@ -567,7 +567,7 @@ var require_logger = __commonJS({
|
|
|
567
567
|
}
|
|
568
568
|
}
|
|
569
569
|
};
|
|
570
|
-
exports["default"] =
|
|
570
|
+
exports["default"] = logger198;
|
|
571
571
|
module.exports = exports["default"];
|
|
572
572
|
}
|
|
573
573
|
});
|
|
@@ -9062,27 +9062,23 @@ function useMemberRepo() {
|
|
|
9062
9062
|
limit = 10,
|
|
9063
9063
|
user = "",
|
|
9064
9064
|
org = "",
|
|
9065
|
+
siteId = "",
|
|
9065
9066
|
type = "",
|
|
9066
9067
|
status = ""
|
|
9067
9068
|
}) {
|
|
9068
9069
|
limit = limit > 0 ? limit : 10;
|
|
9069
9070
|
search = search || "";
|
|
9070
9071
|
page = page > 0 ? page - 1 : 0;
|
|
9071
|
-
const query = {
|
|
9072
|
+
const query = {
|
|
9073
|
+
type,
|
|
9074
|
+
status
|
|
9075
|
+
};
|
|
9072
9076
|
const cacheOptions = {
|
|
9073
9077
|
page,
|
|
9074
9078
|
limit,
|
|
9075
9079
|
type,
|
|
9076
9080
|
status
|
|
9077
9081
|
};
|
|
9078
|
-
if (user) {
|
|
9079
|
-
try {
|
|
9080
|
-
query.user = new ObjectId11(user);
|
|
9081
|
-
cacheOptions.user = user.toString();
|
|
9082
|
-
} catch (error) {
|
|
9083
|
-
throw new BadRequestError11("Invalid user ID format.");
|
|
9084
|
-
}
|
|
9085
|
-
}
|
|
9086
9082
|
if (org) {
|
|
9087
9083
|
try {
|
|
9088
9084
|
query.org = new ObjectId11(org);
|
|
@@ -9091,6 +9087,22 @@ function useMemberRepo() {
|
|
|
9091
9087
|
throw new BadRequestError11("Invalid organization ID format.");
|
|
9092
9088
|
}
|
|
9093
9089
|
}
|
|
9090
|
+
if (siteId) {
|
|
9091
|
+
try {
|
|
9092
|
+
query.siteId = new ObjectId11(siteId);
|
|
9093
|
+
cacheOptions.siteId = siteId.toString();
|
|
9094
|
+
} catch (error) {
|
|
9095
|
+
throw new BadRequestError11("Invalid site ID format.");
|
|
9096
|
+
}
|
|
9097
|
+
}
|
|
9098
|
+
if (user) {
|
|
9099
|
+
try {
|
|
9100
|
+
query.user = new ObjectId11(user);
|
|
9101
|
+
cacheOptions.user = user.toString();
|
|
9102
|
+
} catch (error) {
|
|
9103
|
+
throw new BadRequestError11("Invalid user ID format.");
|
|
9104
|
+
}
|
|
9105
|
+
}
|
|
9094
9106
|
if (search) {
|
|
9095
9107
|
query.$text = { $search: search };
|
|
9096
9108
|
cacheOptions.search = search;
|
|
@@ -14073,6 +14085,7 @@ function useMemberController() {
|
|
|
14073
14085
|
limit: Joi15.number().integer().min(1).max(50).allow("", null).default(10),
|
|
14074
14086
|
user: Joi15.string().hex().optional().allow("", null),
|
|
14075
14087
|
org: Joi15.string().hex().optional().allow("", null),
|
|
14088
|
+
siteId: Joi15.string().hex().optional().allow("", null),
|
|
14076
14089
|
type: Joi15.string().required(),
|
|
14077
14090
|
status: Joi15.string().required()
|
|
14078
14091
|
});
|
|
@@ -14088,6 +14101,7 @@ function useMemberController() {
|
|
|
14088
14101
|
const limit = parseInt(req.query.limit ?? "10");
|
|
14089
14102
|
const user = req.query.user ?? "";
|
|
14090
14103
|
const org = req.query.org ?? "";
|
|
14104
|
+
const siteId = req.query.siteId ?? "";
|
|
14091
14105
|
const type = req.query.type ?? "main";
|
|
14092
14106
|
const status = req.query.status ?? "active";
|
|
14093
14107
|
try {
|
|
@@ -14097,6 +14111,7 @@ function useMemberController() {
|
|
|
14097
14111
|
limit,
|
|
14098
14112
|
user,
|
|
14099
14113
|
org,
|
|
14114
|
+
siteId,
|
|
14100
14115
|
type,
|
|
14101
14116
|
status
|
|
14102
14117
|
});
|
|
@@ -29976,12 +29991,91 @@ function useCustomerSiteRepo() {
|
|
|
29976
29991
|
} catch (error) {
|
|
29977
29992
|
}
|
|
29978
29993
|
}
|
|
29994
|
+
async function getById(id) {
|
|
29995
|
+
try {
|
|
29996
|
+
id = new ObjectId54(id);
|
|
29997
|
+
} catch {
|
|
29998
|
+
throw new BadRequestError90("Invalid ID.");
|
|
29999
|
+
}
|
|
30000
|
+
const data = await collection.findOne({
|
|
30001
|
+
_id: id
|
|
30002
|
+
});
|
|
30003
|
+
if (!data) {
|
|
30004
|
+
throw new BadRequestError90("Customer site not found.");
|
|
30005
|
+
}
|
|
30006
|
+
return data;
|
|
30007
|
+
}
|
|
30008
|
+
async function updateCustomerSiteById(id, payload, session) {
|
|
30009
|
+
try {
|
|
30010
|
+
id = new ObjectId54(id);
|
|
30011
|
+
} catch {
|
|
30012
|
+
throw new BadRequestError90("Invalid ID.");
|
|
30013
|
+
}
|
|
30014
|
+
delete payload._id;
|
|
30015
|
+
const result = await collection.findOneAndUpdate(
|
|
30016
|
+
{ _id: id, status: "active" },
|
|
30017
|
+
{
|
|
30018
|
+
$set: {
|
|
30019
|
+
...payload,
|
|
30020
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
30021
|
+
}
|
|
30022
|
+
},
|
|
30023
|
+
{
|
|
30024
|
+
returnDocument: "after",
|
|
30025
|
+
session
|
|
30026
|
+
}
|
|
30027
|
+
);
|
|
30028
|
+
if (!result) {
|
|
30029
|
+
throw new BadRequestError90("Customer site not found.");
|
|
30030
|
+
}
|
|
30031
|
+
delNamespace().then(() => {
|
|
30032
|
+
logger70.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
30033
|
+
}).catch((err) => {
|
|
30034
|
+
logger70.error(`Failed to clear cache for namespace: ${namespace_collection}`, err);
|
|
30035
|
+
});
|
|
30036
|
+
return result;
|
|
30037
|
+
}
|
|
30038
|
+
async function deleteById(id, session) {
|
|
30039
|
+
try {
|
|
30040
|
+
id = new ObjectId54(id);
|
|
30041
|
+
} catch {
|
|
30042
|
+
throw new BadRequestError90("Invalid ID.");
|
|
30043
|
+
}
|
|
30044
|
+
const result = await collection.findOneAndUpdate(
|
|
30045
|
+
{
|
|
30046
|
+
_id: id,
|
|
30047
|
+
status: { $ne: "deleted" }
|
|
30048
|
+
},
|
|
30049
|
+
{
|
|
30050
|
+
$set: {
|
|
30051
|
+
status: "deleted",
|
|
30052
|
+
deletedAt: /* @__PURE__ */ new Date()
|
|
30053
|
+
}
|
|
30054
|
+
},
|
|
30055
|
+
{
|
|
30056
|
+
returnDocument: "after",
|
|
30057
|
+
session
|
|
30058
|
+
}
|
|
30059
|
+
);
|
|
30060
|
+
if (!result) {
|
|
30061
|
+
throw new BadRequestError90("Customer site not found.");
|
|
30062
|
+
}
|
|
30063
|
+
delNamespace().then(() => {
|
|
30064
|
+
logger70.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
30065
|
+
}).catch((err) => {
|
|
30066
|
+
logger70.error(`Failed to clear cache for namespace: ${namespace_collection}`, err);
|
|
30067
|
+
});
|
|
30068
|
+
return result;
|
|
30069
|
+
}
|
|
29979
30070
|
return {
|
|
29980
30071
|
createIndexes,
|
|
29981
30072
|
add,
|
|
29982
30073
|
getAll,
|
|
29983
30074
|
getByName,
|
|
29984
|
-
getBySiteAsServiceProvider
|
|
30075
|
+
getBySiteAsServiceProvider,
|
|
30076
|
+
getById,
|
|
30077
|
+
updateCustomerSiteById,
|
|
30078
|
+
deleteById
|
|
29985
30079
|
};
|
|
29986
30080
|
}
|
|
29987
30081
|
|
|
@@ -29993,12 +30087,13 @@ import {
|
|
|
29993
30087
|
} from "@7365admin1/node-server-utils";
|
|
29994
30088
|
import levenshtein from "fast-levenshtein";
|
|
29995
30089
|
function useCustomerSiteService() {
|
|
29996
|
-
const { add: _add } = useCustomerSiteRepo();
|
|
30090
|
+
const { add: _add, updateCustomerSiteById, getById: _getById } = useCustomerSiteRepo();
|
|
29997
30091
|
const {
|
|
29998
30092
|
getByName: getSiteByName,
|
|
29999
30093
|
getByExactName: getSiteByExactName,
|
|
30000
30094
|
createSite,
|
|
30001
|
-
getSiteById
|
|
30095
|
+
getSiteById,
|
|
30096
|
+
updateSiteById
|
|
30002
30097
|
} = useSiteRepo();
|
|
30003
30098
|
const {
|
|
30004
30099
|
getById: _getByOrgId,
|
|
@@ -30129,9 +30224,47 @@ function useCustomerSiteService() {
|
|
|
30129
30224
|
session?.endSession();
|
|
30130
30225
|
}
|
|
30131
30226
|
}
|
|
30227
|
+
async function updateCusSiteById(customerSiteId, payload) {
|
|
30228
|
+
const session = useAtlas44.getClient()?.startSession();
|
|
30229
|
+
session?.startTransaction();
|
|
30230
|
+
try {
|
|
30231
|
+
const customerSite = await _getById(customerSiteId);
|
|
30232
|
+
if (!customerSite) {
|
|
30233
|
+
throw new NotFoundError20("Customer site not found.");
|
|
30234
|
+
}
|
|
30235
|
+
const siteId = customerSite.site;
|
|
30236
|
+
await updateSiteById(
|
|
30237
|
+
siteId,
|
|
30238
|
+
{
|
|
30239
|
+
...payload.name !== void 0 && { name: payload.name },
|
|
30240
|
+
...payload.address !== void 0 && { address: payload.address },
|
|
30241
|
+
...payload.category !== void 0 && { category: payload.category }
|
|
30242
|
+
},
|
|
30243
|
+
session
|
|
30244
|
+
);
|
|
30245
|
+
const safePayload = {
|
|
30246
|
+
...payload.name !== void 0 && { name: payload.name },
|
|
30247
|
+
...payload.address !== void 0 && { address: payload.address },
|
|
30248
|
+
...payload.category !== void 0 && { category: payload.category }
|
|
30249
|
+
};
|
|
30250
|
+
const result = await updateCustomerSiteById(
|
|
30251
|
+
customerSiteId,
|
|
30252
|
+
safePayload,
|
|
30253
|
+
session
|
|
30254
|
+
);
|
|
30255
|
+
await session?.commitTransaction();
|
|
30256
|
+
return result;
|
|
30257
|
+
} catch (error) {
|
|
30258
|
+
await session?.abortTransaction();
|
|
30259
|
+
throw error;
|
|
30260
|
+
} finally {
|
|
30261
|
+
await session?.endSession();
|
|
30262
|
+
}
|
|
30263
|
+
}
|
|
30132
30264
|
return {
|
|
30133
30265
|
add,
|
|
30134
|
-
addViaInvite
|
|
30266
|
+
addViaInvite,
|
|
30267
|
+
updateCusSiteById
|
|
30135
30268
|
};
|
|
30136
30269
|
}
|
|
30137
30270
|
|
|
@@ -30141,9 +30274,11 @@ import { BadRequestError as BadRequestError92, logger as logger71 } from "@7365a
|
|
|
30141
30274
|
function useCustomerSiteController() {
|
|
30142
30275
|
const {
|
|
30143
30276
|
getAll: _getAll,
|
|
30144
|
-
getBySiteAsServiceProvider: _getBySiteAsServiceProvider
|
|
30277
|
+
getBySiteAsServiceProvider: _getBySiteAsServiceProvider,
|
|
30278
|
+
getById: _getById,
|
|
30279
|
+
deleteById: _deleteById
|
|
30145
30280
|
} = useCustomerSiteRepo();
|
|
30146
|
-
const { add: _add, addViaInvite: _addViaInvite } = useCustomerSiteService();
|
|
30281
|
+
const { add: _add, addViaInvite: _addViaInvite, updateCusSiteById: _updateCusSiteById } = useCustomerSiteService();
|
|
30147
30282
|
async function add(req, res, next) {
|
|
30148
30283
|
const { error, value } = schemaCustomerSite.validate(req.body);
|
|
30149
30284
|
if (error) {
|
|
@@ -30260,11 +30395,63 @@ function useCustomerSiteController() {
|
|
|
30260
30395
|
return;
|
|
30261
30396
|
}
|
|
30262
30397
|
}
|
|
30398
|
+
async function getById(req, res, next) {
|
|
30399
|
+
const validation = Joi52.object({
|
|
30400
|
+
id: Joi52.string().hex().required()
|
|
30401
|
+
});
|
|
30402
|
+
const id = req.params.id;
|
|
30403
|
+
const { error } = validation.validate({ id });
|
|
30404
|
+
if (error) {
|
|
30405
|
+
next(new BadRequestError92(error.message));
|
|
30406
|
+
return;
|
|
30407
|
+
}
|
|
30408
|
+
try {
|
|
30409
|
+
const data = await _getById(id);
|
|
30410
|
+
res.json(data);
|
|
30411
|
+
return;
|
|
30412
|
+
} catch (error2) {
|
|
30413
|
+
next(error2);
|
|
30414
|
+
return;
|
|
30415
|
+
}
|
|
30416
|
+
}
|
|
30417
|
+
async function updateById(req, res, next) {
|
|
30418
|
+
const validation = Joi52.object({
|
|
30419
|
+
id: Joi52.string().hex().required()
|
|
30420
|
+
});
|
|
30421
|
+
const id = req.params.id;
|
|
30422
|
+
const { error } = validation.validate({ id });
|
|
30423
|
+
if (error) {
|
|
30424
|
+
next(new BadRequestError92(error.message));
|
|
30425
|
+
return;
|
|
30426
|
+
}
|
|
30427
|
+
try {
|
|
30428
|
+
const data = await _updateCusSiteById(id, req.body);
|
|
30429
|
+
res.json(data);
|
|
30430
|
+
return;
|
|
30431
|
+
} catch (error2) {
|
|
30432
|
+
next(error2);
|
|
30433
|
+
return;
|
|
30434
|
+
}
|
|
30435
|
+
}
|
|
30436
|
+
async function deleteById(req, res, next) {
|
|
30437
|
+
const id = req.params.id;
|
|
30438
|
+
try {
|
|
30439
|
+
const data = await _deleteById(id);
|
|
30440
|
+
res.json(data);
|
|
30441
|
+
return;
|
|
30442
|
+
} catch (error) {
|
|
30443
|
+
next(error);
|
|
30444
|
+
return;
|
|
30445
|
+
}
|
|
30446
|
+
}
|
|
30263
30447
|
return {
|
|
30264
30448
|
add,
|
|
30265
30449
|
getAll,
|
|
30266
30450
|
addViaInvite,
|
|
30267
|
-
getBySiteAsServiceProvider
|
|
30451
|
+
getBySiteAsServiceProvider,
|
|
30452
|
+
getById,
|
|
30453
|
+
updateById,
|
|
30454
|
+
deleteById
|
|
30268
30455
|
};
|
|
30269
30456
|
}
|
|
30270
30457
|
|
|
@@ -63852,57 +64039,145 @@ function useChatPrelovedController() {
|
|
|
63852
64039
|
return { add, updateById, deleteById };
|
|
63853
64040
|
}
|
|
63854
64041
|
|
|
63855
|
-
// src/models/
|
|
64042
|
+
// src/models/channel-preloved.model.ts
|
|
63856
64043
|
import Joi143 from "joi";
|
|
63857
64044
|
import { ObjectId as ObjectId143 } from "mongodb";
|
|
64045
|
+
var schemaChannelPreloved = Joi143.object({
|
|
64046
|
+
receiverId: Joi143.string().hex().length(24).required(),
|
|
64047
|
+
senderId: Joi143.string().hex().length(24).required(),
|
|
64048
|
+
postId: Joi143.string().hex().length(24).required()
|
|
64049
|
+
});
|
|
64050
|
+
function toObjectId22(value, label) {
|
|
64051
|
+
if (typeof value === "string") {
|
|
64052
|
+
try {
|
|
64053
|
+
return new ObjectId143(value);
|
|
64054
|
+
} catch {
|
|
64055
|
+
throw new Error(`Invalid ${label}.`);
|
|
64056
|
+
}
|
|
64057
|
+
}
|
|
64058
|
+
return value;
|
|
64059
|
+
}
|
|
64060
|
+
function MChannelPreloved(value) {
|
|
64061
|
+
const { error } = schemaChannelPreloved.validate(value);
|
|
64062
|
+
if (error)
|
|
64063
|
+
throw new Error(error.details[0].message);
|
|
64064
|
+
if (value.receiverId)
|
|
64065
|
+
value.receiverId = toObjectId22(value.receiverId, "receiver ID");
|
|
64066
|
+
if (value.senderId)
|
|
64067
|
+
value.senderId = toObjectId22(value.senderId, "sender ID");
|
|
64068
|
+
if (value.postId)
|
|
64069
|
+
value.postId = toObjectId22(value.postId, "post ID");
|
|
64070
|
+
return {
|
|
64071
|
+
_id: new ObjectId143(),
|
|
64072
|
+
name: `seven365-${(/* @__PURE__ */ new Date()).getTime()}`,
|
|
64073
|
+
receiverId: value.receiverId,
|
|
64074
|
+
senderId: value.senderId,
|
|
64075
|
+
postId: value.postId,
|
|
64076
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
64077
|
+
updatedAt: null
|
|
64078
|
+
};
|
|
64079
|
+
}
|
|
64080
|
+
|
|
64081
|
+
// src/repositories/channel-preloved.repo.ts
|
|
64082
|
+
import {
|
|
64083
|
+
InternalServerError as InternalServerError80,
|
|
64084
|
+
useAtlas as useAtlas125
|
|
64085
|
+
} from "@7365admin1/node-server-utils";
|
|
64086
|
+
function useChannelPrelovedRepo() {
|
|
64087
|
+
const db = useAtlas125.getDb();
|
|
64088
|
+
if (!db)
|
|
64089
|
+
throw new InternalServerError80("Unable to connect to server.");
|
|
64090
|
+
const CHANNEL_COLLECTION = "channel-preloved";
|
|
64091
|
+
const collection = db.collection(CHANNEL_COLLECTION);
|
|
64092
|
+
async function add(value, session) {
|
|
64093
|
+
try {
|
|
64094
|
+
const doc = MChannelPreloved(value);
|
|
64095
|
+
const res = await collection.insertOne(doc, { session });
|
|
64096
|
+
return res.insertedId;
|
|
64097
|
+
} catch (error) {
|
|
64098
|
+
throw error;
|
|
64099
|
+
}
|
|
64100
|
+
}
|
|
64101
|
+
return { add };
|
|
64102
|
+
}
|
|
64103
|
+
|
|
64104
|
+
// src/controllers/channel-preloved.controller.ts
|
|
64105
|
+
import { BadRequestError as BadRequestError222, logger as logger194 } from "@7365admin1/node-server-utils";
|
|
64106
|
+
function useChannelPrelovedController() {
|
|
64107
|
+
const { add: _add } = useChannelPrelovedRepo();
|
|
64108
|
+
async function add(req, res, next) {
|
|
64109
|
+
const { error, value } = schemaChannelPreloved.validate(req.body, {
|
|
64110
|
+
abortEarly: false
|
|
64111
|
+
});
|
|
64112
|
+
if (error) {
|
|
64113
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
64114
|
+
logger194.log({ level: "error", message: messages });
|
|
64115
|
+
next(new BadRequestError222(messages));
|
|
64116
|
+
return;
|
|
64117
|
+
}
|
|
64118
|
+
try {
|
|
64119
|
+
const data = await _add(value);
|
|
64120
|
+
res.status(201).json(data);
|
|
64121
|
+
} catch (error2) {
|
|
64122
|
+
logger194.log({ level: "error", message: error2.message });
|
|
64123
|
+
next(error2);
|
|
64124
|
+
}
|
|
64125
|
+
}
|
|
64126
|
+
return { add };
|
|
64127
|
+
}
|
|
64128
|
+
|
|
64129
|
+
// src/models/online-forms-v2.model.ts
|
|
64130
|
+
import Joi144 from "joi";
|
|
64131
|
+
import { ObjectId as ObjectId144 } from "mongodb";
|
|
63858
64132
|
var FormEntryStatus = /* @__PURE__ */ ((FormEntryStatus2) => {
|
|
63859
64133
|
FormEntryStatus2["ACTIVE"] = "active";
|
|
63860
64134
|
FormEntryStatus2["INACTIVE"] = "inactive";
|
|
63861
64135
|
FormEntryStatus2["DELETED"] = "deleted";
|
|
63862
64136
|
return FormEntryStatus2;
|
|
63863
64137
|
})(FormEntryStatus || {});
|
|
63864
|
-
var schemaFormEntry =
|
|
63865
|
-
_id:
|
|
63866
|
-
formType:
|
|
63867
|
-
block:
|
|
63868
|
-
level:
|
|
63869
|
-
unit:
|
|
63870
|
-
name:
|
|
63871
|
-
phoneNumber:
|
|
63872
|
-
|
|
63873
|
-
|
|
63874
|
-
|
|
63875
|
-
|
|
63876
|
-
|
|
63877
|
-
|
|
63878
|
-
|
|
64138
|
+
var schemaFormEntry = Joi144.object({
|
|
64139
|
+
_id: Joi144.string().hex().optional().allow("", null),
|
|
64140
|
+
formType: Joi144.string().required(),
|
|
64141
|
+
block: Joi144.string().optional().allow(null, ""),
|
|
64142
|
+
level: Joi144.string().optional().allow(null, ""),
|
|
64143
|
+
unit: Joi144.string().optional().allow(null, ""),
|
|
64144
|
+
name: Joi144.string().optional().allow(null, ""),
|
|
64145
|
+
phoneNumber: Joi144.string().optional().allow(null, ""),
|
|
64146
|
+
createdBy: Joi144.string().required(),
|
|
64147
|
+
fields: Joi144.object().pattern(
|
|
64148
|
+
Joi144.string(),
|
|
64149
|
+
Joi144.alternatives().try(
|
|
64150
|
+
Joi144.string(),
|
|
64151
|
+
Joi144.number(),
|
|
64152
|
+
Joi144.boolean(),
|
|
64153
|
+
Joi144.valid(null)
|
|
63879
64154
|
)
|
|
63880
64155
|
).required(),
|
|
63881
|
-
status:
|
|
63882
|
-
org:
|
|
63883
|
-
site:
|
|
63884
|
-
createdAt:
|
|
63885
|
-
updatedAt:
|
|
63886
|
-
deletedAt:
|
|
64156
|
+
status: Joi144.string().optional().allow("", null),
|
|
64157
|
+
org: Joi144.string().hex().optional().allow("", null),
|
|
64158
|
+
site: Joi144.string().hex().optional().allow("", null),
|
|
64159
|
+
createdAt: Joi144.date().optional().allow("", null),
|
|
64160
|
+
updatedAt: Joi144.date().optional().allow("", null),
|
|
64161
|
+
deletedAt: Joi144.date().optional().allow("", null)
|
|
63887
64162
|
});
|
|
63888
|
-
var schemaUpdateFormEntry =
|
|
63889
|
-
_id:
|
|
63890
|
-
formType:
|
|
63891
|
-
block:
|
|
63892
|
-
level:
|
|
63893
|
-
unit:
|
|
63894
|
-
fields:
|
|
63895
|
-
|
|
63896
|
-
|
|
63897
|
-
|
|
63898
|
-
|
|
63899
|
-
|
|
63900
|
-
|
|
64163
|
+
var schemaUpdateFormEntry = Joi144.object({
|
|
64164
|
+
_id: Joi144.string().hex().required(),
|
|
64165
|
+
formType: Joi144.string().optional().allow("", null),
|
|
64166
|
+
block: Joi144.string().optional().allow(null, ""),
|
|
64167
|
+
level: Joi144.string().optional().allow(null, ""),
|
|
64168
|
+
unit: Joi144.string().optional().allow(null, ""),
|
|
64169
|
+
fields: Joi144.object().pattern(
|
|
64170
|
+
Joi144.string(),
|
|
64171
|
+
Joi144.alternatives().try(
|
|
64172
|
+
Joi144.string(),
|
|
64173
|
+
Joi144.number(),
|
|
64174
|
+
Joi144.boolean(),
|
|
64175
|
+
Joi144.valid(null)
|
|
63901
64176
|
)
|
|
63902
64177
|
).optional(),
|
|
63903
|
-
status:
|
|
63904
|
-
updatedAt:
|
|
63905
|
-
deletedAt:
|
|
64178
|
+
status: Joi144.string().optional().allow("", null),
|
|
64179
|
+
updatedAt: Joi144.date().optional().allow("", null),
|
|
64180
|
+
deletedAt: Joi144.date().optional().allow("", null)
|
|
63906
64181
|
});
|
|
63907
64182
|
function MFormEntry(value) {
|
|
63908
64183
|
const { error } = schemaFormEntry.validate(value);
|
|
@@ -63911,21 +64186,21 @@ function MFormEntry(value) {
|
|
|
63911
64186
|
}
|
|
63912
64187
|
if (value._id && typeof value._id === "string") {
|
|
63913
64188
|
try {
|
|
63914
|
-
value._id = new
|
|
64189
|
+
value._id = new ObjectId144(value._id);
|
|
63915
64190
|
} catch {
|
|
63916
64191
|
throw new Error("Invalid ID.");
|
|
63917
64192
|
}
|
|
63918
64193
|
}
|
|
63919
64194
|
if (value.org && typeof value.org === "string") {
|
|
63920
64195
|
try {
|
|
63921
|
-
value.org = new
|
|
64196
|
+
value.org = new ObjectId144(value.org);
|
|
63922
64197
|
} catch {
|
|
63923
64198
|
throw new Error("Invalid org ID.");
|
|
63924
64199
|
}
|
|
63925
64200
|
}
|
|
63926
64201
|
if (value.site && typeof value.site === "string") {
|
|
63927
64202
|
try {
|
|
63928
|
-
value.site = new
|
|
64203
|
+
value.site = new ObjectId144(value.site);
|
|
63929
64204
|
} catch {
|
|
63930
64205
|
throw new Error("Invalid site ID.");
|
|
63931
64206
|
}
|
|
@@ -63950,21 +64225,21 @@ function MFormEntry(value) {
|
|
|
63950
64225
|
|
|
63951
64226
|
// src/repositories/online-forms-v2.repository.ts
|
|
63952
64227
|
import {
|
|
63953
|
-
BadRequestError as
|
|
63954
|
-
InternalServerError as
|
|
63955
|
-
logger as
|
|
64228
|
+
BadRequestError as BadRequestError223,
|
|
64229
|
+
InternalServerError as InternalServerError81,
|
|
64230
|
+
logger as logger195,
|
|
63956
64231
|
makeCacheKey as makeCacheKey66,
|
|
63957
64232
|
NotFoundError as NotFoundError61,
|
|
63958
64233
|
paginate as paginate62,
|
|
63959
|
-
useAtlas as
|
|
64234
|
+
useAtlas as useAtlas126,
|
|
63960
64235
|
useCache as useCache70
|
|
63961
64236
|
} from "@7365admin1/node-server-utils";
|
|
63962
|
-
import { ObjectId as
|
|
64237
|
+
import { ObjectId as ObjectId145 } from "mongodb";
|
|
63963
64238
|
var online_forms_namespace_collection = "online-forms";
|
|
63964
64239
|
function useFormEntryRepo() {
|
|
63965
|
-
const db =
|
|
64240
|
+
const db = useAtlas126.getDb();
|
|
63966
64241
|
if (!db) {
|
|
63967
|
-
throw new
|
|
64242
|
+
throw new InternalServerError81("Unable to connect to server.");
|
|
63968
64243
|
}
|
|
63969
64244
|
const collection = db.collection(online_forms_namespace_collection);
|
|
63970
64245
|
const { delNamespace, getCache, setCache } = useCache70(
|
|
@@ -63976,7 +64251,7 @@ function useFormEntryRepo() {
|
|
|
63976
64251
|
name: "text"
|
|
63977
64252
|
});
|
|
63978
64253
|
} catch (error) {
|
|
63979
|
-
throw new
|
|
64254
|
+
throw new InternalServerError81(
|
|
63980
64255
|
"Failed to create text index on online form."
|
|
63981
64256
|
);
|
|
63982
64257
|
}
|
|
@@ -63986,11 +64261,11 @@ function useFormEntryRepo() {
|
|
|
63986
64261
|
value = MFormEntry(value);
|
|
63987
64262
|
const res = await collection.insertOne(value, { session });
|
|
63988
64263
|
delNamespace().then(() => {
|
|
63989
|
-
|
|
64264
|
+
logger195.info(
|
|
63990
64265
|
`Cache cleared for namespace: ${online_forms_namespace_collection}`
|
|
63991
64266
|
);
|
|
63992
64267
|
}).catch((err) => {
|
|
63993
|
-
|
|
64268
|
+
logger195.error(
|
|
63994
64269
|
`Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
|
|
63995
64270
|
err
|
|
63996
64271
|
);
|
|
@@ -63999,7 +64274,7 @@ function useFormEntryRepo() {
|
|
|
63999
64274
|
} catch (error) {
|
|
64000
64275
|
const isDuplicated = error.message.includes("duplicate");
|
|
64001
64276
|
if (isDuplicated) {
|
|
64002
|
-
throw new
|
|
64277
|
+
throw new BadRequestError223("Online Form already exists.");
|
|
64003
64278
|
}
|
|
64004
64279
|
throw error;
|
|
64005
64280
|
}
|
|
@@ -64025,7 +64300,7 @@ function useFormEntryRepo() {
|
|
|
64025
64300
|
};
|
|
64026
64301
|
const query = {
|
|
64027
64302
|
...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } },
|
|
64028
|
-
...site && { site: new
|
|
64303
|
+
...site && { site: new ObjectId145(site) },
|
|
64029
64304
|
...search && { search: [{ name: { $regex: search, $options: "i" } }] }
|
|
64030
64305
|
};
|
|
64031
64306
|
const cacheKey = makeCacheKey66(
|
|
@@ -64034,7 +64309,7 @@ function useFormEntryRepo() {
|
|
|
64034
64309
|
);
|
|
64035
64310
|
const cachedData = await getCache(cacheKey);
|
|
64036
64311
|
if (cachedData) {
|
|
64037
|
-
|
|
64312
|
+
logger195.info(`Cache hit for key: ${cacheKey}`);
|
|
64038
64313
|
return cachedData;
|
|
64039
64314
|
}
|
|
64040
64315
|
try {
|
|
@@ -64047,9 +64322,9 @@ function useFormEntryRepo() {
|
|
|
64047
64322
|
const length = await collection.countDocuments(query);
|
|
64048
64323
|
const data = paginate62(items, page, limit, length);
|
|
64049
64324
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
64050
|
-
|
|
64325
|
+
logger195.info(`Cache set for key: ${cacheKey}`);
|
|
64051
64326
|
}).catch((err) => {
|
|
64052
|
-
|
|
64327
|
+
logger195.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
64053
64328
|
});
|
|
64054
64329
|
return data;
|
|
64055
64330
|
} catch (error) {
|
|
@@ -64060,13 +64335,13 @@ function useFormEntryRepo() {
|
|
|
64060
64335
|
const cacheKey = makeCacheKey66(online_forms_namespace_collection, { _id });
|
|
64061
64336
|
const cachedData = await getCache(cacheKey);
|
|
64062
64337
|
if (cachedData) {
|
|
64063
|
-
|
|
64338
|
+
logger195.info(`Cache hit for key: ${cacheKey}`);
|
|
64064
64339
|
return cachedData;
|
|
64065
64340
|
}
|
|
64066
64341
|
try {
|
|
64067
|
-
_id = new
|
|
64342
|
+
_id = new ObjectId145(_id);
|
|
64068
64343
|
} catch (error) {
|
|
64069
|
-
throw new
|
|
64344
|
+
throw new BadRequestError223("Invalid online form ID format.");
|
|
64070
64345
|
}
|
|
64071
64346
|
const query = { _id, status: { $ne: "deleted" } };
|
|
64072
64347
|
try {
|
|
@@ -64075,9 +64350,9 @@ function useFormEntryRepo() {
|
|
|
64075
64350
|
throw new NotFoundError61("Document not found.");
|
|
64076
64351
|
}
|
|
64077
64352
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
64078
|
-
|
|
64353
|
+
logger195.info(`Cache set for key: ${cacheKey}`);
|
|
64079
64354
|
}).catch((err) => {
|
|
64080
|
-
|
|
64355
|
+
logger195.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
64081
64356
|
});
|
|
64082
64357
|
return data;
|
|
64083
64358
|
} catch (error) {
|
|
@@ -64086,9 +64361,9 @@ function useFormEntryRepo() {
|
|
|
64086
64361
|
}
|
|
64087
64362
|
async function updateFormEntryById(_id, value) {
|
|
64088
64363
|
try {
|
|
64089
|
-
_id = new
|
|
64364
|
+
_id = new ObjectId145(_id);
|
|
64090
64365
|
} catch (error) {
|
|
64091
|
-
throw new
|
|
64366
|
+
throw new BadRequestError223("Invalid online form ID format.");
|
|
64092
64367
|
}
|
|
64093
64368
|
try {
|
|
64094
64369
|
const updateValue = {
|
|
@@ -64097,14 +64372,14 @@ function useFormEntryRepo() {
|
|
|
64097
64372
|
};
|
|
64098
64373
|
const res = await collection.updateOne({ _id }, { $set: updateValue });
|
|
64099
64374
|
if (res.modifiedCount === 0) {
|
|
64100
|
-
throw new
|
|
64375
|
+
throw new InternalServerError81("Unable to update online form.");
|
|
64101
64376
|
}
|
|
64102
64377
|
delNamespace().then(() => {
|
|
64103
|
-
|
|
64378
|
+
logger195.info(
|
|
64104
64379
|
`Cache cleared for namespace: ${online_forms_namespace_collection}`
|
|
64105
64380
|
);
|
|
64106
64381
|
}).catch((err) => {
|
|
64107
|
-
|
|
64382
|
+
logger195.error(
|
|
64108
64383
|
`Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
|
|
64109
64384
|
err
|
|
64110
64385
|
);
|
|
@@ -64116,9 +64391,9 @@ function useFormEntryRepo() {
|
|
|
64116
64391
|
}
|
|
64117
64392
|
async function deleteOnlineFormById(_id, session) {
|
|
64118
64393
|
try {
|
|
64119
|
-
_id = new
|
|
64394
|
+
_id = new ObjectId145(_id);
|
|
64120
64395
|
} catch (error) {
|
|
64121
|
-
throw new
|
|
64396
|
+
throw new BadRequestError223("Invalid online form ID format.");
|
|
64122
64397
|
}
|
|
64123
64398
|
try {
|
|
64124
64399
|
const updateValue = {
|
|
@@ -64132,12 +64407,12 @@ function useFormEntryRepo() {
|
|
|
64132
64407
|
{ session }
|
|
64133
64408
|
);
|
|
64134
64409
|
if (res.modifiedCount === 0) {
|
|
64135
|
-
throw new
|
|
64410
|
+
throw new InternalServerError81("Unable to delete online form.");
|
|
64136
64411
|
}
|
|
64137
64412
|
delNamespace().then(() => {
|
|
64138
|
-
|
|
64413
|
+
logger195.info(`Cache cleared for namespace: ${online_forms_namespace_collection}`);
|
|
64139
64414
|
}).catch((err) => {
|
|
64140
|
-
|
|
64415
|
+
logger195.error(
|
|
64141
64416
|
`Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
|
|
64142
64417
|
err
|
|
64143
64418
|
);
|
|
@@ -64158,8 +64433,8 @@ function useFormEntryRepo() {
|
|
|
64158
64433
|
}
|
|
64159
64434
|
|
|
64160
64435
|
// src/controllers/online-forms-v2.controller.ts
|
|
64161
|
-
import { BadRequestError as
|
|
64162
|
-
import
|
|
64436
|
+
import { BadRequestError as BadRequestError224, logger as logger196 } from "@7365admin1/node-server-utils";
|
|
64437
|
+
import Joi145 from "joi";
|
|
64163
64438
|
import ExcelJS3 from "exceljs";
|
|
64164
64439
|
import fs6 from "fs";
|
|
64165
64440
|
function useFormEntryController() {
|
|
@@ -64183,14 +64458,14 @@ function useFormEntryController() {
|
|
|
64183
64458
|
async function uploadFormEntrys(req, res, next) {
|
|
64184
64459
|
try {
|
|
64185
64460
|
if (!req.file) {
|
|
64186
|
-
next(new
|
|
64461
|
+
next(new BadRequestError224("Excel file is required."));
|
|
64187
64462
|
return;
|
|
64188
64463
|
}
|
|
64189
64464
|
const workbook = new ExcelJS3.Workbook();
|
|
64190
64465
|
await workbook.xlsx.readFile(req.file.path);
|
|
64191
64466
|
const worksheet = workbook.worksheets[0];
|
|
64192
64467
|
if (!worksheet) {
|
|
64193
|
-
next(new
|
|
64468
|
+
next(new BadRequestError224("No worksheet found in uploaded Excel file."));
|
|
64194
64469
|
return;
|
|
64195
64470
|
}
|
|
64196
64471
|
const headerRow = worksheet.getRow(1);
|
|
@@ -64218,8 +64493,8 @@ function useFormEntryController() {
|
|
|
64218
64493
|
});
|
|
64219
64494
|
if (error) {
|
|
64220
64495
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
64221
|
-
|
|
64222
|
-
next(new
|
|
64496
|
+
logger196.log({ level: "error", message: messages });
|
|
64497
|
+
next(new BadRequestError224(messages));
|
|
64223
64498
|
return;
|
|
64224
64499
|
}
|
|
64225
64500
|
const result = await _add(value);
|
|
@@ -64227,25 +64502,25 @@ function useFormEntryController() {
|
|
|
64227
64502
|
fs6.unlink(req.file.path, () => {
|
|
64228
64503
|
});
|
|
64229
64504
|
} catch (error) {
|
|
64230
|
-
|
|
64505
|
+
logger196.log({ level: "error", message: error.message });
|
|
64231
64506
|
next(error);
|
|
64232
64507
|
}
|
|
64233
64508
|
}
|
|
64234
64509
|
async function getAll(req, res, next) {
|
|
64235
64510
|
try {
|
|
64236
|
-
const schema2 =
|
|
64237
|
-
search:
|
|
64238
|
-
page:
|
|
64239
|
-
limit:
|
|
64240
|
-
status:
|
|
64241
|
-
org:
|
|
64242
|
-
site:
|
|
64511
|
+
const schema2 = Joi145.object({
|
|
64512
|
+
search: Joi145.string().optional().allow("", null),
|
|
64513
|
+
page: Joi145.number().integer().min(1).allow("", null).default(1),
|
|
64514
|
+
limit: Joi145.number().integer().min(1).max(100).allow("", null).default(10),
|
|
64515
|
+
status: Joi145.string().optional().allow(null, ""),
|
|
64516
|
+
org: Joi145.string().hex().optional().allow("", null),
|
|
64517
|
+
site: Joi145.string().hex().optional().allow("", null)
|
|
64243
64518
|
});
|
|
64244
64519
|
const { error, value } = schema2.validate(req.query);
|
|
64245
64520
|
if (error) {
|
|
64246
64521
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
64247
|
-
|
|
64248
|
-
next(new
|
|
64522
|
+
logger196.log({ level: "error", message: messages });
|
|
64523
|
+
next(new BadRequestError224(messages));
|
|
64249
64524
|
return;
|
|
64250
64525
|
}
|
|
64251
64526
|
const { search, page, limit, status, org, site } = value;
|
|
@@ -64253,21 +64528,21 @@ function useFormEntryController() {
|
|
|
64253
64528
|
res.json(data);
|
|
64254
64529
|
return;
|
|
64255
64530
|
} catch (error) {
|
|
64256
|
-
|
|
64531
|
+
logger196.log({ level: "error", message: error.message });
|
|
64257
64532
|
next(error);
|
|
64258
64533
|
return;
|
|
64259
64534
|
}
|
|
64260
64535
|
}
|
|
64261
64536
|
async function getFormEntryById(req, res, next) {
|
|
64262
64537
|
try {
|
|
64263
|
-
const schema2 =
|
|
64264
|
-
_id:
|
|
64538
|
+
const schema2 = Joi145.object({
|
|
64539
|
+
_id: Joi145.string().hex().length(24).required()
|
|
64265
64540
|
});
|
|
64266
64541
|
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
64267
64542
|
if (error) {
|
|
64268
64543
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
64269
|
-
|
|
64270
|
-
next(new
|
|
64544
|
+
logger196.log({ level: "error", message: messages });
|
|
64545
|
+
next(new BadRequestError224(messages));
|
|
64271
64546
|
return;
|
|
64272
64547
|
}
|
|
64273
64548
|
const { _id } = value;
|
|
@@ -64275,7 +64550,7 @@ function useFormEntryController() {
|
|
|
64275
64550
|
res.json(data);
|
|
64276
64551
|
return;
|
|
64277
64552
|
} catch (error) {
|
|
64278
|
-
|
|
64553
|
+
logger196.log({ level: "error", message: error.message });
|
|
64279
64554
|
next(error);
|
|
64280
64555
|
return;
|
|
64281
64556
|
}
|
|
@@ -64288,8 +64563,8 @@ function useFormEntryController() {
|
|
|
64288
64563
|
});
|
|
64289
64564
|
if (error) {
|
|
64290
64565
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
64291
|
-
|
|
64292
|
-
next(new
|
|
64566
|
+
logger196.log({ level: "error", message: messages });
|
|
64567
|
+
next(new BadRequestError224(messages));
|
|
64293
64568
|
return;
|
|
64294
64569
|
}
|
|
64295
64570
|
const { _id, ...rest } = value;
|
|
@@ -64297,31 +64572,58 @@ function useFormEntryController() {
|
|
|
64297
64572
|
res.json({ message: "Successfully updated online form." });
|
|
64298
64573
|
return;
|
|
64299
64574
|
} catch (error) {
|
|
64300
|
-
|
|
64575
|
+
logger196.log({ level: "error", message: error.message });
|
|
64301
64576
|
next(error);
|
|
64302
64577
|
return;
|
|
64303
64578
|
}
|
|
64304
64579
|
}
|
|
64305
64580
|
async function deleteFormEntryById(req, res, next) {
|
|
64306
64581
|
try {
|
|
64307
|
-
const validation =
|
|
64582
|
+
const validation = Joi145.string().hex().required();
|
|
64308
64583
|
const _id = req.params.id;
|
|
64309
64584
|
const { error } = validation.validate(_id);
|
|
64310
64585
|
if (error) {
|
|
64311
|
-
|
|
64312
|
-
next(new
|
|
64586
|
+
logger196.log({ level: "error", message: error.message });
|
|
64587
|
+
next(new BadRequestError224(error.message));
|
|
64313
64588
|
return;
|
|
64314
64589
|
}
|
|
64315
64590
|
await _deleteOnlineFormById(_id);
|
|
64316
64591
|
res.json({ message: "Successfully deleted online form." });
|
|
64317
64592
|
return;
|
|
64318
64593
|
} catch (error) {
|
|
64319
|
-
|
|
64594
|
+
logger196.log({ level: "error", message: error.message });
|
|
64320
64595
|
next(error);
|
|
64321
64596
|
return;
|
|
64322
64597
|
}
|
|
64323
64598
|
}
|
|
64599
|
+
async function add(req, res, next) {
|
|
64600
|
+
const cookies = req.headers.cookie?.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
64601
|
+
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
64602
|
+
{}
|
|
64603
|
+
);
|
|
64604
|
+
const createdBy = cookies?.["user"].toString() ?? "";
|
|
64605
|
+
const payload = { ...req.body, createdBy };
|
|
64606
|
+
const { error } = schemaFormEntry.validate(payload, {
|
|
64607
|
+
abortEarly: false
|
|
64608
|
+
});
|
|
64609
|
+
if (error) {
|
|
64610
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
64611
|
+
logger196.log({ level: "error", message: messages });
|
|
64612
|
+
next(new BadRequestError224(messages));
|
|
64613
|
+
return;
|
|
64614
|
+
}
|
|
64615
|
+
try {
|
|
64616
|
+
const data = await _add(payload);
|
|
64617
|
+
res.status(201).json({ message: data });
|
|
64618
|
+
return;
|
|
64619
|
+
} catch (error2) {
|
|
64620
|
+
logger196.log({ level: "error", message: error2.message });
|
|
64621
|
+
next(error2);
|
|
64622
|
+
return;
|
|
64623
|
+
}
|
|
64624
|
+
}
|
|
64324
64625
|
return {
|
|
64626
|
+
add,
|
|
64325
64627
|
uploadFormEntrys,
|
|
64326
64628
|
getAll,
|
|
64327
64629
|
getFormEntryById,
|
|
@@ -64331,11 +64633,11 @@ function useFormEntryController() {
|
|
|
64331
64633
|
}
|
|
64332
64634
|
|
|
64333
64635
|
// src/services/building-level.service.ts
|
|
64334
|
-
import { useAtlas as
|
|
64636
|
+
import { useAtlas as useAtlas127 } from "@7365admin1/node-server-utils";
|
|
64335
64637
|
function useBuildingLevelService() {
|
|
64336
64638
|
const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelRepo();
|
|
64337
64639
|
async function add(value) {
|
|
64338
|
-
const session =
|
|
64640
|
+
const session = useAtlas127.getClient()?.startSession();
|
|
64339
64641
|
try {
|
|
64340
64642
|
session?.startTransaction();
|
|
64341
64643
|
await _add(value, session);
|
|
@@ -64349,7 +64651,7 @@ function useBuildingLevelService() {
|
|
|
64349
64651
|
}
|
|
64350
64652
|
}
|
|
64351
64653
|
async function updateLevelById(_id, value) {
|
|
64352
|
-
const session =
|
|
64654
|
+
const session = useAtlas127.getClient()?.startSession();
|
|
64353
64655
|
try {
|
|
64354
64656
|
session?.startTransaction();
|
|
64355
64657
|
await _updateLevelById(_id, value, session);
|
|
@@ -64369,8 +64671,8 @@ function useBuildingLevelService() {
|
|
|
64369
64671
|
}
|
|
64370
64672
|
|
|
64371
64673
|
// src/controllers/building-level.controller.ts
|
|
64372
|
-
import { BadRequestError as
|
|
64373
|
-
import
|
|
64674
|
+
import { BadRequestError as BadRequestError225, logger as logger197 } from "@7365admin1/node-server-utils";
|
|
64675
|
+
import Joi146 from "joi";
|
|
64374
64676
|
function useBuildingLevelController() {
|
|
64375
64677
|
const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelService();
|
|
64376
64678
|
const {
|
|
@@ -64385,8 +64687,8 @@ function useBuildingLevelController() {
|
|
|
64385
64687
|
});
|
|
64386
64688
|
if (error) {
|
|
64387
64689
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
64388
|
-
|
|
64389
|
-
next(new
|
|
64690
|
+
logger197.log({ level: "error", message: messages });
|
|
64691
|
+
next(new BadRequestError225(messages));
|
|
64390
64692
|
return;
|
|
64391
64693
|
}
|
|
64392
64694
|
const result = await _add(value);
|
|
@@ -64397,20 +64699,20 @@ function useBuildingLevelController() {
|
|
|
64397
64699
|
}
|
|
64398
64700
|
async function getAll(req, res, next) {
|
|
64399
64701
|
try {
|
|
64400
|
-
const validation =
|
|
64401
|
-
page:
|
|
64402
|
-
limit:
|
|
64403
|
-
search:
|
|
64404
|
-
site:
|
|
64405
|
-
status:
|
|
64702
|
+
const validation = Joi146.object({
|
|
64703
|
+
page: Joi146.number().min(1).optional().default(1),
|
|
64704
|
+
limit: Joi146.number().min(1).optional().default(20),
|
|
64705
|
+
search: Joi146.string().optional().allow("", null),
|
|
64706
|
+
site: Joi146.string().hex().length(24).optional().allow("", null),
|
|
64707
|
+
status: Joi146.string().valid(...Object.values(BuildingLevelStatus)).default("active" /* ACTIVE */)
|
|
64406
64708
|
});
|
|
64407
64709
|
const { error, value } = validation.validate(req.query, {
|
|
64408
64710
|
abortEarly: false
|
|
64409
64711
|
});
|
|
64410
64712
|
if (error) {
|
|
64411
64713
|
const messages = error.details.map((d) => d.message);
|
|
64412
|
-
|
|
64413
|
-
next(new
|
|
64714
|
+
logger197.log({ level: "error", message: messages.join(", ") });
|
|
64715
|
+
next(new BadRequestError225(messages.join(", ")));
|
|
64414
64716
|
return;
|
|
64415
64717
|
}
|
|
64416
64718
|
const { page, limit, status, site, search } = value;
|
|
@@ -64429,14 +64731,14 @@ function useBuildingLevelController() {
|
|
|
64429
64731
|
}
|
|
64430
64732
|
async function getById(req, res, next) {
|
|
64431
64733
|
try {
|
|
64432
|
-
const schema2 =
|
|
64433
|
-
id:
|
|
64734
|
+
const schema2 = Joi146.object({
|
|
64735
|
+
id: Joi146.string().hex().length(24).required()
|
|
64434
64736
|
});
|
|
64435
64737
|
const { error, value } = schema2.validate({ id: req.params.id });
|
|
64436
64738
|
if (error) {
|
|
64437
64739
|
const messages = error.details.map((d) => d.message);
|
|
64438
|
-
|
|
64439
|
-
next(new
|
|
64740
|
+
logger197.log({ level: "error", message: messages.join(", ") });
|
|
64741
|
+
next(new BadRequestError225(messages.join(", ")));
|
|
64440
64742
|
return;
|
|
64441
64743
|
}
|
|
64442
64744
|
const { id } = value;
|
|
@@ -64455,8 +64757,8 @@ function useBuildingLevelController() {
|
|
|
64455
64757
|
});
|
|
64456
64758
|
if (error) {
|
|
64457
64759
|
const messages = error.details.map((d) => d.message);
|
|
64458
|
-
|
|
64459
|
-
next(new
|
|
64760
|
+
logger197.log({ level: "error", message: messages.join(", ") });
|
|
64761
|
+
next(new BadRequestError225(messages.join(", ")));
|
|
64460
64762
|
return;
|
|
64461
64763
|
}
|
|
64462
64764
|
const { _id, ...rest } = value;
|
|
@@ -64468,14 +64770,14 @@ function useBuildingLevelController() {
|
|
|
64468
64770
|
}
|
|
64469
64771
|
async function deleteById(req, res, next) {
|
|
64470
64772
|
try {
|
|
64471
|
-
const schema2 =
|
|
64472
|
-
id:
|
|
64773
|
+
const schema2 = Joi146.object({
|
|
64774
|
+
id: Joi146.string().hex().required()
|
|
64473
64775
|
});
|
|
64474
64776
|
const { error, value } = schema2.validate({ id: req.params.id });
|
|
64475
64777
|
if (error) {
|
|
64476
64778
|
const messages = error.details.map((d) => d.message);
|
|
64477
|
-
|
|
64478
|
-
next(new
|
|
64779
|
+
logger197.log({ level: "error", message: messages.join(", ") });
|
|
64780
|
+
next(new BadRequestError225(messages.join(", ")));
|
|
64479
64781
|
return;
|
|
64480
64782
|
}
|
|
64481
64783
|
const { id } = value;
|
|
@@ -64537,6 +64839,7 @@ export {
|
|
|
64537
64839
|
MBulletinBoard,
|
|
64538
64840
|
MBulletinVideo,
|
|
64539
64841
|
MCategoryPreloved,
|
|
64842
|
+
MChannelPreloved,
|
|
64540
64843
|
MChat,
|
|
64541
64844
|
MChatPreloved,
|
|
64542
64845
|
MCustomer,
|
|
@@ -64683,6 +64986,7 @@ export {
|
|
|
64683
64986
|
schemaBulletinBoard,
|
|
64684
64987
|
schemaBulletinVideo,
|
|
64685
64988
|
schemaCategoryPreloved,
|
|
64989
|
+
schemaChannelPreloved,
|
|
64686
64990
|
schemaChatPreloved,
|
|
64687
64991
|
schemaCustomerSite,
|
|
64688
64992
|
schemaDocumentManagement,
|
|
@@ -64791,6 +65095,8 @@ export {
|
|
|
64791
65095
|
useBulletinVideoService,
|
|
64792
65096
|
useCategoryPrelovedController,
|
|
64793
65097
|
useCategoryPrelovedRepo,
|
|
65098
|
+
useChannelPrelovedController,
|
|
65099
|
+
useChannelPrelovedRepo,
|
|
64794
65100
|
useChatController,
|
|
64795
65101
|
useChatPrelovedController,
|
|
64796
65102
|
useChatPrelovedRepo,
|