@7365admin1/core 3.17.0 → 3.18.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
@@ -65591,6 +65591,74 @@ function usePostPrelovedRepo() {
65591
65591
  throw error;
65592
65592
  }
65593
65593
  }
65594
+ async function getByOwnerId(ownerId, {
65595
+ search = "",
65596
+ page = 1,
65597
+ limit = 10,
65598
+ filter,
65599
+ site,
65600
+ status,
65601
+ category
65602
+ }, session) {
65603
+ page = page > 0 ? page - 1 : 0;
65604
+ let ownerObjectId;
65605
+ try {
65606
+ ownerObjectId = new ObjectId137(ownerId);
65607
+ } catch {
65608
+ throw new BadRequestError212("Invalid user ID format.");
65609
+ }
65610
+ if (site) {
65611
+ try {
65612
+ site = new ObjectId137(site);
65613
+ } catch {
65614
+ throw new BadRequestError212("Invalid site ID format.");
65615
+ }
65616
+ }
65617
+ let categoryIds = null;
65618
+ if (Array.isArray(category) && category.length > 0) {
65619
+ categoryIds = category.map((cat) => {
65620
+ try {
65621
+ return new ObjectId137(cat);
65622
+ } catch {
65623
+ throw new BadRequestError212("Invalid category ID format.");
65624
+ }
65625
+ });
65626
+ }
65627
+ const query = {
65628
+ status: { $ne: "deleted" /* DELETED */ },
65629
+ createdBy: ownerObjectId,
65630
+ ...site && { site },
65631
+ ...search && {
65632
+ $or: [
65633
+ { title: { $regex: search, $options: "i" } },
65634
+ { description: { $regex: search, $options: "i" } }
65635
+ ]
65636
+ },
65637
+ ...status && {
65638
+ status: { $in: Array.isArray(status) ? status : [status] }
65639
+ },
65640
+ ...categoryIds && { category: { $in: categoryIds } }
65641
+ };
65642
+ const sortObj = buildSortObj(filter);
65643
+ try {
65644
+ const items = await collection.aggregate(
65645
+ [
65646
+ { $match: query },
65647
+ USER_LOOKUP,
65648
+ USER_UNWIND,
65649
+ CATEGORY_LOOKUP,
65650
+ { $sort: sortObj },
65651
+ { $skip: page * limit },
65652
+ { $limit: limit }
65653
+ ],
65654
+ { session }
65655
+ ).toArray();
65656
+ const length = await collection.countDocuments(query, { session });
65657
+ return paginate61(items, page, limit, length);
65658
+ } catch (error) {
65659
+ throw error;
65660
+ }
65661
+ }
65594
65662
  async function updateById(_id, value, session) {
65595
65663
  try {
65596
65664
  _id = new ObjectId137(_id);
@@ -65661,6 +65729,7 @@ function usePostPrelovedRepo() {
65661
65729
  add,
65662
65730
  getById,
65663
65731
  getAll,
65732
+ getByOwnerId,
65664
65733
  updateById,
65665
65734
  deleteById,
65666
65735
  updateStatus
@@ -65875,6 +65944,7 @@ function usePostPrelovedController() {
65875
65944
  const {
65876
65945
  getById: _getById,
65877
65946
  getAll: _getAll,
65947
+ getByOwnerId: _getByOwnerId,
65878
65948
  updateById: _updateById,
65879
65949
  deleteById: _deleteById,
65880
65950
  updateStatus: _updateStatus
@@ -65978,6 +66048,49 @@ function usePostPrelovedController() {
65978
66048
  return;
65979
66049
  }
65980
66050
  }
66051
+ async function getByOwnerId(req, res, next) {
66052
+ const validation = Joi135.object({
66053
+ ownerId: Joi135.string().hex().length(24).required(),
66054
+ page: Joi135.number().integer().min(1).allow("", null).default(1),
66055
+ limit: Joi135.number().integer().min(1).max(100).allow("", null).default(10),
66056
+ search: Joi135.string().optional().allow("", null),
66057
+ filter: Joi135.string().valid("recent", "price-low-high", "price-high-low").optional().allow("", null),
66058
+ site: Joi135.string().hex().length(24).optional().allow("", null),
66059
+ status: Joi135.alternatives().try(
66060
+ Joi135.array().items(Joi135.string().valid(...Object.values(PostStatus))),
66061
+ Joi135.string().valid(...Object.values(PostStatus))
66062
+ ).optional().allow(null),
66063
+ category: Joi135.array().items(Joi135.string().hex().length(24)).single().optional().allow(null)
66064
+ });
66065
+ const { error, value } = validation.validate(
66066
+ { ...req.query, ownerId: req.params.ownerId },
66067
+ { abortEarly: false }
66068
+ );
66069
+ if (error) {
66070
+ const messages = error.details.map((d) => d.message).join(", ");
66071
+ logger188.log({ level: "error", message: messages });
66072
+ next(new BadRequestError214(messages));
66073
+ return;
66074
+ }
66075
+ const { ownerId, page, limit, search, filter, site, status, category } = value;
66076
+ try {
66077
+ const data = await _getByOwnerId(ownerId, {
66078
+ page,
66079
+ limit,
66080
+ search,
66081
+ filter,
66082
+ site,
66083
+ status: status ? Array.isArray(status) ? status : [status] : void 0,
66084
+ category: category ?? void 0
66085
+ });
66086
+ res.status(200).json(data);
66087
+ return;
66088
+ } catch (error2) {
66089
+ logger188.log({ level: "error", message: error2.message });
66090
+ next(error2);
66091
+ return;
66092
+ }
66093
+ }
65981
66094
  async function updateById(req, res, next) {
65982
66095
  const _id = req.params.id;
65983
66096
  const payload = { _id, ...req.body };
@@ -66048,6 +66161,7 @@ function usePostPrelovedController() {
66048
66161
  add,
66049
66162
  getById,
66050
66163
  getAll,
66164
+ getByOwnerId,
66051
66165
  updateById,
66052
66166
  deleteById,
66053
66167
  updateStatus