@7365admin1/core 2.79.0 → 2.80.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/dist/index.js CHANGED
@@ -73,6 +73,7 @@ __export(src_exports, {
73
73
  MBulletinVideo: () => MBulletinVideo,
74
74
  MCategoryPreloved: () => MCategoryPreloved,
75
75
  MChat: () => MChat,
76
+ MChatPreloved: () => MChatPreloved,
76
77
  MCustomer: () => MCustomer,
77
78
  MCustomerSite: () => MCustomerSite,
78
79
  MDocumentManagement: () => MDocumentManagement,
@@ -217,6 +218,7 @@ __export(src_exports, {
217
218
  schemaBulletinBoard: () => schemaBulletinBoard,
218
219
  schemaBulletinVideo: () => schemaBulletinVideo,
219
220
  schemaCategoryPreloved: () => schemaCategoryPreloved,
221
+ schemaChatPreloved: () => schemaChatPreloved,
220
222
  schemaCustomerSite: () => schemaCustomerSite,
221
223
  schemaDocumentManagement: () => schemaDocumentManagement,
222
224
  schemaEntryPassSettings: () => schemaEntryPassSettings,
@@ -324,6 +326,8 @@ __export(src_exports, {
324
326
  useCategoryPrelovedController: () => useCategoryPrelovedController,
325
327
  useCategoryPrelovedRepo: () => useCategoryPrelovedRepo,
326
328
  useChatController: () => useChatController,
329
+ useChatPrelovedController: () => useChatPrelovedController,
330
+ useChatPrelovedRepo: () => useChatPrelovedRepo,
327
331
  useChatRepo: () => useChatRepo,
328
332
  useCounterModel: () => useCounterModel,
329
333
  useCounterRepo: () => useCounterRepo,
@@ -32706,19 +32710,19 @@ function useDocumentManagementRepo() {
32706
32710
  parentId = ""
32707
32711
  }) {
32708
32712
  page = page > 0 ? page - 1 : 0;
32713
+ const query = {
32714
+ status: { $ne: "deleted" }
32715
+ };
32716
+ const cacheOptions = {
32717
+ page,
32718
+ limit
32719
+ };
32709
32720
  try {
32710
- site = new import_mongodb80.ObjectId(site);
32721
+ query.site = new import_mongodb80.ObjectId(site);
32722
+ cacheOptions.site = site?.toString();
32711
32723
  } catch (error) {
32712
32724
  throw new import_node_server_utils136.BadRequestError("Invalid site ID format.");
32713
32725
  }
32714
- const cacheOptions = {
32715
- page,
32716
- limit,
32717
- site: site?.toString()
32718
- };
32719
- const query = {
32720
- status: { $ne: "deleted" }
32721
- };
32722
32726
  if (type && type !== "all") {
32723
32727
  query.type = type;
32724
32728
  cacheOptions.type = type;
@@ -56963,14 +56967,29 @@ function useCategoryPrelovedRepo() {
56963
56967
  throw new import_node_server_utils241.InternalServerError("Unable to update category.");
56964
56968
  return "Category updated successfully.";
56965
56969
  }
56966
- return { getAll, getById, addCategory, updateById };
56970
+ async function deleteById(_id) {
56971
+ let objectId2;
56972
+ try {
56973
+ objectId2 = new import_mongodb138.ObjectId(_id);
56974
+ } catch {
56975
+ throw new import_node_server_utils241.BadRequestError("Invalid category ID format.");
56976
+ }
56977
+ const existing = await collection.findOne({ _id: objectId2 });
56978
+ if (!existing)
56979
+ throw new import_node_server_utils241.NotFoundError("Category not found.");
56980
+ const res = await collection.deleteOne({ _id: objectId2 });
56981
+ if (res.deletedCount === 0)
56982
+ throw new import_node_server_utils241.InternalServerError("Unable to delete category.");
56983
+ return "Category deleted successfully.";
56984
+ }
56985
+ return { getAll, getById, addCategory, updateById, deleteById };
56967
56986
  }
56968
56987
 
56969
56988
  // src/controllers/category-preloved.controller.ts
56970
56989
  var import_node_server_utils242 = require("@7365admin1/node-server-utils");
56971
56990
  var import_joi138 = __toESM(require("joi"));
56972
56991
  function useCategoryPrelovedController() {
56973
- const { getAll: _getAll, getById: _getById, addCategory: _addCategory, updateById: _updateById } = useCategoryPrelovedRepo();
56992
+ const { getAll: _getAll, getById: _getById, addCategory: _addCategory, updateById: _updateById, deleteById: _deleteById } = useCategoryPrelovedRepo();
56974
56993
  async function getAll(req, res, next) {
56975
56994
  const schema2 = import_joi138.default.object({
56976
56995
  search: import_joi138.default.string().optional().allow("", null),
@@ -57049,7 +57068,25 @@ function useCategoryPrelovedController() {
57049
57068
  next(error2);
57050
57069
  }
57051
57070
  }
57052
- return { getAll, getById, addCategory, updateById };
57071
+ async function deleteById(req, res, next) {
57072
+ const schema2 = import_joi138.default.object({
57073
+ _id: import_joi138.default.string().hex().length(24).required()
57074
+ });
57075
+ const { error, value } = schema2.validate({ _id: req.params.id });
57076
+ if (error) {
57077
+ import_node_server_utils242.logger.log({ level: "error", message: error.message });
57078
+ next(new import_node_server_utils242.BadRequestError(error.message));
57079
+ return;
57080
+ }
57081
+ try {
57082
+ const data = await _deleteById(value._id);
57083
+ res.status(200).json(data);
57084
+ } catch (error2) {
57085
+ import_node_server_utils242.logger.log({ level: "error", message: error2.message });
57086
+ next(error2);
57087
+ }
57088
+ }
57089
+ return { getAll, getById, addCategory, updateById, deleteById };
57053
57090
  }
57054
57091
 
57055
57092
  // src/models/subcategory-preloved.model.ts
@@ -57335,57 +57372,180 @@ function useSubcategoryPrelovedController() {
57335
57372
  return { getAll, getById, addSubcategory, updateById, deleteById };
57336
57373
  }
57337
57374
 
57338
- // src/models/online-forms-v2.model.ts
57375
+ // src/models/chat-preloved.model.ts
57339
57376
  var import_joi141 = __toESM(require("joi"));
57340
57377
  var import_mongodb141 = require("mongodb");
57378
+ var schemaMessage = import_joi141.default.object({
57379
+ text: import_joi141.default.string().required(),
57380
+ date: import_joi141.default.date().optional().allow(null),
57381
+ time: import_joi141.default.string().optional().allow("", null),
57382
+ senderId: import_joi141.default.string().hex().length(24).required()
57383
+ });
57384
+ var schemaChatPreloved = import_joi141.default.object({
57385
+ channelId: import_joi141.default.string().hex().length(24).required(),
57386
+ senderId: import_joi141.default.string().hex().length(24).required(),
57387
+ postId: import_joi141.default.string().hex().length(24).optional().allow("", null),
57388
+ message: schemaMessage.required(),
57389
+ readMessage: import_joi141.default.array().items(import_joi141.default.string().hex()).optional().default([]),
57390
+ viewMessage: import_joi141.default.array().items(import_joi141.default.string().hex()).optional().default([]),
57391
+ attachments: import_joi141.default.array().items(import_joi141.default.string().hex()).optional().default([]),
57392
+ reactions: import_joi141.default.string().optional().allow("", null).default(""),
57393
+ bidId: import_joi141.default.string().hex().length(24).optional().allow("", null),
57394
+ edited: import_joi141.default.boolean().optional().default(false)
57395
+ });
57396
+ function toObjectId21(value, label) {
57397
+ if (typeof value === "string") {
57398
+ try {
57399
+ return new import_mongodb141.ObjectId(value);
57400
+ } catch {
57401
+ throw new Error(`Invalid ${label}.`);
57402
+ }
57403
+ }
57404
+ return value;
57405
+ }
57406
+ function MChatPreloved(value) {
57407
+ const { error } = schemaChatPreloved.validate(value);
57408
+ if (error)
57409
+ throw new Error(error.details[0].message);
57410
+ if (value.channelId)
57411
+ value.channelId = toObjectId21(value.channelId, "channel ID");
57412
+ if (value.senderId)
57413
+ value.senderId = toObjectId21(value.senderId, "sender ID");
57414
+ if (value.postId)
57415
+ value.postId = toObjectId21(value.postId, "post ID");
57416
+ if (value.bidId)
57417
+ value.bidId = toObjectId21(value.bidId, "bid ID");
57418
+ if (value.message?.senderId) {
57419
+ value.message.senderId = toObjectId21(value.message.senderId, "message sender ID");
57420
+ }
57421
+ if (value.readMessage?.length) {
57422
+ value.readMessage = value.readMessage.map((id) => toObjectId21(id, "readMessage ID"));
57423
+ }
57424
+ if (value.viewMessage?.length) {
57425
+ value.viewMessage = value.viewMessage.map((id) => toObjectId21(id, "viewMessage ID"));
57426
+ }
57427
+ if (value.attachments?.length) {
57428
+ value.attachments = value.attachments.map((id) => toObjectId21(id, "attachment ID"));
57429
+ }
57430
+ return {
57431
+ _id: new import_mongodb141.ObjectId(),
57432
+ channelId: value.channelId ?? "",
57433
+ senderId: value.senderId ?? "",
57434
+ postId: value.postId ?? null,
57435
+ message: {
57436
+ text: value.message?.text ?? "",
57437
+ date: value.message?.date ?? (/* @__PURE__ */ new Date()).toISOString(),
57438
+ time: value.message?.time ?? "",
57439
+ senderId: value.message?.senderId ?? ""
57440
+ },
57441
+ readMessage: value.readMessage ?? [],
57442
+ viewMessage: value.viewMessage ?? [],
57443
+ attachments: value.attachments ?? [],
57444
+ reactions: value.reactions ?? "",
57445
+ bidId: value.bidId ?? null,
57446
+ edited: value.edited ?? false,
57447
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
57448
+ updatedAt: null,
57449
+ deletedAt: null
57450
+ };
57451
+ }
57452
+
57453
+ // src/repositories/chat-preloved.repo.ts
57454
+ var import_node_server_utils245 = require("@7365admin1/node-server-utils");
57455
+ function useChatPrelovedRepo() {
57456
+ const db = import_node_server_utils245.useAtlas.getDb();
57457
+ if (!db)
57458
+ throw new import_node_server_utils245.InternalServerError("Unable to connect to server.");
57459
+ const CHAT_COLLECTION = "chat-preloved";
57460
+ const collection = db.collection(CHAT_COLLECTION);
57461
+ async function add(value, session) {
57462
+ try {
57463
+ const doc = MChatPreloved(value);
57464
+ const res = await collection.insertOne(doc, { session });
57465
+ return res.insertedId;
57466
+ } catch (error) {
57467
+ throw error;
57468
+ }
57469
+ }
57470
+ return { add };
57471
+ }
57472
+
57473
+ // src/controllers/chat-preloved.controller.ts
57474
+ var import_node_server_utils246 = require("@7365admin1/node-server-utils");
57475
+ function useChatPrelovedController() {
57476
+ const { add: _add } = useChatPrelovedRepo();
57477
+ async function add(req, res, next) {
57478
+ const { error, value } = schemaChatPreloved.validate(req.body, {
57479
+ abortEarly: false
57480
+ });
57481
+ if (error) {
57482
+ const messages = error.details.map((d) => d.message).join(", ");
57483
+ import_node_server_utils246.logger.log({ level: "error", message: messages });
57484
+ next(new import_node_server_utils246.BadRequestError(messages));
57485
+ return;
57486
+ }
57487
+ try {
57488
+ const data = await _add(value);
57489
+ res.status(201).json(data);
57490
+ } catch (error2) {
57491
+ import_node_server_utils246.logger.log({ level: "error", message: error2.message });
57492
+ next(error2);
57493
+ }
57494
+ }
57495
+ return { add };
57496
+ }
57497
+
57498
+ // src/models/online-forms-v2.model.ts
57499
+ var import_joi142 = __toESM(require("joi"));
57500
+ var import_mongodb142 = require("mongodb");
57341
57501
  var FormEntryStatus = /* @__PURE__ */ ((FormEntryStatus2) => {
57342
57502
  FormEntryStatus2["ACTIVE"] = "active";
57343
57503
  FormEntryStatus2["INACTIVE"] = "inactive";
57344
57504
  FormEntryStatus2["DELETED"] = "deleted";
57345
57505
  return FormEntryStatus2;
57346
57506
  })(FormEntryStatus || {});
57347
- var schemaFormEntry = import_joi141.default.object({
57348
- _id: import_joi141.default.string().hex().optional().allow("", null),
57349
- formType: import_joi141.default.string().required(),
57350
- block: import_joi141.default.string().optional().allow(null, ""),
57351
- level: import_joi141.default.string().optional().allow(null, ""),
57352
- unit: import_joi141.default.string().optional().allow(null, ""),
57353
- name: import_joi141.default.string().optional().allow(null, ""),
57354
- phoneNumber: import_joi141.default.string().optional().allow(null, ""),
57355
- fields: import_joi141.default.object().pattern(
57356
- import_joi141.default.string(),
57357
- import_joi141.default.alternatives().try(
57358
- import_joi141.default.string(),
57359
- import_joi141.default.number(),
57360
- import_joi141.default.boolean(),
57361
- import_joi141.default.valid(null)
57507
+ var schemaFormEntry = import_joi142.default.object({
57508
+ _id: import_joi142.default.string().hex().optional().allow("", null),
57509
+ formType: import_joi142.default.string().required(),
57510
+ block: import_joi142.default.string().optional().allow(null, ""),
57511
+ level: import_joi142.default.string().optional().allow(null, ""),
57512
+ unit: import_joi142.default.string().optional().allow(null, ""),
57513
+ name: import_joi142.default.string().optional().allow(null, ""),
57514
+ phoneNumber: import_joi142.default.string().optional().allow(null, ""),
57515
+ fields: import_joi142.default.object().pattern(
57516
+ import_joi142.default.string(),
57517
+ import_joi142.default.alternatives().try(
57518
+ import_joi142.default.string(),
57519
+ import_joi142.default.number(),
57520
+ import_joi142.default.boolean(),
57521
+ import_joi142.default.valid(null)
57362
57522
  )
57363
57523
  ).required(),
57364
- status: import_joi141.default.string().optional().allow("", null),
57365
- org: import_joi141.default.string().hex().optional().allow("", null),
57366
- site: import_joi141.default.string().hex().optional().allow("", null),
57367
- createdAt: import_joi141.default.date().optional().allow("", null),
57368
- updatedAt: import_joi141.default.date().optional().allow("", null),
57369
- deletedAt: import_joi141.default.date().optional().allow("", null)
57524
+ status: import_joi142.default.string().optional().allow("", null),
57525
+ org: import_joi142.default.string().hex().optional().allow("", null),
57526
+ site: import_joi142.default.string().hex().optional().allow("", null),
57527
+ createdAt: import_joi142.default.date().optional().allow("", null),
57528
+ updatedAt: import_joi142.default.date().optional().allow("", null),
57529
+ deletedAt: import_joi142.default.date().optional().allow("", null)
57370
57530
  });
57371
- var schemaUpdateFormEntry = import_joi141.default.object({
57372
- _id: import_joi141.default.string().hex().required(),
57373
- formType: import_joi141.default.string().optional().allow("", null),
57374
- block: import_joi141.default.string().optional().allow(null, ""),
57375
- level: import_joi141.default.string().optional().allow(null, ""),
57376
- unit: import_joi141.default.string().optional().allow(null, ""),
57377
- fields: import_joi141.default.object().pattern(
57378
- import_joi141.default.string(),
57379
- import_joi141.default.alternatives().try(
57380
- import_joi141.default.string(),
57381
- import_joi141.default.number(),
57382
- import_joi141.default.boolean(),
57383
- import_joi141.default.valid(null)
57531
+ var schemaUpdateFormEntry = import_joi142.default.object({
57532
+ _id: import_joi142.default.string().hex().required(),
57533
+ formType: import_joi142.default.string().optional().allow("", null),
57534
+ block: import_joi142.default.string().optional().allow(null, ""),
57535
+ level: import_joi142.default.string().optional().allow(null, ""),
57536
+ unit: import_joi142.default.string().optional().allow(null, ""),
57537
+ fields: import_joi142.default.object().pattern(
57538
+ import_joi142.default.string(),
57539
+ import_joi142.default.alternatives().try(
57540
+ import_joi142.default.string(),
57541
+ import_joi142.default.number(),
57542
+ import_joi142.default.boolean(),
57543
+ import_joi142.default.valid(null)
57384
57544
  )
57385
57545
  ).optional(),
57386
- status: import_joi141.default.string().optional().allow("", null),
57387
- updatedAt: import_joi141.default.date().optional().allow("", null),
57388
- deletedAt: import_joi141.default.date().optional().allow("", null)
57546
+ status: import_joi142.default.string().optional().allow("", null),
57547
+ updatedAt: import_joi142.default.date().optional().allow("", null),
57548
+ deletedAt: import_joi142.default.date().optional().allow("", null)
57389
57549
  });
57390
57550
  function MFormEntry(value) {
57391
57551
  const { error } = schemaFormEntry.validate(value);
@@ -57394,21 +57554,21 @@ function MFormEntry(value) {
57394
57554
  }
57395
57555
  if (value._id && typeof value._id === "string") {
57396
57556
  try {
57397
- value._id = new import_mongodb141.ObjectId(value._id);
57557
+ value._id = new import_mongodb142.ObjectId(value._id);
57398
57558
  } catch {
57399
57559
  throw new Error("Invalid ID.");
57400
57560
  }
57401
57561
  }
57402
57562
  if (value.org && typeof value.org === "string") {
57403
57563
  try {
57404
- value.org = new import_mongodb141.ObjectId(value.org);
57564
+ value.org = new import_mongodb142.ObjectId(value.org);
57405
57565
  } catch {
57406
57566
  throw new Error("Invalid org ID.");
57407
57567
  }
57408
57568
  }
57409
57569
  if (value.site && typeof value.site === "string") {
57410
57570
  try {
57411
- value.site = new import_mongodb141.ObjectId(value.site);
57571
+ value.site = new import_mongodb142.ObjectId(value.site);
57412
57572
  } catch {
57413
57573
  throw new Error("Invalid site ID.");
57414
57574
  }
@@ -57432,16 +57592,16 @@ function MFormEntry(value) {
57432
57592
  }
57433
57593
 
57434
57594
  // src/repositories/online-forms-v2.repository.ts
57435
- var import_node_server_utils245 = require("@7365admin1/node-server-utils");
57436
- var import_mongodb142 = require("mongodb");
57595
+ var import_node_server_utils247 = require("@7365admin1/node-server-utils");
57596
+ var import_mongodb143 = require("mongodb");
57437
57597
  var online_forms_namespace_collection = "online-forms";
57438
57598
  function useFormEntryRepo() {
57439
- const db = import_node_server_utils245.useAtlas.getDb();
57599
+ const db = import_node_server_utils247.useAtlas.getDb();
57440
57600
  if (!db) {
57441
- throw new import_node_server_utils245.InternalServerError("Unable to connect to server.");
57601
+ throw new import_node_server_utils247.InternalServerError("Unable to connect to server.");
57442
57602
  }
57443
57603
  const collection = db.collection(online_forms_namespace_collection);
57444
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils245.useCache)(
57604
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils247.useCache)(
57445
57605
  online_forms_namespace_collection
57446
57606
  );
57447
57607
  async function createTextIndex() {
@@ -57450,7 +57610,7 @@ function useFormEntryRepo() {
57450
57610
  name: "text"
57451
57611
  });
57452
57612
  } catch (error) {
57453
- throw new import_node_server_utils245.InternalServerError(
57613
+ throw new import_node_server_utils247.InternalServerError(
57454
57614
  "Failed to create text index on online form."
57455
57615
  );
57456
57616
  }
@@ -57460,11 +57620,11 @@ function useFormEntryRepo() {
57460
57620
  value = MFormEntry(value);
57461
57621
  const res = await collection.insertOne(value, { session });
57462
57622
  delNamespace().then(() => {
57463
- import_node_server_utils245.logger.info(
57623
+ import_node_server_utils247.logger.info(
57464
57624
  `Cache cleared for namespace: ${online_forms_namespace_collection}`
57465
57625
  );
57466
57626
  }).catch((err) => {
57467
- import_node_server_utils245.logger.error(
57627
+ import_node_server_utils247.logger.error(
57468
57628
  `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
57469
57629
  err
57470
57630
  );
@@ -57473,7 +57633,7 @@ function useFormEntryRepo() {
57473
57633
  } catch (error) {
57474
57634
  const isDuplicated = error.message.includes("duplicate");
57475
57635
  if (isDuplicated) {
57476
- throw new import_node_server_utils245.BadRequestError("Online Form already exists.");
57636
+ throw new import_node_server_utils247.BadRequestError("Online Form already exists.");
57477
57637
  }
57478
57638
  throw error;
57479
57639
  }
@@ -57499,16 +57659,16 @@ function useFormEntryRepo() {
57499
57659
  };
57500
57660
  const query = {
57501
57661
  ...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } },
57502
- ...site && { site: new import_mongodb142.ObjectId(site) },
57662
+ ...site && { site: new import_mongodb143.ObjectId(site) },
57503
57663
  ...search && { search: [{ name: { $regex: search, $options: "i" } }] }
57504
57664
  };
57505
- const cacheKey = (0, import_node_server_utils245.makeCacheKey)(
57665
+ const cacheKey = (0, import_node_server_utils247.makeCacheKey)(
57506
57666
  online_forms_namespace_collection,
57507
57667
  cacheOptions
57508
57668
  );
57509
57669
  const cachedData = await getCache(cacheKey);
57510
57670
  if (cachedData) {
57511
- import_node_server_utils245.logger.info(`Cache hit for key: ${cacheKey}`);
57671
+ import_node_server_utils247.logger.info(`Cache hit for key: ${cacheKey}`);
57512
57672
  return cachedData;
57513
57673
  }
57514
57674
  try {
@@ -57519,11 +57679,11 @@ function useFormEntryRepo() {
57519
57679
  { $limit: limit }
57520
57680
  ]).toArray();
57521
57681
  const length = await collection.countDocuments(query);
57522
- const data = (0, import_node_server_utils245.paginate)(items, page, limit, length);
57682
+ const data = (0, import_node_server_utils247.paginate)(items, page, limit, length);
57523
57683
  setCache(cacheKey, data, 15 * 60).then(() => {
57524
- import_node_server_utils245.logger.info(`Cache set for key: ${cacheKey}`);
57684
+ import_node_server_utils247.logger.info(`Cache set for key: ${cacheKey}`);
57525
57685
  }).catch((err) => {
57526
- import_node_server_utils245.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
57686
+ import_node_server_utils247.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
57527
57687
  });
57528
57688
  return data;
57529
57689
  } catch (error) {
@@ -57531,27 +57691,27 @@ function useFormEntryRepo() {
57531
57691
  }
57532
57692
  }
57533
57693
  async function getFormEntryById(_id) {
57534
- const cacheKey = (0, import_node_server_utils245.makeCacheKey)(online_forms_namespace_collection, { _id });
57694
+ const cacheKey = (0, import_node_server_utils247.makeCacheKey)(online_forms_namespace_collection, { _id });
57535
57695
  const cachedData = await getCache(cacheKey);
57536
57696
  if (cachedData) {
57537
- import_node_server_utils245.logger.info(`Cache hit for key: ${cacheKey}`);
57697
+ import_node_server_utils247.logger.info(`Cache hit for key: ${cacheKey}`);
57538
57698
  return cachedData;
57539
57699
  }
57540
57700
  try {
57541
- _id = new import_mongodb142.ObjectId(_id);
57701
+ _id = new import_mongodb143.ObjectId(_id);
57542
57702
  } catch (error) {
57543
- throw new import_node_server_utils245.BadRequestError("Invalid online form ID format.");
57703
+ throw new import_node_server_utils247.BadRequestError("Invalid online form ID format.");
57544
57704
  }
57545
57705
  const query = { _id, status: { $ne: "deleted" } };
57546
57706
  try {
57547
57707
  const [data] = await collection.aggregate([{ $match: query }]).toArray();
57548
57708
  if (!data) {
57549
- throw new import_node_server_utils245.NotFoundError("Document not found.");
57709
+ throw new import_node_server_utils247.NotFoundError("Document not found.");
57550
57710
  }
57551
57711
  setCache(cacheKey, data, 15 * 60).then(() => {
57552
- import_node_server_utils245.logger.info(`Cache set for key: ${cacheKey}`);
57712
+ import_node_server_utils247.logger.info(`Cache set for key: ${cacheKey}`);
57553
57713
  }).catch((err) => {
57554
- import_node_server_utils245.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
57714
+ import_node_server_utils247.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
57555
57715
  });
57556
57716
  return data;
57557
57717
  } catch (error) {
@@ -57560,9 +57720,9 @@ function useFormEntryRepo() {
57560
57720
  }
57561
57721
  async function updateFormEntryById(_id, value) {
57562
57722
  try {
57563
- _id = new import_mongodb142.ObjectId(_id);
57723
+ _id = new import_mongodb143.ObjectId(_id);
57564
57724
  } catch (error) {
57565
- throw new import_node_server_utils245.BadRequestError("Invalid online form ID format.");
57725
+ throw new import_node_server_utils247.BadRequestError("Invalid online form ID format.");
57566
57726
  }
57567
57727
  try {
57568
57728
  const updateValue = {
@@ -57571,14 +57731,14 @@ function useFormEntryRepo() {
57571
57731
  };
57572
57732
  const res = await collection.updateOne({ _id }, { $set: updateValue });
57573
57733
  if (res.modifiedCount === 0) {
57574
- throw new import_node_server_utils245.InternalServerError("Unable to update online form.");
57734
+ throw new import_node_server_utils247.InternalServerError("Unable to update online form.");
57575
57735
  }
57576
57736
  delNamespace().then(() => {
57577
- import_node_server_utils245.logger.info(
57737
+ import_node_server_utils247.logger.info(
57578
57738
  `Cache cleared for namespace: ${online_forms_namespace_collection}`
57579
57739
  );
57580
57740
  }).catch((err) => {
57581
- import_node_server_utils245.logger.error(
57741
+ import_node_server_utils247.logger.error(
57582
57742
  `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
57583
57743
  err
57584
57744
  );
@@ -57588,18 +57748,52 @@ function useFormEntryRepo() {
57588
57748
  throw error;
57589
57749
  }
57590
57750
  }
57751
+ async function deleteOnlineFormById(_id, session) {
57752
+ try {
57753
+ _id = new import_mongodb143.ObjectId(_id);
57754
+ } catch (error) {
57755
+ throw new import_node_server_utils247.BadRequestError("Invalid online form ID format.");
57756
+ }
57757
+ try {
57758
+ const updateValue = {
57759
+ status: "deleted",
57760
+ updatedAt: /* @__PURE__ */ new Date(),
57761
+ deletedAt: /* @__PURE__ */ new Date()
57762
+ };
57763
+ const res = await collection.updateOne(
57764
+ { _id },
57765
+ { $set: updateValue },
57766
+ { session }
57767
+ );
57768
+ if (res.modifiedCount === 0) {
57769
+ throw new import_node_server_utils247.InternalServerError("Unable to delete online form.");
57770
+ }
57771
+ delNamespace().then(() => {
57772
+ import_node_server_utils247.logger.info(`Cache cleared for namespace: ${online_forms_namespace_collection}`);
57773
+ }).catch((err) => {
57774
+ import_node_server_utils247.logger.error(
57775
+ `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
57776
+ err
57777
+ );
57778
+ });
57779
+ return res.modifiedCount;
57780
+ } catch (error) {
57781
+ throw new Error(error.message);
57782
+ }
57783
+ }
57591
57784
  return {
57592
57785
  add,
57593
57786
  getAll,
57594
57787
  getFormEntryById,
57595
57788
  updateFormEntryById,
57596
- createTextIndex
57789
+ createTextIndex,
57790
+ deleteOnlineFormById
57597
57791
  };
57598
57792
  }
57599
57793
 
57600
57794
  // src/controllers/online-forms-v2.controller.ts
57601
- var import_node_server_utils246 = require("@7365admin1/node-server-utils");
57602
- var import_joi142 = __toESM(require("joi"));
57795
+ var import_node_server_utils248 = require("@7365admin1/node-server-utils");
57796
+ var import_joi143 = __toESM(require("joi"));
57603
57797
  var import_exceljs3 = __toESM(require("exceljs"));
57604
57798
  var import_fs6 = __toESM(require("fs"));
57605
57799
  function useFormEntryController() {
@@ -57607,7 +57801,8 @@ function useFormEntryController() {
57607
57801
  add: _add,
57608
57802
  getAll: _getAll,
57609
57803
  getFormEntryById: _getFormEntryById,
57610
- updateFormEntryById: _updateFormEntryById
57804
+ updateFormEntryById: _updateFormEntryById,
57805
+ deleteOnlineFormById: _deleteOnlineFormById
57611
57806
  } = useFormEntryRepo();
57612
57807
  function toCamelCase(str) {
57613
57808
  return str.replace(/\s(.)/g, (_, char) => char.toUpperCase()).replace(/\s+/g, "").replace(/^(.)/, (_, char) => char.toLowerCase());
@@ -57622,14 +57817,14 @@ function useFormEntryController() {
57622
57817
  async function uploadFormEntrys(req, res, next) {
57623
57818
  try {
57624
57819
  if (!req.file) {
57625
- next(new import_node_server_utils246.BadRequestError("Excel file is required."));
57820
+ next(new import_node_server_utils248.BadRequestError("Excel file is required."));
57626
57821
  return;
57627
57822
  }
57628
57823
  const workbook = new import_exceljs3.default.Workbook();
57629
57824
  await workbook.xlsx.readFile(req.file.path);
57630
57825
  const worksheet = workbook.worksheets[0];
57631
57826
  if (!worksheet) {
57632
- next(new import_node_server_utils246.BadRequestError("No worksheet found in uploaded Excel file."));
57827
+ next(new import_node_server_utils248.BadRequestError("No worksheet found in uploaded Excel file."));
57633
57828
  return;
57634
57829
  }
57635
57830
  const headerRow = worksheet.getRow(1);
@@ -57657,8 +57852,8 @@ function useFormEntryController() {
57657
57852
  });
57658
57853
  if (error) {
57659
57854
  const messages = error.details.map((d) => d.message).join(", ");
57660
- import_node_server_utils246.logger.log({ level: "error", message: messages });
57661
- next(new import_node_server_utils246.BadRequestError(messages));
57855
+ import_node_server_utils248.logger.log({ level: "error", message: messages });
57856
+ next(new import_node_server_utils248.BadRequestError(messages));
57662
57857
  return;
57663
57858
  }
57664
57859
  const result = await _add(value);
@@ -57666,25 +57861,25 @@ function useFormEntryController() {
57666
57861
  import_fs6.default.unlink(req.file.path, () => {
57667
57862
  });
57668
57863
  } catch (error) {
57669
- import_node_server_utils246.logger.log({ level: "error", message: error.message });
57864
+ import_node_server_utils248.logger.log({ level: "error", message: error.message });
57670
57865
  next(error);
57671
57866
  }
57672
57867
  }
57673
57868
  async function getAll(req, res, next) {
57674
57869
  try {
57675
- const schema2 = import_joi142.default.object({
57676
- search: import_joi142.default.string().optional().allow("", null),
57677
- page: import_joi142.default.number().integer().min(1).allow("", null).default(1),
57678
- limit: import_joi142.default.number().integer().min(1).max(100).allow("", null).default(10),
57679
- status: import_joi142.default.string().optional().allow(null, ""),
57680
- org: import_joi142.default.string().hex().optional().allow("", null),
57681
- site: import_joi142.default.string().hex().optional().allow("", null)
57870
+ const schema2 = import_joi143.default.object({
57871
+ search: import_joi143.default.string().optional().allow("", null),
57872
+ page: import_joi143.default.number().integer().min(1).allow("", null).default(1),
57873
+ limit: import_joi143.default.number().integer().min(1).max(100).allow("", null).default(10),
57874
+ status: import_joi143.default.string().optional().allow(null, ""),
57875
+ org: import_joi143.default.string().hex().optional().allow("", null),
57876
+ site: import_joi143.default.string().hex().optional().allow("", null)
57682
57877
  });
57683
57878
  const { error, value } = schema2.validate(req.query);
57684
57879
  if (error) {
57685
57880
  const messages = error.details.map((d) => d.message).join(", ");
57686
- import_node_server_utils246.logger.log({ level: "error", message: messages });
57687
- next(new import_node_server_utils246.BadRequestError(messages));
57881
+ import_node_server_utils248.logger.log({ level: "error", message: messages });
57882
+ next(new import_node_server_utils248.BadRequestError(messages));
57688
57883
  return;
57689
57884
  }
57690
57885
  const { search, page, limit, status, org, site } = value;
@@ -57692,21 +57887,21 @@ function useFormEntryController() {
57692
57887
  res.json(data);
57693
57888
  return;
57694
57889
  } catch (error) {
57695
- import_node_server_utils246.logger.log({ level: "error", message: error.message });
57890
+ import_node_server_utils248.logger.log({ level: "error", message: error.message });
57696
57891
  next(error);
57697
57892
  return;
57698
57893
  }
57699
57894
  }
57700
57895
  async function getFormEntryById(req, res, next) {
57701
57896
  try {
57702
- const schema2 = import_joi142.default.object({
57703
- _id: import_joi142.default.string().hex().length(24).required()
57897
+ const schema2 = import_joi143.default.object({
57898
+ _id: import_joi143.default.string().hex().length(24).required()
57704
57899
  });
57705
57900
  const { error, value } = schema2.validate({ _id: req.params.id });
57706
57901
  if (error) {
57707
57902
  const messages = error.details.map((d) => d.message).join(", ");
57708
- import_node_server_utils246.logger.log({ level: "error", message: messages });
57709
- next(new import_node_server_utils246.BadRequestError(messages));
57903
+ import_node_server_utils248.logger.log({ level: "error", message: messages });
57904
+ next(new import_node_server_utils248.BadRequestError(messages));
57710
57905
  return;
57711
57906
  }
57712
57907
  const { _id } = value;
@@ -57714,7 +57909,7 @@ function useFormEntryController() {
57714
57909
  res.json(data);
57715
57910
  return;
57716
57911
  } catch (error) {
57717
- import_node_server_utils246.logger.log({ level: "error", message: error.message });
57912
+ import_node_server_utils248.logger.log({ level: "error", message: error.message });
57718
57913
  next(error);
57719
57914
  return;
57720
57915
  }
@@ -57727,8 +57922,8 @@ function useFormEntryController() {
57727
57922
  });
57728
57923
  if (error) {
57729
57924
  const messages = error.details.map((d) => d.message).join(", ");
57730
- import_node_server_utils246.logger.log({ level: "error", message: messages });
57731
- next(new import_node_server_utils246.BadRequestError(messages));
57925
+ import_node_server_utils248.logger.log({ level: "error", message: messages });
57926
+ next(new import_node_server_utils248.BadRequestError(messages));
57732
57927
  return;
57733
57928
  }
57734
57929
  const { _id, ...rest } = value;
@@ -57736,7 +57931,26 @@ function useFormEntryController() {
57736
57931
  res.json({ message: "Successfully updated online form." });
57737
57932
  return;
57738
57933
  } catch (error) {
57739
- import_node_server_utils246.logger.log({ level: "error", message: error.message });
57934
+ import_node_server_utils248.logger.log({ level: "error", message: error.message });
57935
+ next(error);
57936
+ return;
57937
+ }
57938
+ }
57939
+ async function deleteFormEntryById(req, res, next) {
57940
+ try {
57941
+ const validation = import_joi143.default.string().hex().required();
57942
+ const _id = req.params.id;
57943
+ const { error } = validation.validate(_id);
57944
+ if (error) {
57945
+ import_node_server_utils248.logger.log({ level: "error", message: error.message });
57946
+ next(new import_node_server_utils248.BadRequestError(error.message));
57947
+ return;
57948
+ }
57949
+ await _deleteOnlineFormById(_id);
57950
+ res.json({ message: "Successfully deleted online form." });
57951
+ return;
57952
+ } catch (error) {
57953
+ import_node_server_utils248.logger.log({ level: "error", message: error.message });
57740
57954
  next(error);
57741
57955
  return;
57742
57956
  }
@@ -57745,16 +57959,17 @@ function useFormEntryController() {
57745
57959
  uploadFormEntrys,
57746
57960
  getAll,
57747
57961
  getFormEntryById,
57748
- updateFormEntryById
57962
+ updateFormEntryById,
57963
+ deleteFormEntryById
57749
57964
  };
57750
57965
  }
57751
57966
 
57752
57967
  // src/services/building-level.service.ts
57753
- var import_node_server_utils247 = require("@7365admin1/node-server-utils");
57968
+ var import_node_server_utils249 = require("@7365admin1/node-server-utils");
57754
57969
  function useBuildingLevelService() {
57755
57970
  const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelRepo();
57756
57971
  async function add(value) {
57757
- const session = import_node_server_utils247.useAtlas.getClient()?.startSession();
57972
+ const session = import_node_server_utils249.useAtlas.getClient()?.startSession();
57758
57973
  try {
57759
57974
  session?.startTransaction();
57760
57975
  await _add(value, session);
@@ -57768,7 +57983,7 @@ function useBuildingLevelService() {
57768
57983
  }
57769
57984
  }
57770
57985
  async function updateLevelById(_id, value) {
57771
- const session = import_node_server_utils247.useAtlas.getClient()?.startSession();
57986
+ const session = import_node_server_utils249.useAtlas.getClient()?.startSession();
57772
57987
  try {
57773
57988
  session?.startTransaction();
57774
57989
  await _updateLevelById(_id, value, session);
@@ -57788,8 +58003,8 @@ function useBuildingLevelService() {
57788
58003
  }
57789
58004
 
57790
58005
  // src/controllers/building-level.controller.ts
57791
- var import_node_server_utils248 = require("@7365admin1/node-server-utils");
57792
- var import_joi143 = __toESM(require("joi"));
58006
+ var import_node_server_utils250 = require("@7365admin1/node-server-utils");
58007
+ var import_joi144 = __toESM(require("joi"));
57793
58008
  function useBuildingLevelController() {
57794
58009
  const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelService();
57795
58010
  const {
@@ -57804,8 +58019,8 @@ function useBuildingLevelController() {
57804
58019
  });
57805
58020
  if (error) {
57806
58021
  const messages = error.details.map((d) => d.message).join(", ");
57807
- import_node_server_utils248.logger.log({ level: "error", message: messages });
57808
- next(new import_node_server_utils248.BadRequestError(messages));
58022
+ import_node_server_utils250.logger.log({ level: "error", message: messages });
58023
+ next(new import_node_server_utils250.BadRequestError(messages));
57809
58024
  return;
57810
58025
  }
57811
58026
  const result = await _add(value);
@@ -57816,20 +58031,20 @@ function useBuildingLevelController() {
57816
58031
  }
57817
58032
  async function getAll(req, res, next) {
57818
58033
  try {
57819
- const validation = import_joi143.default.object({
57820
- page: import_joi143.default.number().min(1).optional().default(1),
57821
- limit: import_joi143.default.number().min(1).optional().default(20),
57822
- search: import_joi143.default.string().optional().allow("", null),
57823
- site: import_joi143.default.string().hex().length(24).optional().allow("", null),
57824
- status: import_joi143.default.string().valid(...Object.values(BuildingLevelStatus)).default("active" /* ACTIVE */)
58034
+ const validation = import_joi144.default.object({
58035
+ page: import_joi144.default.number().min(1).optional().default(1),
58036
+ limit: import_joi144.default.number().min(1).optional().default(20),
58037
+ search: import_joi144.default.string().optional().allow("", null),
58038
+ site: import_joi144.default.string().hex().length(24).optional().allow("", null),
58039
+ status: import_joi144.default.string().valid(...Object.values(BuildingLevelStatus)).default("active" /* ACTIVE */)
57825
58040
  });
57826
58041
  const { error, value } = validation.validate(req.query, {
57827
58042
  abortEarly: false
57828
58043
  });
57829
58044
  if (error) {
57830
58045
  const messages = error.details.map((d) => d.message);
57831
- import_node_server_utils248.logger.log({ level: "error", message: messages.join(", ") });
57832
- next(new import_node_server_utils248.BadRequestError(messages.join(", ")));
58046
+ import_node_server_utils250.logger.log({ level: "error", message: messages.join(", ") });
58047
+ next(new import_node_server_utils250.BadRequestError(messages.join(", ")));
57833
58048
  return;
57834
58049
  }
57835
58050
  const { page, limit, status, site, search } = value;
@@ -57848,14 +58063,14 @@ function useBuildingLevelController() {
57848
58063
  }
57849
58064
  async function getById(req, res, next) {
57850
58065
  try {
57851
- const schema2 = import_joi143.default.object({
57852
- id: import_joi143.default.string().hex().length(24).required()
58066
+ const schema2 = import_joi144.default.object({
58067
+ id: import_joi144.default.string().hex().length(24).required()
57853
58068
  });
57854
58069
  const { error, value } = schema2.validate({ id: req.params.id });
57855
58070
  if (error) {
57856
58071
  const messages = error.details.map((d) => d.message);
57857
- import_node_server_utils248.logger.log({ level: "error", message: messages.join(", ") });
57858
- next(new import_node_server_utils248.BadRequestError(messages.join(", ")));
58072
+ import_node_server_utils250.logger.log({ level: "error", message: messages.join(", ") });
58073
+ next(new import_node_server_utils250.BadRequestError(messages.join(", ")));
57859
58074
  return;
57860
58075
  }
57861
58076
  const { id } = value;
@@ -57874,8 +58089,8 @@ function useBuildingLevelController() {
57874
58089
  });
57875
58090
  if (error) {
57876
58091
  const messages = error.details.map((d) => d.message);
57877
- import_node_server_utils248.logger.log({ level: "error", message: messages.join(", ") });
57878
- next(new import_node_server_utils248.BadRequestError(messages.join(", ")));
58092
+ import_node_server_utils250.logger.log({ level: "error", message: messages.join(", ") });
58093
+ next(new import_node_server_utils250.BadRequestError(messages.join(", ")));
57879
58094
  return;
57880
58095
  }
57881
58096
  const { _id, ...rest } = value;
@@ -57887,14 +58102,14 @@ function useBuildingLevelController() {
57887
58102
  }
57888
58103
  async function deleteById(req, res, next) {
57889
58104
  try {
57890
- const schema2 = import_joi143.default.object({
57891
- id: import_joi143.default.string().hex().required()
58105
+ const schema2 = import_joi144.default.object({
58106
+ id: import_joi144.default.string().hex().required()
57892
58107
  });
57893
58108
  const { error, value } = schema2.validate({ id: req.params.id });
57894
58109
  if (error) {
57895
58110
  const messages = error.details.map((d) => d.message);
57896
- import_node_server_utils248.logger.log({ level: "error", message: messages.join(", ") });
57897
- next(new import_node_server_utils248.BadRequestError(messages.join(", ")));
58111
+ import_node_server_utils250.logger.log({ level: "error", message: messages.join(", ") });
58112
+ next(new import_node_server_utils250.BadRequestError(messages.join(", ")));
57898
58113
  return;
57899
58114
  }
57900
58115
  const { id } = value;
@@ -57958,6 +58173,7 @@ function useBuildingLevelController() {
57958
58173
  MBulletinVideo,
57959
58174
  MCategoryPreloved,
57960
58175
  MChat,
58176
+ MChatPreloved,
57961
58177
  MCustomer,
57962
58178
  MCustomerSite,
57963
58179
  MDocumentManagement,
@@ -58102,6 +58318,7 @@ function useBuildingLevelController() {
58102
58318
  schemaBulletinBoard,
58103
58319
  schemaBulletinVideo,
58104
58320
  schemaCategoryPreloved,
58321
+ schemaChatPreloved,
58105
58322
  schemaCustomerSite,
58106
58323
  schemaDocumentManagement,
58107
58324
  schemaEntryPassSettings,
@@ -58209,6 +58426,8 @@ function useBuildingLevelController() {
58209
58426
  useCategoryPrelovedController,
58210
58427
  useCategoryPrelovedRepo,
58211
58428
  useChatController,
58429
+ useChatPrelovedController,
58430
+ useChatPrelovedRepo,
58212
58431
  useChatRepo,
58213
58432
  useCounterModel,
58214
58433
  useCounterRepo,