@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.mjs CHANGED
@@ -32654,19 +32654,19 @@ function useDocumentManagementRepo() {
32654
32654
  parentId = ""
32655
32655
  }) {
32656
32656
  page = page > 0 ? page - 1 : 0;
32657
+ const query = {
32658
+ status: { $ne: "deleted" }
32659
+ };
32660
+ const cacheOptions = {
32661
+ page,
32662
+ limit
32663
+ };
32657
32664
  try {
32658
- site = new ObjectId80(site);
32665
+ query.site = new ObjectId80(site);
32666
+ cacheOptions.site = site?.toString();
32659
32667
  } catch (error) {
32660
32668
  throw new BadRequestError126("Invalid site ID format.");
32661
32669
  }
32662
- const cacheOptions = {
32663
- page,
32664
- limit,
32665
- site: site?.toString()
32666
- };
32667
- const query = {
32668
- status: { $ne: "deleted" }
32669
- };
32670
32670
  if (type && type !== "all") {
32671
32671
  query.type = type;
32672
32672
  cacheOptions.type = type;
@@ -57226,14 +57226,29 @@ function useCategoryPrelovedRepo() {
57226
57226
  throw new InternalServerError77("Unable to update category.");
57227
57227
  return "Category updated successfully.";
57228
57228
  }
57229
- return { getAll, getById, addCategory, updateById };
57229
+ async function deleteById(_id) {
57230
+ let objectId2;
57231
+ try {
57232
+ objectId2 = new ObjectId138(_id);
57233
+ } catch {
57234
+ throw new BadRequestError216("Invalid category ID format.");
57235
+ }
57236
+ const existing = await collection.findOne({ _id: objectId2 });
57237
+ if (!existing)
57238
+ throw new NotFoundError58("Category not found.");
57239
+ const res = await collection.deleteOne({ _id: objectId2 });
57240
+ if (res.deletedCount === 0)
57241
+ throw new InternalServerError77("Unable to delete category.");
57242
+ return "Category deleted successfully.";
57243
+ }
57244
+ return { getAll, getById, addCategory, updateById, deleteById };
57230
57245
  }
57231
57246
 
57232
57247
  // src/controllers/category-preloved.controller.ts
57233
57248
  import { BadRequestError as BadRequestError217, logger as logger191 } from "@7365admin1/node-server-utils";
57234
57249
  import Joi138 from "joi";
57235
57250
  function useCategoryPrelovedController() {
57236
- const { getAll: _getAll, getById: _getById, addCategory: _addCategory, updateById: _updateById } = useCategoryPrelovedRepo();
57251
+ const { getAll: _getAll, getById: _getById, addCategory: _addCategory, updateById: _updateById, deleteById: _deleteById } = useCategoryPrelovedRepo();
57237
57252
  async function getAll(req, res, next) {
57238
57253
  const schema2 = Joi138.object({
57239
57254
  search: Joi138.string().optional().allow("", null),
@@ -57312,7 +57327,25 @@ function useCategoryPrelovedController() {
57312
57327
  next(error2);
57313
57328
  }
57314
57329
  }
57315
- return { getAll, getById, addCategory, updateById };
57330
+ async function deleteById(req, res, next) {
57331
+ const schema2 = Joi138.object({
57332
+ _id: Joi138.string().hex().length(24).required()
57333
+ });
57334
+ const { error, value } = schema2.validate({ _id: req.params.id });
57335
+ if (error) {
57336
+ logger191.log({ level: "error", message: error.message });
57337
+ next(new BadRequestError217(error.message));
57338
+ return;
57339
+ }
57340
+ try {
57341
+ const data = await _deleteById(value._id);
57342
+ res.status(200).json(data);
57343
+ } catch (error2) {
57344
+ logger191.log({ level: "error", message: error2.message });
57345
+ next(error2);
57346
+ }
57347
+ }
57348
+ return { getAll, getById, addCategory, updateById, deleteById };
57316
57349
  }
57317
57350
 
57318
57351
  // src/models/subcategory-preloved.model.ts
@@ -57603,57 +57636,183 @@ function useSubcategoryPrelovedController() {
57603
57636
  return { getAll, getById, addSubcategory, updateById, deleteById };
57604
57637
  }
57605
57638
 
57606
- // src/models/online-forms-v2.model.ts
57639
+ // src/models/chat-preloved.model.ts
57607
57640
  import Joi141 from "joi";
57608
57641
  import { ObjectId as ObjectId141 } from "mongodb";
57642
+ var schemaMessage = Joi141.object({
57643
+ text: Joi141.string().required(),
57644
+ date: Joi141.date().optional().allow(null),
57645
+ time: Joi141.string().optional().allow("", null),
57646
+ senderId: Joi141.string().hex().length(24).required()
57647
+ });
57648
+ var schemaChatPreloved = Joi141.object({
57649
+ channelId: Joi141.string().hex().length(24).required(),
57650
+ senderId: Joi141.string().hex().length(24).required(),
57651
+ postId: Joi141.string().hex().length(24).optional().allow("", null),
57652
+ message: schemaMessage.required(),
57653
+ readMessage: Joi141.array().items(Joi141.string().hex()).optional().default([]),
57654
+ viewMessage: Joi141.array().items(Joi141.string().hex()).optional().default([]),
57655
+ attachments: Joi141.array().items(Joi141.string().hex()).optional().default([]),
57656
+ reactions: Joi141.string().optional().allow("", null).default(""),
57657
+ bidId: Joi141.string().hex().length(24).optional().allow("", null),
57658
+ edited: Joi141.boolean().optional().default(false)
57659
+ });
57660
+ function toObjectId21(value, label) {
57661
+ if (typeof value === "string") {
57662
+ try {
57663
+ return new ObjectId141(value);
57664
+ } catch {
57665
+ throw new Error(`Invalid ${label}.`);
57666
+ }
57667
+ }
57668
+ return value;
57669
+ }
57670
+ function MChatPreloved(value) {
57671
+ const { error } = schemaChatPreloved.validate(value);
57672
+ if (error)
57673
+ throw new Error(error.details[0].message);
57674
+ if (value.channelId)
57675
+ value.channelId = toObjectId21(value.channelId, "channel ID");
57676
+ if (value.senderId)
57677
+ value.senderId = toObjectId21(value.senderId, "sender ID");
57678
+ if (value.postId)
57679
+ value.postId = toObjectId21(value.postId, "post ID");
57680
+ if (value.bidId)
57681
+ value.bidId = toObjectId21(value.bidId, "bid ID");
57682
+ if (value.message?.senderId) {
57683
+ value.message.senderId = toObjectId21(value.message.senderId, "message sender ID");
57684
+ }
57685
+ if (value.readMessage?.length) {
57686
+ value.readMessage = value.readMessage.map((id) => toObjectId21(id, "readMessage ID"));
57687
+ }
57688
+ if (value.viewMessage?.length) {
57689
+ value.viewMessage = value.viewMessage.map((id) => toObjectId21(id, "viewMessage ID"));
57690
+ }
57691
+ if (value.attachments?.length) {
57692
+ value.attachments = value.attachments.map((id) => toObjectId21(id, "attachment ID"));
57693
+ }
57694
+ return {
57695
+ _id: new ObjectId141(),
57696
+ channelId: value.channelId ?? "",
57697
+ senderId: value.senderId ?? "",
57698
+ postId: value.postId ?? null,
57699
+ message: {
57700
+ text: value.message?.text ?? "",
57701
+ date: value.message?.date ?? (/* @__PURE__ */ new Date()).toISOString(),
57702
+ time: value.message?.time ?? "",
57703
+ senderId: value.message?.senderId ?? ""
57704
+ },
57705
+ readMessage: value.readMessage ?? [],
57706
+ viewMessage: value.viewMessage ?? [],
57707
+ attachments: value.attachments ?? [],
57708
+ reactions: value.reactions ?? "",
57709
+ bidId: value.bidId ?? null,
57710
+ edited: value.edited ?? false,
57711
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
57712
+ updatedAt: null,
57713
+ deletedAt: null
57714
+ };
57715
+ }
57716
+
57717
+ // src/repositories/chat-preloved.repo.ts
57718
+ import {
57719
+ InternalServerError as InternalServerError79,
57720
+ useAtlas as useAtlas124
57721
+ } from "@7365admin1/node-server-utils";
57722
+ function useChatPrelovedRepo() {
57723
+ const db = useAtlas124.getDb();
57724
+ if (!db)
57725
+ throw new InternalServerError79("Unable to connect to server.");
57726
+ const CHAT_COLLECTION = "chat-preloved";
57727
+ const collection = db.collection(CHAT_COLLECTION);
57728
+ async function add(value, session) {
57729
+ try {
57730
+ const doc = MChatPreloved(value);
57731
+ const res = await collection.insertOne(doc, { session });
57732
+ return res.insertedId;
57733
+ } catch (error) {
57734
+ throw error;
57735
+ }
57736
+ }
57737
+ return { add };
57738
+ }
57739
+
57740
+ // src/controllers/chat-preloved.controller.ts
57741
+ import { BadRequestError as BadRequestError221, logger as logger193 } from "@7365admin1/node-server-utils";
57742
+ function useChatPrelovedController() {
57743
+ const { add: _add } = useChatPrelovedRepo();
57744
+ async function add(req, res, next) {
57745
+ const { error, value } = schemaChatPreloved.validate(req.body, {
57746
+ abortEarly: false
57747
+ });
57748
+ if (error) {
57749
+ const messages = error.details.map((d) => d.message).join(", ");
57750
+ logger193.log({ level: "error", message: messages });
57751
+ next(new BadRequestError221(messages));
57752
+ return;
57753
+ }
57754
+ try {
57755
+ const data = await _add(value);
57756
+ res.status(201).json(data);
57757
+ } catch (error2) {
57758
+ logger193.log({ level: "error", message: error2.message });
57759
+ next(error2);
57760
+ }
57761
+ }
57762
+ return { add };
57763
+ }
57764
+
57765
+ // src/models/online-forms-v2.model.ts
57766
+ import Joi142 from "joi";
57767
+ import { ObjectId as ObjectId142 } from "mongodb";
57609
57768
  var FormEntryStatus = /* @__PURE__ */ ((FormEntryStatus2) => {
57610
57769
  FormEntryStatus2["ACTIVE"] = "active";
57611
57770
  FormEntryStatus2["INACTIVE"] = "inactive";
57612
57771
  FormEntryStatus2["DELETED"] = "deleted";
57613
57772
  return FormEntryStatus2;
57614
57773
  })(FormEntryStatus || {});
57615
- var schemaFormEntry = Joi141.object({
57616
- _id: Joi141.string().hex().optional().allow("", null),
57617
- formType: Joi141.string().required(),
57618
- block: Joi141.string().optional().allow(null, ""),
57619
- level: Joi141.string().optional().allow(null, ""),
57620
- unit: Joi141.string().optional().allow(null, ""),
57621
- name: Joi141.string().optional().allow(null, ""),
57622
- phoneNumber: Joi141.string().optional().allow(null, ""),
57623
- fields: Joi141.object().pattern(
57624
- Joi141.string(),
57625
- Joi141.alternatives().try(
57626
- Joi141.string(),
57627
- Joi141.number(),
57628
- Joi141.boolean(),
57629
- Joi141.valid(null)
57774
+ var schemaFormEntry = Joi142.object({
57775
+ _id: Joi142.string().hex().optional().allow("", null),
57776
+ formType: Joi142.string().required(),
57777
+ block: Joi142.string().optional().allow(null, ""),
57778
+ level: Joi142.string().optional().allow(null, ""),
57779
+ unit: Joi142.string().optional().allow(null, ""),
57780
+ name: Joi142.string().optional().allow(null, ""),
57781
+ phoneNumber: Joi142.string().optional().allow(null, ""),
57782
+ fields: Joi142.object().pattern(
57783
+ Joi142.string(),
57784
+ Joi142.alternatives().try(
57785
+ Joi142.string(),
57786
+ Joi142.number(),
57787
+ Joi142.boolean(),
57788
+ Joi142.valid(null)
57630
57789
  )
57631
57790
  ).required(),
57632
- status: Joi141.string().optional().allow("", null),
57633
- org: Joi141.string().hex().optional().allow("", null),
57634
- site: Joi141.string().hex().optional().allow("", null),
57635
- createdAt: Joi141.date().optional().allow("", null),
57636
- updatedAt: Joi141.date().optional().allow("", null),
57637
- deletedAt: Joi141.date().optional().allow("", null)
57791
+ status: Joi142.string().optional().allow("", null),
57792
+ org: Joi142.string().hex().optional().allow("", null),
57793
+ site: Joi142.string().hex().optional().allow("", null),
57794
+ createdAt: Joi142.date().optional().allow("", null),
57795
+ updatedAt: Joi142.date().optional().allow("", null),
57796
+ deletedAt: Joi142.date().optional().allow("", null)
57638
57797
  });
57639
- var schemaUpdateFormEntry = Joi141.object({
57640
- _id: Joi141.string().hex().required(),
57641
- formType: Joi141.string().optional().allow("", null),
57642
- block: Joi141.string().optional().allow(null, ""),
57643
- level: Joi141.string().optional().allow(null, ""),
57644
- unit: Joi141.string().optional().allow(null, ""),
57645
- fields: Joi141.object().pattern(
57646
- Joi141.string(),
57647
- Joi141.alternatives().try(
57648
- Joi141.string(),
57649
- Joi141.number(),
57650
- Joi141.boolean(),
57651
- Joi141.valid(null)
57798
+ var schemaUpdateFormEntry = Joi142.object({
57799
+ _id: Joi142.string().hex().required(),
57800
+ formType: Joi142.string().optional().allow("", null),
57801
+ block: Joi142.string().optional().allow(null, ""),
57802
+ level: Joi142.string().optional().allow(null, ""),
57803
+ unit: Joi142.string().optional().allow(null, ""),
57804
+ fields: Joi142.object().pattern(
57805
+ Joi142.string(),
57806
+ Joi142.alternatives().try(
57807
+ Joi142.string(),
57808
+ Joi142.number(),
57809
+ Joi142.boolean(),
57810
+ Joi142.valid(null)
57652
57811
  )
57653
57812
  ).optional(),
57654
- status: Joi141.string().optional().allow("", null),
57655
- updatedAt: Joi141.date().optional().allow("", null),
57656
- deletedAt: Joi141.date().optional().allow("", null)
57813
+ status: Joi142.string().optional().allow("", null),
57814
+ updatedAt: Joi142.date().optional().allow("", null),
57815
+ deletedAt: Joi142.date().optional().allow("", null)
57657
57816
  });
57658
57817
  function MFormEntry(value) {
57659
57818
  const { error } = schemaFormEntry.validate(value);
@@ -57662,21 +57821,21 @@ function MFormEntry(value) {
57662
57821
  }
57663
57822
  if (value._id && typeof value._id === "string") {
57664
57823
  try {
57665
- value._id = new ObjectId141(value._id);
57824
+ value._id = new ObjectId142(value._id);
57666
57825
  } catch {
57667
57826
  throw new Error("Invalid ID.");
57668
57827
  }
57669
57828
  }
57670
57829
  if (value.org && typeof value.org === "string") {
57671
57830
  try {
57672
- value.org = new ObjectId141(value.org);
57831
+ value.org = new ObjectId142(value.org);
57673
57832
  } catch {
57674
57833
  throw new Error("Invalid org ID.");
57675
57834
  }
57676
57835
  }
57677
57836
  if (value.site && typeof value.site === "string") {
57678
57837
  try {
57679
- value.site = new ObjectId141(value.site);
57838
+ value.site = new ObjectId142(value.site);
57680
57839
  } catch {
57681
57840
  throw new Error("Invalid site ID.");
57682
57841
  }
@@ -57701,21 +57860,21 @@ function MFormEntry(value) {
57701
57860
 
57702
57861
  // src/repositories/online-forms-v2.repository.ts
57703
57862
  import {
57704
- BadRequestError as BadRequestError220,
57705
- InternalServerError as InternalServerError79,
57706
- logger as logger193,
57863
+ BadRequestError as BadRequestError222,
57864
+ InternalServerError as InternalServerError80,
57865
+ logger as logger194,
57707
57866
  makeCacheKey as makeCacheKey66,
57708
57867
  NotFoundError as NotFoundError60,
57709
57868
  paginate as paginate62,
57710
- useAtlas as useAtlas124,
57869
+ useAtlas as useAtlas125,
57711
57870
  useCache as useCache70
57712
57871
  } from "@7365admin1/node-server-utils";
57713
- import { ObjectId as ObjectId142 } from "mongodb";
57872
+ import { ObjectId as ObjectId143 } from "mongodb";
57714
57873
  var online_forms_namespace_collection = "online-forms";
57715
57874
  function useFormEntryRepo() {
57716
- const db = useAtlas124.getDb();
57875
+ const db = useAtlas125.getDb();
57717
57876
  if (!db) {
57718
- throw new InternalServerError79("Unable to connect to server.");
57877
+ throw new InternalServerError80("Unable to connect to server.");
57719
57878
  }
57720
57879
  const collection = db.collection(online_forms_namespace_collection);
57721
57880
  const { delNamespace, getCache, setCache } = useCache70(
@@ -57727,7 +57886,7 @@ function useFormEntryRepo() {
57727
57886
  name: "text"
57728
57887
  });
57729
57888
  } catch (error) {
57730
- throw new InternalServerError79(
57889
+ throw new InternalServerError80(
57731
57890
  "Failed to create text index on online form."
57732
57891
  );
57733
57892
  }
@@ -57737,11 +57896,11 @@ function useFormEntryRepo() {
57737
57896
  value = MFormEntry(value);
57738
57897
  const res = await collection.insertOne(value, { session });
57739
57898
  delNamespace().then(() => {
57740
- logger193.info(
57899
+ logger194.info(
57741
57900
  `Cache cleared for namespace: ${online_forms_namespace_collection}`
57742
57901
  );
57743
57902
  }).catch((err) => {
57744
- logger193.error(
57903
+ logger194.error(
57745
57904
  `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
57746
57905
  err
57747
57906
  );
@@ -57750,7 +57909,7 @@ function useFormEntryRepo() {
57750
57909
  } catch (error) {
57751
57910
  const isDuplicated = error.message.includes("duplicate");
57752
57911
  if (isDuplicated) {
57753
- throw new BadRequestError220("Online Form already exists.");
57912
+ throw new BadRequestError222("Online Form already exists.");
57754
57913
  }
57755
57914
  throw error;
57756
57915
  }
@@ -57776,7 +57935,7 @@ function useFormEntryRepo() {
57776
57935
  };
57777
57936
  const query = {
57778
57937
  ...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } },
57779
- ...site && { site: new ObjectId142(site) },
57938
+ ...site && { site: new ObjectId143(site) },
57780
57939
  ...search && { search: [{ name: { $regex: search, $options: "i" } }] }
57781
57940
  };
57782
57941
  const cacheKey = makeCacheKey66(
@@ -57785,7 +57944,7 @@ function useFormEntryRepo() {
57785
57944
  );
57786
57945
  const cachedData = await getCache(cacheKey);
57787
57946
  if (cachedData) {
57788
- logger193.info(`Cache hit for key: ${cacheKey}`);
57947
+ logger194.info(`Cache hit for key: ${cacheKey}`);
57789
57948
  return cachedData;
57790
57949
  }
57791
57950
  try {
@@ -57798,9 +57957,9 @@ function useFormEntryRepo() {
57798
57957
  const length = await collection.countDocuments(query);
57799
57958
  const data = paginate62(items, page, limit, length);
57800
57959
  setCache(cacheKey, data, 15 * 60).then(() => {
57801
- logger193.info(`Cache set for key: ${cacheKey}`);
57960
+ logger194.info(`Cache set for key: ${cacheKey}`);
57802
57961
  }).catch((err) => {
57803
- logger193.error(`Failed to set cache for key: ${cacheKey}`, err);
57962
+ logger194.error(`Failed to set cache for key: ${cacheKey}`, err);
57804
57963
  });
57805
57964
  return data;
57806
57965
  } catch (error) {
@@ -57811,13 +57970,13 @@ function useFormEntryRepo() {
57811
57970
  const cacheKey = makeCacheKey66(online_forms_namespace_collection, { _id });
57812
57971
  const cachedData = await getCache(cacheKey);
57813
57972
  if (cachedData) {
57814
- logger193.info(`Cache hit for key: ${cacheKey}`);
57973
+ logger194.info(`Cache hit for key: ${cacheKey}`);
57815
57974
  return cachedData;
57816
57975
  }
57817
57976
  try {
57818
- _id = new ObjectId142(_id);
57977
+ _id = new ObjectId143(_id);
57819
57978
  } catch (error) {
57820
- throw new BadRequestError220("Invalid online form ID format.");
57979
+ throw new BadRequestError222("Invalid online form ID format.");
57821
57980
  }
57822
57981
  const query = { _id, status: { $ne: "deleted" } };
57823
57982
  try {
@@ -57826,9 +57985,9 @@ function useFormEntryRepo() {
57826
57985
  throw new NotFoundError60("Document not found.");
57827
57986
  }
57828
57987
  setCache(cacheKey, data, 15 * 60).then(() => {
57829
- logger193.info(`Cache set for key: ${cacheKey}`);
57988
+ logger194.info(`Cache set for key: ${cacheKey}`);
57830
57989
  }).catch((err) => {
57831
- logger193.error(`Failed to set cache for key: ${cacheKey}`, err);
57990
+ logger194.error(`Failed to set cache for key: ${cacheKey}`, err);
57832
57991
  });
57833
57992
  return data;
57834
57993
  } catch (error) {
@@ -57837,9 +57996,9 @@ function useFormEntryRepo() {
57837
57996
  }
57838
57997
  async function updateFormEntryById(_id, value) {
57839
57998
  try {
57840
- _id = new ObjectId142(_id);
57999
+ _id = new ObjectId143(_id);
57841
58000
  } catch (error) {
57842
- throw new BadRequestError220("Invalid online form ID format.");
58001
+ throw new BadRequestError222("Invalid online form ID format.");
57843
58002
  }
57844
58003
  try {
57845
58004
  const updateValue = {
@@ -57848,14 +58007,14 @@ function useFormEntryRepo() {
57848
58007
  };
57849
58008
  const res = await collection.updateOne({ _id }, { $set: updateValue });
57850
58009
  if (res.modifiedCount === 0) {
57851
- throw new InternalServerError79("Unable to update online form.");
58010
+ throw new InternalServerError80("Unable to update online form.");
57852
58011
  }
57853
58012
  delNamespace().then(() => {
57854
- logger193.info(
58013
+ logger194.info(
57855
58014
  `Cache cleared for namespace: ${online_forms_namespace_collection}`
57856
58015
  );
57857
58016
  }).catch((err) => {
57858
- logger193.error(
58017
+ logger194.error(
57859
58018
  `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
57860
58019
  err
57861
58020
  );
@@ -57865,18 +58024,52 @@ function useFormEntryRepo() {
57865
58024
  throw error;
57866
58025
  }
57867
58026
  }
58027
+ async function deleteOnlineFormById(_id, session) {
58028
+ try {
58029
+ _id = new ObjectId143(_id);
58030
+ } catch (error) {
58031
+ throw new BadRequestError222("Invalid online form ID format.");
58032
+ }
58033
+ try {
58034
+ const updateValue = {
58035
+ status: "deleted",
58036
+ updatedAt: /* @__PURE__ */ new Date(),
58037
+ deletedAt: /* @__PURE__ */ new Date()
58038
+ };
58039
+ const res = await collection.updateOne(
58040
+ { _id },
58041
+ { $set: updateValue },
58042
+ { session }
58043
+ );
58044
+ if (res.modifiedCount === 0) {
58045
+ throw new InternalServerError80("Unable to delete online form.");
58046
+ }
58047
+ delNamespace().then(() => {
58048
+ logger194.info(`Cache cleared for namespace: ${online_forms_namespace_collection}`);
58049
+ }).catch((err) => {
58050
+ logger194.error(
58051
+ `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
58052
+ err
58053
+ );
58054
+ });
58055
+ return res.modifiedCount;
58056
+ } catch (error) {
58057
+ throw new Error(error.message);
58058
+ }
58059
+ }
57868
58060
  return {
57869
58061
  add,
57870
58062
  getAll,
57871
58063
  getFormEntryById,
57872
58064
  updateFormEntryById,
57873
- createTextIndex
58065
+ createTextIndex,
58066
+ deleteOnlineFormById
57874
58067
  };
57875
58068
  }
57876
58069
 
57877
58070
  // src/controllers/online-forms-v2.controller.ts
57878
- import { BadRequestError as BadRequestError221, logger as logger194 } from "@7365admin1/node-server-utils";
57879
- import Joi142 from "joi";
58071
+ import { BadRequestError as BadRequestError223, logger as logger195 } from "@7365admin1/node-server-utils";
58072
+ import Joi143 from "joi";
57880
58073
  import ExcelJS3 from "exceljs";
57881
58074
  import fs5 from "fs";
57882
58075
  function useFormEntryController() {
@@ -57884,7 +58077,8 @@ function useFormEntryController() {
57884
58077
  add: _add,
57885
58078
  getAll: _getAll,
57886
58079
  getFormEntryById: _getFormEntryById,
57887
- updateFormEntryById: _updateFormEntryById
58080
+ updateFormEntryById: _updateFormEntryById,
58081
+ deleteOnlineFormById: _deleteOnlineFormById
57888
58082
  } = useFormEntryRepo();
57889
58083
  function toCamelCase(str) {
57890
58084
  return str.replace(/\s(.)/g, (_, char) => char.toUpperCase()).replace(/\s+/g, "").replace(/^(.)/, (_, char) => char.toLowerCase());
@@ -57899,14 +58093,14 @@ function useFormEntryController() {
57899
58093
  async function uploadFormEntrys(req, res, next) {
57900
58094
  try {
57901
58095
  if (!req.file) {
57902
- next(new BadRequestError221("Excel file is required."));
58096
+ next(new BadRequestError223("Excel file is required."));
57903
58097
  return;
57904
58098
  }
57905
58099
  const workbook = new ExcelJS3.Workbook();
57906
58100
  await workbook.xlsx.readFile(req.file.path);
57907
58101
  const worksheet = workbook.worksheets[0];
57908
58102
  if (!worksheet) {
57909
- next(new BadRequestError221("No worksheet found in uploaded Excel file."));
58103
+ next(new BadRequestError223("No worksheet found in uploaded Excel file."));
57910
58104
  return;
57911
58105
  }
57912
58106
  const headerRow = worksheet.getRow(1);
@@ -57934,8 +58128,8 @@ function useFormEntryController() {
57934
58128
  });
57935
58129
  if (error) {
57936
58130
  const messages = error.details.map((d) => d.message).join(", ");
57937
- logger194.log({ level: "error", message: messages });
57938
- next(new BadRequestError221(messages));
58131
+ logger195.log({ level: "error", message: messages });
58132
+ next(new BadRequestError223(messages));
57939
58133
  return;
57940
58134
  }
57941
58135
  const result = await _add(value);
@@ -57943,25 +58137,25 @@ function useFormEntryController() {
57943
58137
  fs5.unlink(req.file.path, () => {
57944
58138
  });
57945
58139
  } catch (error) {
57946
- logger194.log({ level: "error", message: error.message });
58140
+ logger195.log({ level: "error", message: error.message });
57947
58141
  next(error);
57948
58142
  }
57949
58143
  }
57950
58144
  async function getAll(req, res, next) {
57951
58145
  try {
57952
- const schema2 = Joi142.object({
57953
- search: Joi142.string().optional().allow("", null),
57954
- page: Joi142.number().integer().min(1).allow("", null).default(1),
57955
- limit: Joi142.number().integer().min(1).max(100).allow("", null).default(10),
57956
- status: Joi142.string().optional().allow(null, ""),
57957
- org: Joi142.string().hex().optional().allow("", null),
57958
- site: Joi142.string().hex().optional().allow("", null)
58146
+ const schema2 = Joi143.object({
58147
+ search: Joi143.string().optional().allow("", null),
58148
+ page: Joi143.number().integer().min(1).allow("", null).default(1),
58149
+ limit: Joi143.number().integer().min(1).max(100).allow("", null).default(10),
58150
+ status: Joi143.string().optional().allow(null, ""),
58151
+ org: Joi143.string().hex().optional().allow("", null),
58152
+ site: Joi143.string().hex().optional().allow("", null)
57959
58153
  });
57960
58154
  const { error, value } = schema2.validate(req.query);
57961
58155
  if (error) {
57962
58156
  const messages = error.details.map((d) => d.message).join(", ");
57963
- logger194.log({ level: "error", message: messages });
57964
- next(new BadRequestError221(messages));
58157
+ logger195.log({ level: "error", message: messages });
58158
+ next(new BadRequestError223(messages));
57965
58159
  return;
57966
58160
  }
57967
58161
  const { search, page, limit, status, org, site } = value;
@@ -57969,21 +58163,21 @@ function useFormEntryController() {
57969
58163
  res.json(data);
57970
58164
  return;
57971
58165
  } catch (error) {
57972
- logger194.log({ level: "error", message: error.message });
58166
+ logger195.log({ level: "error", message: error.message });
57973
58167
  next(error);
57974
58168
  return;
57975
58169
  }
57976
58170
  }
57977
58171
  async function getFormEntryById(req, res, next) {
57978
58172
  try {
57979
- const schema2 = Joi142.object({
57980
- _id: Joi142.string().hex().length(24).required()
58173
+ const schema2 = Joi143.object({
58174
+ _id: Joi143.string().hex().length(24).required()
57981
58175
  });
57982
58176
  const { error, value } = schema2.validate({ _id: req.params.id });
57983
58177
  if (error) {
57984
58178
  const messages = error.details.map((d) => d.message).join(", ");
57985
- logger194.log({ level: "error", message: messages });
57986
- next(new BadRequestError221(messages));
58179
+ logger195.log({ level: "error", message: messages });
58180
+ next(new BadRequestError223(messages));
57987
58181
  return;
57988
58182
  }
57989
58183
  const { _id } = value;
@@ -57991,7 +58185,7 @@ function useFormEntryController() {
57991
58185
  res.json(data);
57992
58186
  return;
57993
58187
  } catch (error) {
57994
- logger194.log({ level: "error", message: error.message });
58188
+ logger195.log({ level: "error", message: error.message });
57995
58189
  next(error);
57996
58190
  return;
57997
58191
  }
@@ -58004,8 +58198,8 @@ function useFormEntryController() {
58004
58198
  });
58005
58199
  if (error) {
58006
58200
  const messages = error.details.map((d) => d.message).join(", ");
58007
- logger194.log({ level: "error", message: messages });
58008
- next(new BadRequestError221(messages));
58201
+ logger195.log({ level: "error", message: messages });
58202
+ next(new BadRequestError223(messages));
58009
58203
  return;
58010
58204
  }
58011
58205
  const { _id, ...rest } = value;
@@ -58013,7 +58207,26 @@ function useFormEntryController() {
58013
58207
  res.json({ message: "Successfully updated online form." });
58014
58208
  return;
58015
58209
  } catch (error) {
58016
- logger194.log({ level: "error", message: error.message });
58210
+ logger195.log({ level: "error", message: error.message });
58211
+ next(error);
58212
+ return;
58213
+ }
58214
+ }
58215
+ async function deleteFormEntryById(req, res, next) {
58216
+ try {
58217
+ const validation = Joi143.string().hex().required();
58218
+ const _id = req.params.id;
58219
+ const { error } = validation.validate(_id);
58220
+ if (error) {
58221
+ logger195.log({ level: "error", message: error.message });
58222
+ next(new BadRequestError223(error.message));
58223
+ return;
58224
+ }
58225
+ await _deleteOnlineFormById(_id);
58226
+ res.json({ message: "Successfully deleted online form." });
58227
+ return;
58228
+ } catch (error) {
58229
+ logger195.log({ level: "error", message: error.message });
58017
58230
  next(error);
58018
58231
  return;
58019
58232
  }
@@ -58022,16 +58235,17 @@ function useFormEntryController() {
58022
58235
  uploadFormEntrys,
58023
58236
  getAll,
58024
58237
  getFormEntryById,
58025
- updateFormEntryById
58238
+ updateFormEntryById,
58239
+ deleteFormEntryById
58026
58240
  };
58027
58241
  }
58028
58242
 
58029
58243
  // src/services/building-level.service.ts
58030
- import { useAtlas as useAtlas125 } from "@7365admin1/node-server-utils";
58244
+ import { useAtlas as useAtlas126 } from "@7365admin1/node-server-utils";
58031
58245
  function useBuildingLevelService() {
58032
58246
  const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelRepo();
58033
58247
  async function add(value) {
58034
- const session = useAtlas125.getClient()?.startSession();
58248
+ const session = useAtlas126.getClient()?.startSession();
58035
58249
  try {
58036
58250
  session?.startTransaction();
58037
58251
  await _add(value, session);
@@ -58045,7 +58259,7 @@ function useBuildingLevelService() {
58045
58259
  }
58046
58260
  }
58047
58261
  async function updateLevelById(_id, value) {
58048
- const session = useAtlas125.getClient()?.startSession();
58262
+ const session = useAtlas126.getClient()?.startSession();
58049
58263
  try {
58050
58264
  session?.startTransaction();
58051
58265
  await _updateLevelById(_id, value, session);
@@ -58065,8 +58279,8 @@ function useBuildingLevelService() {
58065
58279
  }
58066
58280
 
58067
58281
  // src/controllers/building-level.controller.ts
58068
- import { BadRequestError as BadRequestError222, logger as logger195 } from "@7365admin1/node-server-utils";
58069
- import Joi143 from "joi";
58282
+ import { BadRequestError as BadRequestError224, logger as logger196 } from "@7365admin1/node-server-utils";
58283
+ import Joi144 from "joi";
58070
58284
  function useBuildingLevelController() {
58071
58285
  const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelService();
58072
58286
  const {
@@ -58081,8 +58295,8 @@ function useBuildingLevelController() {
58081
58295
  });
58082
58296
  if (error) {
58083
58297
  const messages = error.details.map((d) => d.message).join(", ");
58084
- logger195.log({ level: "error", message: messages });
58085
- next(new BadRequestError222(messages));
58298
+ logger196.log({ level: "error", message: messages });
58299
+ next(new BadRequestError224(messages));
58086
58300
  return;
58087
58301
  }
58088
58302
  const result = await _add(value);
@@ -58093,20 +58307,20 @@ function useBuildingLevelController() {
58093
58307
  }
58094
58308
  async function getAll(req, res, next) {
58095
58309
  try {
58096
- const validation = Joi143.object({
58097
- page: Joi143.number().min(1).optional().default(1),
58098
- limit: Joi143.number().min(1).optional().default(20),
58099
- search: Joi143.string().optional().allow("", null),
58100
- site: Joi143.string().hex().length(24).optional().allow("", null),
58101
- status: Joi143.string().valid(...Object.values(BuildingLevelStatus)).default("active" /* ACTIVE */)
58310
+ const validation = Joi144.object({
58311
+ page: Joi144.number().min(1).optional().default(1),
58312
+ limit: Joi144.number().min(1).optional().default(20),
58313
+ search: Joi144.string().optional().allow("", null),
58314
+ site: Joi144.string().hex().length(24).optional().allow("", null),
58315
+ status: Joi144.string().valid(...Object.values(BuildingLevelStatus)).default("active" /* ACTIVE */)
58102
58316
  });
58103
58317
  const { error, value } = validation.validate(req.query, {
58104
58318
  abortEarly: false
58105
58319
  });
58106
58320
  if (error) {
58107
58321
  const messages = error.details.map((d) => d.message);
58108
- logger195.log({ level: "error", message: messages.join(", ") });
58109
- next(new BadRequestError222(messages.join(", ")));
58322
+ logger196.log({ level: "error", message: messages.join(", ") });
58323
+ next(new BadRequestError224(messages.join(", ")));
58110
58324
  return;
58111
58325
  }
58112
58326
  const { page, limit, status, site, search } = value;
@@ -58125,14 +58339,14 @@ function useBuildingLevelController() {
58125
58339
  }
58126
58340
  async function getById(req, res, next) {
58127
58341
  try {
58128
- const schema2 = Joi143.object({
58129
- id: Joi143.string().hex().length(24).required()
58342
+ const schema2 = Joi144.object({
58343
+ id: Joi144.string().hex().length(24).required()
58130
58344
  });
58131
58345
  const { error, value } = schema2.validate({ id: req.params.id });
58132
58346
  if (error) {
58133
58347
  const messages = error.details.map((d) => d.message);
58134
- logger195.log({ level: "error", message: messages.join(", ") });
58135
- next(new BadRequestError222(messages.join(", ")));
58348
+ logger196.log({ level: "error", message: messages.join(", ") });
58349
+ next(new BadRequestError224(messages.join(", ")));
58136
58350
  return;
58137
58351
  }
58138
58352
  const { id } = value;
@@ -58151,8 +58365,8 @@ function useBuildingLevelController() {
58151
58365
  });
58152
58366
  if (error) {
58153
58367
  const messages = error.details.map((d) => d.message);
58154
- logger195.log({ level: "error", message: messages.join(", ") });
58155
- next(new BadRequestError222(messages.join(", ")));
58368
+ logger196.log({ level: "error", message: messages.join(", ") });
58369
+ next(new BadRequestError224(messages.join(", ")));
58156
58370
  return;
58157
58371
  }
58158
58372
  const { _id, ...rest } = value;
@@ -58164,14 +58378,14 @@ function useBuildingLevelController() {
58164
58378
  }
58165
58379
  async function deleteById(req, res, next) {
58166
58380
  try {
58167
- const schema2 = Joi143.object({
58168
- id: Joi143.string().hex().required()
58381
+ const schema2 = Joi144.object({
58382
+ id: Joi144.string().hex().required()
58169
58383
  });
58170
58384
  const { error, value } = schema2.validate({ id: req.params.id });
58171
58385
  if (error) {
58172
58386
  const messages = error.details.map((d) => d.message);
58173
- logger195.log({ level: "error", message: messages.join(", ") });
58174
- next(new BadRequestError222(messages.join(", ")));
58387
+ logger196.log({ level: "error", message: messages.join(", ") });
58388
+ next(new BadRequestError224(messages.join(", ")));
58175
58389
  return;
58176
58390
  }
58177
58391
  const { id } = value;
@@ -58234,6 +58448,7 @@ export {
58234
58448
  MBulletinVideo,
58235
58449
  MCategoryPreloved,
58236
58450
  MChat,
58451
+ MChatPreloved,
58237
58452
  MCustomer,
58238
58453
  MCustomerSite,
58239
58454
  MDocumentManagement,
@@ -58378,6 +58593,7 @@ export {
58378
58593
  schemaBulletinBoard,
58379
58594
  schemaBulletinVideo,
58380
58595
  schemaCategoryPreloved,
58596
+ schemaChatPreloved,
58381
58597
  schemaCustomerSite,
58382
58598
  schemaDocumentManagement,
58383
58599
  schemaEntryPassSettings,
@@ -58485,6 +58701,8 @@ export {
58485
58701
  useCategoryPrelovedController,
58486
58702
  useCategoryPrelovedRepo,
58487
58703
  useChatController,
58704
+ useChatPrelovedController,
58705
+ useChatPrelovedRepo,
58488
58706
  useChatRepo,
58489
58707
  useCounterModel,
58490
58708
  useCounterRepo,