@7365admin1/core 3.16.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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +130 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +130 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -8333,7 +8333,22 @@ function useUserRepo() {
|
|
|
8333
8333
|
as: "unitInfo"
|
|
8334
8334
|
}
|
|
8335
8335
|
},
|
|
8336
|
-
{ $unwind: { path: "$unitInfo", preserveNullAndEmptyArrays: true } }
|
|
8336
|
+
{ $unwind: { path: "$unitInfo", preserveNullAndEmptyArrays: true } },
|
|
8337
|
+
{
|
|
8338
|
+
$lookup: {
|
|
8339
|
+
from: "sites",
|
|
8340
|
+
localField: "site",
|
|
8341
|
+
foreignField: "_id",
|
|
8342
|
+
pipeline: [{ $project: { _id: 0, category: 1 } }],
|
|
8343
|
+
as: "siteInfo"
|
|
8344
|
+
}
|
|
8345
|
+
},
|
|
8346
|
+
{
|
|
8347
|
+
$addFields: {
|
|
8348
|
+
siteCategory: { $first: "$siteInfo.category" }
|
|
8349
|
+
}
|
|
8350
|
+
},
|
|
8351
|
+
{ $project: { siteInfo: 0 } }
|
|
8337
8352
|
]).toArray();
|
|
8338
8353
|
const data = results.length > 0 ? results[0] : null;
|
|
8339
8354
|
if (!data) {
|
|
@@ -65576,6 +65591,74 @@ function usePostPrelovedRepo() {
|
|
|
65576
65591
|
throw error;
|
|
65577
65592
|
}
|
|
65578
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
|
+
}
|
|
65579
65662
|
async function updateById(_id, value, session) {
|
|
65580
65663
|
try {
|
|
65581
65664
|
_id = new ObjectId137(_id);
|
|
@@ -65646,6 +65729,7 @@ function usePostPrelovedRepo() {
|
|
|
65646
65729
|
add,
|
|
65647
65730
|
getById,
|
|
65648
65731
|
getAll,
|
|
65732
|
+
getByOwnerId,
|
|
65649
65733
|
updateById,
|
|
65650
65734
|
deleteById,
|
|
65651
65735
|
updateStatus
|
|
@@ -65860,6 +65944,7 @@ function usePostPrelovedController() {
|
|
|
65860
65944
|
const {
|
|
65861
65945
|
getById: _getById,
|
|
65862
65946
|
getAll: _getAll,
|
|
65947
|
+
getByOwnerId: _getByOwnerId,
|
|
65863
65948
|
updateById: _updateById,
|
|
65864
65949
|
deleteById: _deleteById,
|
|
65865
65950
|
updateStatus: _updateStatus
|
|
@@ -65963,6 +66048,49 @@ function usePostPrelovedController() {
|
|
|
65963
66048
|
return;
|
|
65964
66049
|
}
|
|
65965
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
|
+
}
|
|
65966
66094
|
async function updateById(req, res, next) {
|
|
65967
66095
|
const _id = req.params.id;
|
|
65968
66096
|
const payload = { _id, ...req.body };
|
|
@@ -66033,6 +66161,7 @@ function usePostPrelovedController() {
|
|
|
66033
66161
|
add,
|
|
66034
66162
|
getById,
|
|
66035
66163
|
getAll,
|
|
66164
|
+
getByOwnerId,
|
|
66036
66165
|
updateById,
|
|
66037
66166
|
deleteById,
|
|
66038
66167
|
updateStatus
|