@7365admin1/core 2.62.0 → 2.64.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
@@ -99,6 +99,7 @@ __export(src_exports, {
99
99
  MPatrolQuestion: () => MPatrolQuestion,
100
100
  MPatrolRoute: () => MPatrolRoute,
101
101
  MPerson: () => MPerson,
102
+ MPost: () => MPost,
102
103
  MPromoCode: () => MPromoCode,
103
104
  MRobot: () => MRobot,
104
105
  MRole: () => MRole,
@@ -129,6 +130,9 @@ __export(src_exports, {
129
130
  Period: () => Period,
130
131
  PersonStatus: () => PersonStatus,
131
132
  PersonTypes: () => PersonTypes,
133
+ PostOrder: () => PostOrder,
134
+ PostSort: () => PostSort,
135
+ PostStatus: () => PostStatus,
132
136
  SiteCategories: () => SiteCategories,
133
137
  SiteStatus: () => SiteStatus,
134
138
  SortFields: () => SortFields,
@@ -224,6 +228,7 @@ __export(src_exports, {
224
228
  schemaPatrolRoute: () => schemaPatrolRoute,
225
229
  schemaPerson: () => schemaPerson,
226
230
  schemaPlate: () => schemaPlate,
231
+ schemaPost: () => schemaPost,
227
232
  schemaServiceProvider: () => schemaServiceProvider,
228
233
  schemaServiceProviderBilling: () => schemaServiceProviderBilling,
229
234
  schemaSiteCamera: () => schemaSiteCamera,
@@ -382,6 +387,8 @@ __export(src_exports, {
382
387
  usePatrolRouteRepo: () => usePatrolRouteRepo,
383
388
  usePersonController: () => usePersonController,
384
389
  usePersonRepo: () => usePersonRepo,
390
+ usePostPrelovedController: () => usePostPrelovedController,
391
+ usePostPrelovedRepo: () => usePostPrelovedRepo,
385
392
  usePriceController: () => usePriceController,
386
393
  usePriceModel: () => usePriceModel,
387
394
  usePriceRepo: () => usePriceRepo,
@@ -4301,7 +4308,9 @@ function useVerificationRepo() {
4301
4308
  status = "active",
4302
4309
  app = "",
4303
4310
  type = {},
4304
- email = ""
4311
+ email = "",
4312
+ siteId = "",
4313
+ orgId = ""
4305
4314
  }) {
4306
4315
  page = page > 0 ? page - 1 : 0;
4307
4316
  const query = { status };
@@ -4328,6 +4337,24 @@ function useVerificationRepo() {
4328
4337
  query.email = email;
4329
4338
  cacheOptions.email = email;
4330
4339
  }
4340
+ if (siteId) {
4341
+ const siteCandidates = [siteId];
4342
+ try {
4343
+ siteCandidates.push(new import_mongodb13.ObjectId(siteId));
4344
+ } catch {
4345
+ }
4346
+ query["metadata.siteId"] = { $in: siteCandidates };
4347
+ cacheOptions.siteId = siteId;
4348
+ }
4349
+ if (orgId) {
4350
+ const orgCandidates = [orgId];
4351
+ try {
4352
+ orgCandidates.push(new import_mongodb13.ObjectId(orgId));
4353
+ } catch {
4354
+ }
4355
+ query["metadata.org"] = { $in: orgCandidates };
4356
+ cacheOptions.orgId = orgId;
4357
+ }
4331
4358
  const cacheKey = (0, import_node_server_utils15.makeCacheKey)(namespace_collection, cacheOptions);
4332
4359
  const cachedData = await getCache(cacheKey);
4333
4360
  if (cachedData) {
@@ -8547,7 +8574,10 @@ function useVerificationController() {
8547
8574
  status: import_joi16.default.string().required(),
8548
8575
  app: import_joi16.default.string().optional().allow("", null),
8549
8576
  type: import_joi16.default.alternatives().try(import_joi16.default.string(), import_joi16.default.array().items(import_joi16.default.string())).optional().allow("", null),
8550
- email: import_joi16.default.string().optional().allow("", null)
8577
+ email: import_joi16.default.string().optional().allow("", null),
8578
+ siteId: import_joi16.default.string().hex().optional().allow("", null),
8579
+ orgId: import_joi16.default.string().hex().optional().allow("", null),
8580
+ limit: import_joi16.default.number().integer().min(1).allow("", null).default(10)
8551
8581
  });
8552
8582
  const query = { ...req.query };
8553
8583
  const { error } = validation.validate(query);
@@ -8561,6 +8591,9 @@ function useVerificationController() {
8561
8591
  const status = req.query.status ?? "pending";
8562
8592
  const app = req.query.app ?? "";
8563
8593
  const email = req.query.email ?? "";
8594
+ const siteId = req.query.siteId ?? "";
8595
+ const orgId = req.query.orgId ?? "";
8596
+ const limit = parseInt(req.query.limit ?? "10");
8564
8597
  const type = req.query.type ? String(req.query.type).split(",") : "";
8565
8598
  const typeObj = {};
8566
8599
  if (type && Array.isArray(type) && type.length) {
@@ -8575,7 +8608,10 @@ function useVerificationController() {
8575
8608
  status,
8576
8609
  app,
8577
8610
  type: typeObj,
8578
- email
8611
+ email,
8612
+ siteId,
8613
+ orgId,
8614
+ limit
8579
8615
  });
8580
8616
  res.json(data);
8581
8617
  return;
@@ -12260,6 +12296,7 @@ function useServiceProviderRepo() {
12260
12296
  throw new import_node_server_utils56.BadRequestError("Invalid site ID format.");
12261
12297
  }
12262
12298
  }
12299
+ cacheOptions.membersLookup = "1";
12263
12300
  const cacheKey = (0, import_node_server_utils56.makeCacheKey)(namespace_collection, cacheOptions);
12264
12301
  const cachedData = await getCache(cacheKey);
12265
12302
  if (cachedData) {
@@ -12275,7 +12312,7 @@ function useServiceProviderRepo() {
12275
12312
  localField: "serviceProviderOrgId",
12276
12313
  foreignField: "_id",
12277
12314
  as: "organization",
12278
- pipeline: [{ $project: { nature: 1 } }]
12315
+ pipeline: [{ $project: { nature: 1, email: 1 } }]
12279
12316
  }
12280
12317
  },
12281
12318
  {
@@ -12284,17 +12321,50 @@ function useServiceProviderRepo() {
12284
12321
  preserveNullAndEmptyArrays: true
12285
12322
  }
12286
12323
  },
12324
+ {
12325
+ $lookup: {
12326
+ from: "members",
12327
+ let: { spOrgId: "$serviceProviderOrgId" },
12328
+ pipeline: [
12329
+ {
12330
+ $match: {
12331
+ $expr: { $eq: ["$org", "$$spOrgId"] },
12332
+ status: "active"
12333
+ }
12334
+ },
12335
+ { $count: "c" }
12336
+ ],
12337
+ as: "_memberCount"
12338
+ }
12339
+ },
12287
12340
  {
12288
12341
  $project: {
12289
12342
  name: 1,
12290
12343
  type: 1,
12344
+ email: {
12345
+ $cond: {
12346
+ if: {
12347
+ $gt: [{ $strLenCP: { $ifNull: ["$email", ""] } }, 0]
12348
+ },
12349
+ then: "$email",
12350
+ else: { $ifNull: ["$organization.email", ""] }
12351
+ }
12352
+ },
12291
12353
  nature: "$organization.nature",
12292
12354
  orgId: 1,
12293
12355
  siteId: 1,
12294
12356
  siteName: 1,
12295
12357
  serviceProviderOrgId: 1,
12296
12358
  status: 1,
12297
- category: 1
12359
+ category: 1,
12360
+ members: {
12361
+ $let: {
12362
+ vars: {
12363
+ mc: { $arrayElemAt: ["$_memberCount", 0] }
12364
+ },
12365
+ in: { $ifNull: ["$$mc.c", 0] }
12366
+ }
12367
+ }
12298
12368
  }
12299
12369
  },
12300
12370
  { $sort: sort },
@@ -31979,7 +32049,8 @@ function useBulletinBoardRepo() {
31979
32049
  sort = {},
31980
32050
  site = "",
31981
32051
  status = "active",
31982
- recipients = []
32052
+ recipients = [],
32053
+ expiration
31983
32054
  }, session) {
31984
32055
  page = page > 0 ? page - 1 : 0;
31985
32056
  try {
@@ -31990,8 +32061,13 @@ function useBulletinBoardRepo() {
31990
32061
  const query = {
31991
32062
  site,
31992
32063
  status,
31993
- ...search && { $text: { $search: search } },
31994
- ...recipients?.length && { recipients: { $in: recipients } }
32064
+ ...search && {
32065
+ $or: [{ title: { $regex: search, $options: "i" } }]
32066
+ },
32067
+ ...recipients?.length && { recipients: { $all: recipients } },
32068
+ ...expiration !== void 0 && {
32069
+ noExpiration: expiration === "yes"
32070
+ }
31995
32071
  };
31996
32072
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
31997
32073
  const cacheOptions = {
@@ -32001,7 +32077,8 @@ function useBulletinBoardRepo() {
32001
32077
  page,
32002
32078
  limit,
32003
32079
  ...search && { search },
32004
- ...recipients?.length && { recipients: recipients.sort().join(",") }
32080
+ ...recipients?.length && { recipients: recipients.sort().join(",") },
32081
+ ...expiration !== void 0 && { expiration }
32005
32082
  };
32006
32083
  const cacheKey = (0, import_node_server_utils136.makeCacheKey)(
32007
32084
  bulletin_boards_namespace_collection,
@@ -32189,7 +32266,9 @@ function useBulletinBoardRepo() {
32189
32266
  { session }
32190
32267
  );
32191
32268
  if (res.matchedCount === 0) {
32192
- throw new import_node_server_utils136.NotFoundError("No upcoming bulletin boards found to activate.");
32269
+ throw new import_node_server_utils136.NotFoundError(
32270
+ "No upcoming bulletin boards found to activate."
32271
+ );
32193
32272
  }
32194
32273
  delNamespace().then(() => {
32195
32274
  import_node_server_utils136.logger.info(
@@ -32375,32 +32454,35 @@ function useBulletinBoardController() {
32375
32454
  order: import_joi77.default.string().valid(...Object.values(BulletinOrder)).default("desc" /* DESC */),
32376
32455
  site: import_joi77.default.string().hex().length(24).required(),
32377
32456
  status: import_joi77.default.string().valid(...Object.values(BulletinStatus)).optional().default("active" /* ACTIVE */),
32378
- recipients: import_joi77.default.alternatives().try(
32379
- import_joi77.default.array().items(
32380
- import_joi77.default.string().valid(...Object.values(BulletinRecipient))
32381
- ),
32382
- import_joi77.default.string().allow("")
32383
- ).optional().allow(null).custom((value2, helpers) => {
32384
- if (!value2 || value2 === "") {
32457
+ recipients: import_joi77.default.any().optional().allow(null, "").custom((value2, helpers) => {
32458
+ if (!value2 || value2 === "")
32385
32459
  return [];
32386
- }
32387
- let parsed = [];
32460
+ let parsed;
32388
32461
  if (Array.isArray(value2)) {
32389
32462
  parsed = value2;
32390
- } else if (typeof value2 === "string") {
32391
- parsed = value2.split(",").map((v) => v.trim()).filter(Boolean);
32392
- }
32393
- for (const r of parsed) {
32394
- if (!Object.values(BulletinRecipient).includes(r)) {
32395
- return helpers.error("any.only");
32463
+ } else if (typeof value2 === "string" && value2.trim().startsWith("[")) {
32464
+ try {
32465
+ const result = JSON.parse(value2);
32466
+ parsed = Array.isArray(result) ? result : [value2];
32467
+ } catch {
32468
+ return helpers.error("any.invalid");
32396
32469
  }
32470
+ } else {
32471
+ parsed = [value2];
32397
32472
  }
32473
+ const validValues = Object.values(BulletinRecipient);
32474
+ const isValid = parsed.every(
32475
+ (r) => validValues.includes(r)
32476
+ );
32477
+ if (!isValid)
32478
+ return helpers.error("any.invalid");
32398
32479
  return parsed;
32399
32480
  }).messages({
32400
- "any.only": `Recipients must be one of: ${Object.values(
32481
+ "any.invalid": `Recipients must be one of: ${Object.values(
32401
32482
  BulletinRecipient
32402
32483
  ).join(", ")}`
32403
- })
32484
+ }),
32485
+ expiration: import_joi77.default.string().valid("yes", "no").optional().allow("", null)
32404
32486
  });
32405
32487
  const { error, value } = validation.validate(req.query, {
32406
32488
  abortEarly: false
@@ -32411,7 +32493,17 @@ function useBulletinBoardController() {
32411
32493
  next(new import_node_server_utils138.BadRequestError(messages));
32412
32494
  return;
32413
32495
  }
32414
- const { search, page, limit, site, status, recipients, sort, order } = value;
32496
+ const {
32497
+ search,
32498
+ page,
32499
+ limit,
32500
+ site,
32501
+ status,
32502
+ recipients,
32503
+ sort,
32504
+ order,
32505
+ expiration
32506
+ } = value;
32415
32507
  const sortObj = {
32416
32508
  [sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
32417
32509
  };
@@ -32423,7 +32515,8 @@ function useBulletinBoardController() {
32423
32515
  sort: sortObj,
32424
32516
  site,
32425
32517
  status,
32426
- recipients
32518
+ recipients,
32519
+ expiration
32427
32520
  });
32428
32521
  res.status(200).json(data);
32429
32522
  return;
@@ -40619,7 +40712,9 @@ function useBulletinVideoRepo() {
40619
40712
  page = 1,
40620
40713
  limit = 10,
40621
40714
  sort = {},
40622
- site = ""
40715
+ site = "",
40716
+ startDate,
40717
+ endDate
40623
40718
  }, session) {
40624
40719
  page = page > 0 ? page - 1 : 0;
40625
40720
  try {
@@ -40627,10 +40722,33 @@ function useBulletinVideoRepo() {
40627
40722
  } catch (error) {
40628
40723
  throw new import_node_server_utils162.BadRequestError("Invalid site ID format.");
40629
40724
  }
40725
+ let dateExpr = {};
40726
+ if (startDate && endDate) {
40727
+ const startingDate = new Date(startDate);
40728
+ startingDate.setUTCHours(0, 0, 0, 0);
40729
+ const endingDate = new Date(endDate);
40730
+ endingDate.setUTCHours(23, 59, 59, 999);
40731
+ const parsedCreatedAt = {
40732
+ $dateFromString: {
40733
+ dateString: "$createdAt",
40734
+ onError: /* @__PURE__ */ new Date(0),
40735
+ onNull: /* @__PURE__ */ new Date(0)
40736
+ }
40737
+ };
40738
+ dateExpr = {
40739
+ $expr: {
40740
+ $and: [
40741
+ { $gte: [parsedCreatedAt, startingDate] },
40742
+ { $lte: [parsedCreatedAt, endingDate] }
40743
+ ]
40744
+ }
40745
+ };
40746
+ }
40630
40747
  const query = {
40631
40748
  site,
40632
40749
  status: { $ne: "deleted" },
40633
- ...search && { $text: { $search: search } }
40750
+ ...search && { $text: { $search: search } },
40751
+ ...dateExpr
40634
40752
  };
40635
40753
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
40636
40754
  const cacheOptions = {
@@ -40639,7 +40757,9 @@ function useBulletinVideoRepo() {
40639
40757
  page,
40640
40758
  limit,
40641
40759
  status: { $ne: "deleted" },
40642
- ...search && { search }
40760
+ ...search && { search },
40761
+ ...startDate && { startDate },
40762
+ ...endDate && { endDate }
40643
40763
  };
40644
40764
  if (search) {
40645
40765
  query.$or = [
@@ -40898,7 +41018,9 @@ function useBulletinVideoController() {
40898
41018
  limit: import_joi92.default.number().integer().min(1).max(100).allow("", null).default(10),
40899
41019
  sort: import_joi92.default.string().valid(...Object.values(BulletinVideoSort)).default("_id" /* ID */),
40900
41020
  order: import_joi92.default.string().valid(...Object.values(BulletinVideoOrder)).default("desc" /* DESC */),
40901
- site: import_joi92.default.string().hex().length(24).required()
41021
+ site: import_joi92.default.string().hex().length(24).required(),
41022
+ startDate: import_joi92.default.string().optional().allow("", null),
41023
+ endDate: import_joi92.default.string().optional().allow("", null)
40902
41024
  });
40903
41025
  const { error, value } = validation.validate(req.query, {
40904
41026
  abortEarly: false
@@ -40909,7 +41031,7 @@ function useBulletinVideoController() {
40909
41031
  next(new import_node_server_utils164.BadRequestError(messages));
40910
41032
  return;
40911
41033
  }
40912
- const { search, page, limit, site, sort, order } = value;
41034
+ const { search, page, limit, site, sort, order, startDate, endDate } = value;
40913
41035
  const sortObj = {
40914
41036
  [sort ?? "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
40915
41037
  };
@@ -40919,7 +41041,9 @@ function useBulletinVideoController() {
40919
41041
  page,
40920
41042
  limit,
40921
41043
  sort: sortObj,
40922
- site
41044
+ site,
41045
+ startDate,
41046
+ endDate
40923
41047
  });
40924
41048
  res.status(200).json(data);
40925
41049
  return;
@@ -53314,6 +53438,364 @@ function useRoleControllerV2() {
53314
53438
  createRole
53315
53439
  };
53316
53440
  }
53441
+
53442
+ // src/models/post-preloved.model.ts
53443
+ var import_joi132 = __toESM(require("joi"));
53444
+ var import_mongodb129 = require("mongodb");
53445
+ var PostStatus = /* @__PURE__ */ ((PostStatus2) => {
53446
+ PostStatus2["PUBLISHED"] = "published";
53447
+ PostStatus2["SOLD"] = "sold";
53448
+ PostStatus2["DELETED"] = "deleted";
53449
+ return PostStatus2;
53450
+ })(PostStatus || {});
53451
+ var PostSort = /* @__PURE__ */ ((PostSort2) => {
53452
+ PostSort2["CREATED_AT"] = "createdAt";
53453
+ PostSort2["TITLE"] = "title";
53454
+ PostSort2["PRICE"] = "price";
53455
+ PostSort2["ID"] = "_id";
53456
+ return PostSort2;
53457
+ })(PostSort || {});
53458
+ var PostOrder = /* @__PURE__ */ ((PostOrder2) => {
53459
+ PostOrder2["ASC"] = "asc";
53460
+ PostOrder2["DESC"] = "desc";
53461
+ return PostOrder2;
53462
+ })(PostOrder || {});
53463
+ var schemaPost = import_joi132.default.object({
53464
+ _id: import_joi132.default.string().hex().optional().allow("", null),
53465
+ title: import_joi132.default.string().required(),
53466
+ description: import_joi132.default.string().optional().allow("", null),
53467
+ attachments: import_joi132.default.array().items(import_joi132.default.string().hex().optional()).optional().allow(null),
53468
+ category: import_joi132.default.array().items(import_joi132.default.string().hex().optional()).optional().allow(null),
53469
+ currency: import_joi132.default.string().optional().allow("", null),
53470
+ price: import_joi132.default.number().required(),
53471
+ status: import_joi132.default.string().valid(...Object.values(PostStatus)).optional().default("published" /* PUBLISHED */),
53472
+ reserverId: import_joi132.default.string().hex().optional().allow("", null),
53473
+ createdBy: import_joi132.default.string().hex().optional().allow("", null),
53474
+ site: import_joi132.default.string().hex().optional().allow("", null),
53475
+ createdAt: import_joi132.default.date().optional().allow(null),
53476
+ updatedAt: import_joi132.default.date().optional().allow(null),
53477
+ deletedAt: import_joi132.default.date().optional().allow(null)
53478
+ });
53479
+ function MPost(value) {
53480
+ const { error } = schemaPost.validate(value);
53481
+ if (error) {
53482
+ throw new Error(error.details[0].message);
53483
+ }
53484
+ if (value._id && typeof value._id === "string") {
53485
+ try {
53486
+ value._id = new import_mongodb129.ObjectId(value._id);
53487
+ } catch {
53488
+ throw new Error("Invalid ID.");
53489
+ }
53490
+ }
53491
+ if (value.site && typeof value.site === "string") {
53492
+ try {
53493
+ value.site = new import_mongodb129.ObjectId(value.site);
53494
+ } catch {
53495
+ throw new Error("Invalid site ID.");
53496
+ }
53497
+ }
53498
+ if (value.createdBy && typeof value.createdBy === "string") {
53499
+ try {
53500
+ value.createdBy = new import_mongodb129.ObjectId(value.createdBy);
53501
+ } catch {
53502
+ throw new Error("Invalid createdBy ID.");
53503
+ }
53504
+ }
53505
+ if (value.reserverId && typeof value.reserverId === "string") {
53506
+ try {
53507
+ value.reserverId = new import_mongodb129.ObjectId(value.reserverId);
53508
+ } catch {
53509
+ throw new Error("Invalid reserver ID.");
53510
+ }
53511
+ }
53512
+ if (value.attachments && Array.isArray(value.attachments)) {
53513
+ value.attachments = value.attachments.map((id) => {
53514
+ if (typeof id === "string") {
53515
+ try {
53516
+ return new import_mongodb129.ObjectId(id);
53517
+ } catch {
53518
+ throw new Error("Invalid attachment ID.");
53519
+ }
53520
+ }
53521
+ return id;
53522
+ });
53523
+ }
53524
+ if (value.category && Array.isArray(value.category)) {
53525
+ value.category = value.category.map((id) => {
53526
+ if (typeof id === "string") {
53527
+ try {
53528
+ return new import_mongodb129.ObjectId(id);
53529
+ } catch {
53530
+ throw new Error("Invalid category ID.");
53531
+ }
53532
+ }
53533
+ return id;
53534
+ });
53535
+ }
53536
+ return {
53537
+ _id: value._id ?? new import_mongodb129.ObjectId(),
53538
+ title: value.title ?? "",
53539
+ description: value.description ?? "",
53540
+ attachments: value.attachments ?? [],
53541
+ category: value.category ?? [],
53542
+ currency: value.currency ?? "",
53543
+ price: value.price ?? 0,
53544
+ status: value.status ?? "published" /* PUBLISHED */,
53545
+ reserverId: value.reserverId ?? null,
53546
+ createdBy: value.createdBy ?? "",
53547
+ site: value.site ?? "",
53548
+ createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
53549
+ updatedAt: value.updatedAt ?? null,
53550
+ deletedAt: value.deletedAt ?? null
53551
+ };
53552
+ }
53553
+
53554
+ // src/repositories/post-preloved.repo.ts
53555
+ var import_node_server_utils232 = require("@7365admin1/node-server-utils");
53556
+ var import_mongodb130 = require("mongodb");
53557
+ function usePostPrelovedRepo() {
53558
+ const db = import_node_server_utils232.useAtlas.getDb();
53559
+ if (!db) {
53560
+ throw new import_node_server_utils232.InternalServerError("Unable to connect to server.");
53561
+ }
53562
+ const POST_COLLECTION = "post-preloved";
53563
+ const USER_LOOKUP = {
53564
+ $lookup: {
53565
+ from: "users",
53566
+ localField: "createdBy",
53567
+ foreignField: "_id",
53568
+ pipeline: [
53569
+ {
53570
+ $project: {
53571
+ name: 1,
53572
+ profile: 1
53573
+ }
53574
+ }
53575
+ ],
53576
+ as: "createdBy"
53577
+ }
53578
+ };
53579
+ const USER_UNWIND = {
53580
+ $unwind: {
53581
+ path: "$createdBy",
53582
+ preserveNullAndEmptyArrays: true
53583
+ }
53584
+ };
53585
+ const CATEGORY_LOOKUP = {
53586
+ $lookup: {
53587
+ from: "category-preloved",
53588
+ localField: "category",
53589
+ foreignField: "_id",
53590
+ as: "categories"
53591
+ }
53592
+ };
53593
+ const collection = db.collection(POST_COLLECTION);
53594
+ function buildSortObj(filter) {
53595
+ switch (filter) {
53596
+ case "price-low-high":
53597
+ return { price: 1 };
53598
+ case "price-high-low":
53599
+ return { price: -1 };
53600
+ case "recent":
53601
+ default:
53602
+ return { createdAt: -1 };
53603
+ }
53604
+ }
53605
+ async function add(value, session) {
53606
+ try {
53607
+ const doc = MPost(value);
53608
+ const res = await collection.insertOne(doc, { session });
53609
+ return res.insertedId;
53610
+ } catch (error) {
53611
+ const isDuplicated = error.message?.includes("duplicate");
53612
+ if (isDuplicated)
53613
+ throw new import_node_server_utils232.BadRequestError("Post already exists.");
53614
+ throw error;
53615
+ }
53616
+ }
53617
+ async function getById(_id) {
53618
+ try {
53619
+ _id = new import_mongodb130.ObjectId(_id);
53620
+ } catch {
53621
+ throw new import_node_server_utils232.BadRequestError("Invalid post ID format.");
53622
+ }
53623
+ try {
53624
+ const result = await collection.aggregate([
53625
+ { $match: { _id, status: { $ne: "deleted" /* DELETED */ } } },
53626
+ USER_LOOKUP,
53627
+ USER_UNWIND,
53628
+ CATEGORY_LOOKUP
53629
+ ]).toArray();
53630
+ const data = result[0] ?? null;
53631
+ if (!data)
53632
+ throw new import_node_server_utils232.NotFoundError("Post not found.");
53633
+ return data;
53634
+ } catch (error) {
53635
+ throw error;
53636
+ }
53637
+ }
53638
+ async function getAll({
53639
+ search = "",
53640
+ page = 1,
53641
+ limit = 10,
53642
+ filter,
53643
+ site,
53644
+ status,
53645
+ category
53646
+ }, session) {
53647
+ page = page > 0 ? page - 1 : 0;
53648
+ if (site) {
53649
+ try {
53650
+ site = new import_mongodb130.ObjectId(site);
53651
+ } catch {
53652
+ throw new import_node_server_utils232.BadRequestError("Invalid site ID format.");
53653
+ }
53654
+ }
53655
+ const categoryIds = category && Array.isArray(category) && category.length > 0 ? category.map((id) => {
53656
+ try {
53657
+ return new import_mongodb130.ObjectId(id);
53658
+ } catch {
53659
+ throw new import_node_server_utils232.BadRequestError("Invalid category ID format.");
53660
+ }
53661
+ }) : null;
53662
+ const query = {
53663
+ status: { $ne: "deleted" /* DELETED */ },
53664
+ ...site && { site },
53665
+ ...search && {
53666
+ $or: [
53667
+ { title: { $regex: search, $options: "i" } },
53668
+ { description: { $regex: search, $options: "i" } }
53669
+ ]
53670
+ },
53671
+ ...status && {
53672
+ status: { $in: Array.isArray(status) ? status : [status] }
53673
+ },
53674
+ ...categoryIds && { category: { $in: categoryIds } }
53675
+ };
53676
+ const sortObj = buildSortObj(filter);
53677
+ try {
53678
+ const items = await collection.aggregate(
53679
+ [
53680
+ { $match: query },
53681
+ USER_LOOKUP,
53682
+ USER_UNWIND,
53683
+ CATEGORY_LOOKUP,
53684
+ { $sort: sortObj },
53685
+ { $skip: page * limit },
53686
+ { $limit: limit }
53687
+ ],
53688
+ { session }
53689
+ ).toArray();
53690
+ const length = await collection.countDocuments(query, { session });
53691
+ return (0, import_node_server_utils232.paginate)(items, page, limit, length);
53692
+ } catch (error) {
53693
+ throw error;
53694
+ }
53695
+ }
53696
+ return {
53697
+ add,
53698
+ getById,
53699
+ getAll
53700
+ };
53701
+ }
53702
+
53703
+ // src/controllers/post-preloved.controller.ts
53704
+ var import_node_server_utils233 = require("@7365admin1/node-server-utils");
53705
+ var import_joi133 = __toESM(require("joi"));
53706
+ function usePostPrelovedController() {
53707
+ const {
53708
+ add: _add,
53709
+ getById: _getById,
53710
+ getAll: _getAll
53711
+ } = usePostPrelovedRepo();
53712
+ async function add(req, res, next) {
53713
+ const { error, value } = schemaPost.validate(req.body, {
53714
+ abortEarly: false
53715
+ });
53716
+ if (error) {
53717
+ const messages = error.details.map((d) => d.message).join(", ");
53718
+ import_node_server_utils233.logger.log({ level: "error", message: messages });
53719
+ next(new import_node_server_utils233.BadRequestError(messages));
53720
+ return;
53721
+ }
53722
+ try {
53723
+ const data = await _add(value);
53724
+ res.status(201).json(data);
53725
+ return;
53726
+ } catch (error2) {
53727
+ import_node_server_utils233.logger.log({ level: "error", message: error2.message });
53728
+ next(error2);
53729
+ return;
53730
+ }
53731
+ }
53732
+ async function getById(req, res, next) {
53733
+ const schema2 = import_joi133.default.object({
53734
+ _id: import_joi133.default.string().hex().length(24).required()
53735
+ });
53736
+ const { error, value } = schema2.validate({ _id: req.params.id });
53737
+ if (error) {
53738
+ import_node_server_utils233.logger.log({ level: "error", message: error.message });
53739
+ next(new import_node_server_utils233.BadRequestError(error.message));
53740
+ return;
53741
+ }
53742
+ try {
53743
+ const data = await _getById(value._id);
53744
+ res.status(200).json(data);
53745
+ return;
53746
+ } catch (error2) {
53747
+ import_node_server_utils233.logger.log({ level: "error", message: error2.message });
53748
+ next(error2);
53749
+ return;
53750
+ }
53751
+ }
53752
+ async function getAll(req, res, next) {
53753
+ const validation = import_joi133.default.object({
53754
+ page: import_joi133.default.number().integer().min(1).allow("", null).default(1),
53755
+ limit: import_joi133.default.number().integer().min(1).max(100).allow("", null).default(10),
53756
+ search: import_joi133.default.string().optional().allow("", null),
53757
+ filter: import_joi133.default.string().valid("recent", "price-low-high", "price-high-low").optional().allow("", null),
53758
+ site: import_joi133.default.string().hex().length(24).optional().allow("", null),
53759
+ status: import_joi133.default.alternatives().try(
53760
+ import_joi133.default.array().items(import_joi133.default.string().valid(...Object.values(PostStatus))),
53761
+ import_joi133.default.string().valid(...Object.values(PostStatus))
53762
+ ).optional().allow(null),
53763
+ category: import_joi133.default.alternatives().try(import_joi133.default.array().items(import_joi133.default.string().hex()), import_joi133.default.string().hex()).optional().allow(null)
53764
+ });
53765
+ const { error, value } = validation.validate(req.query, {
53766
+ abortEarly: false
53767
+ });
53768
+ if (error) {
53769
+ const messages = error.details.map((d) => d.message).join(", ");
53770
+ import_node_server_utils233.logger.log({ level: "error", message: messages });
53771
+ next(new import_node_server_utils233.BadRequestError(messages));
53772
+ return;
53773
+ }
53774
+ const { page, limit, search, filter, site, status, category } = value;
53775
+ try {
53776
+ const data = await _getAll({
53777
+ page,
53778
+ limit,
53779
+ search,
53780
+ filter,
53781
+ site,
53782
+ status: status ? Array.isArray(status) ? status : [status] : void 0,
53783
+ category: category ? Array.isArray(category) ? category : [category] : void 0
53784
+ });
53785
+ res.status(200).json(data);
53786
+ return;
53787
+ } catch (error2) {
53788
+ import_node_server_utils233.logger.log({ level: "error", message: error2.message });
53789
+ next(error2);
53790
+ return;
53791
+ }
53792
+ }
53793
+ return {
53794
+ add,
53795
+ getById,
53796
+ getAll
53797
+ };
53798
+ }
53317
53799
  // Annotate the CommonJS export names for ESM import in node:
53318
53800
  0 && (module.exports = {
53319
53801
  ANPRMode,
@@ -53385,6 +53867,7 @@ function useRoleControllerV2() {
53385
53867
  MPatrolQuestion,
53386
53868
  MPatrolRoute,
53387
53869
  MPerson,
53870
+ MPost,
53388
53871
  MPromoCode,
53389
53872
  MRobot,
53390
53873
  MRole,
@@ -53415,6 +53898,9 @@ function useRoleControllerV2() {
53415
53898
  Period,
53416
53899
  PersonStatus,
53417
53900
  PersonTypes,
53901
+ PostOrder,
53902
+ PostSort,
53903
+ PostStatus,
53418
53904
  SiteCategories,
53419
53905
  SiteStatus,
53420
53906
  SortFields,
@@ -53510,6 +53996,7 @@ function useRoleControllerV2() {
53510
53996
  schemaPatrolRoute,
53511
53997
  schemaPerson,
53512
53998
  schemaPlate,
53999
+ schemaPost,
53513
54000
  schemaServiceProvider,
53514
54001
  schemaServiceProviderBilling,
53515
54002
  schemaSiteCamera,
@@ -53668,6 +54155,8 @@ function useRoleControllerV2() {
53668
54155
  usePatrolRouteRepo,
53669
54156
  usePersonController,
53670
54157
  usePersonRepo,
54158
+ usePostPrelovedController,
54159
+ usePostPrelovedRepo,
53671
54160
  usePriceController,
53672
54161
  usePriceModel,
53673
54162
  usePriceRepo,