@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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +114 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +114 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -7153,6 +7153,19 @@ declare function usePostPrelovedRepo(): {
|
|
|
7153
7153
|
pages: number;
|
|
7154
7154
|
pageRange: string;
|
|
7155
7155
|
}>;
|
|
7156
|
+
getByOwnerId: (ownerId: string | ObjectId, { search, page, limit, filter, site, status, category, }: {
|
|
7157
|
+
search?: string | undefined;
|
|
7158
|
+
page?: number | undefined;
|
|
7159
|
+
limit?: number | undefined;
|
|
7160
|
+
filter?: string | undefined;
|
|
7161
|
+
site?: string | ObjectId | undefined;
|
|
7162
|
+
status?: string | string[] | undefined;
|
|
7163
|
+
category?: (string | ObjectId)[] | undefined;
|
|
7164
|
+
}, session?: any) => Promise<{
|
|
7165
|
+
items: any[];
|
|
7166
|
+
pages: number;
|
|
7167
|
+
pageRange: string;
|
|
7168
|
+
}>;
|
|
7156
7169
|
updateById: (_id: string | ObjectId, value: Partial<TPost>, session?: any) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
7157
7170
|
deleteById: (_id: string | ObjectId, session?: any) => Promise<number>;
|
|
7158
7171
|
updateStatus: (_id: string | ObjectId, status: PostStatus, session?: any) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
@@ -7162,6 +7175,7 @@ declare function usePostPrelovedController(): {
|
|
|
7162
7175
|
add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
7163
7176
|
getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
7164
7177
|
getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
7178
|
+
getByOwnerId: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
7165
7179
|
updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
7166
7180
|
deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
7167
7181
|
updateStatus: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -65349,6 +65349,74 @@ function usePostPrelovedRepo() {
|
|
|
65349
65349
|
throw error;
|
|
65350
65350
|
}
|
|
65351
65351
|
}
|
|
65352
|
+
async function getByOwnerId(ownerId, {
|
|
65353
|
+
search = "",
|
|
65354
|
+
page = 1,
|
|
65355
|
+
limit = 10,
|
|
65356
|
+
filter,
|
|
65357
|
+
site,
|
|
65358
|
+
status,
|
|
65359
|
+
category
|
|
65360
|
+
}, session) {
|
|
65361
|
+
page = page > 0 ? page - 1 : 0;
|
|
65362
|
+
let ownerObjectId;
|
|
65363
|
+
try {
|
|
65364
|
+
ownerObjectId = new import_mongodb137.ObjectId(ownerId);
|
|
65365
|
+
} catch {
|
|
65366
|
+
throw new import_node_server_utils235.BadRequestError("Invalid user ID format.");
|
|
65367
|
+
}
|
|
65368
|
+
if (site) {
|
|
65369
|
+
try {
|
|
65370
|
+
site = new import_mongodb137.ObjectId(site);
|
|
65371
|
+
} catch {
|
|
65372
|
+
throw new import_node_server_utils235.BadRequestError("Invalid site ID format.");
|
|
65373
|
+
}
|
|
65374
|
+
}
|
|
65375
|
+
let categoryIds = null;
|
|
65376
|
+
if (Array.isArray(category) && category.length > 0) {
|
|
65377
|
+
categoryIds = category.map((cat) => {
|
|
65378
|
+
try {
|
|
65379
|
+
return new import_mongodb137.ObjectId(cat);
|
|
65380
|
+
} catch {
|
|
65381
|
+
throw new import_node_server_utils235.BadRequestError("Invalid category ID format.");
|
|
65382
|
+
}
|
|
65383
|
+
});
|
|
65384
|
+
}
|
|
65385
|
+
const query = {
|
|
65386
|
+
status: { $ne: "deleted" /* DELETED */ },
|
|
65387
|
+
createdBy: ownerObjectId,
|
|
65388
|
+
...site && { site },
|
|
65389
|
+
...search && {
|
|
65390
|
+
$or: [
|
|
65391
|
+
{ title: { $regex: search, $options: "i" } },
|
|
65392
|
+
{ description: { $regex: search, $options: "i" } }
|
|
65393
|
+
]
|
|
65394
|
+
},
|
|
65395
|
+
...status && {
|
|
65396
|
+
status: { $in: Array.isArray(status) ? status : [status] }
|
|
65397
|
+
},
|
|
65398
|
+
...categoryIds && { category: { $in: categoryIds } }
|
|
65399
|
+
};
|
|
65400
|
+
const sortObj = buildSortObj(filter);
|
|
65401
|
+
try {
|
|
65402
|
+
const items = await collection.aggregate(
|
|
65403
|
+
[
|
|
65404
|
+
{ $match: query },
|
|
65405
|
+
USER_LOOKUP,
|
|
65406
|
+
USER_UNWIND,
|
|
65407
|
+
CATEGORY_LOOKUP,
|
|
65408
|
+
{ $sort: sortObj },
|
|
65409
|
+
{ $skip: page * limit },
|
|
65410
|
+
{ $limit: limit }
|
|
65411
|
+
],
|
|
65412
|
+
{ session }
|
|
65413
|
+
).toArray();
|
|
65414
|
+
const length = await collection.countDocuments(query, { session });
|
|
65415
|
+
return (0, import_node_server_utils235.paginate)(items, page, limit, length);
|
|
65416
|
+
} catch (error) {
|
|
65417
|
+
throw error;
|
|
65418
|
+
}
|
|
65419
|
+
}
|
|
65352
65420
|
async function updateById(_id, value, session) {
|
|
65353
65421
|
try {
|
|
65354
65422
|
_id = new import_mongodb137.ObjectId(_id);
|
|
@@ -65419,6 +65487,7 @@ function usePostPrelovedRepo() {
|
|
|
65419
65487
|
add,
|
|
65420
65488
|
getById,
|
|
65421
65489
|
getAll,
|
|
65490
|
+
getByOwnerId,
|
|
65422
65491
|
updateById,
|
|
65423
65492
|
deleteById,
|
|
65424
65493
|
updateStatus
|
|
@@ -65628,6 +65697,7 @@ function usePostPrelovedController() {
|
|
|
65628
65697
|
const {
|
|
65629
65698
|
getById: _getById,
|
|
65630
65699
|
getAll: _getAll,
|
|
65700
|
+
getByOwnerId: _getByOwnerId,
|
|
65631
65701
|
updateById: _updateById,
|
|
65632
65702
|
deleteById: _deleteById,
|
|
65633
65703
|
updateStatus: _updateStatus
|
|
@@ -65731,6 +65801,49 @@ function usePostPrelovedController() {
|
|
|
65731
65801
|
return;
|
|
65732
65802
|
}
|
|
65733
65803
|
}
|
|
65804
|
+
async function getByOwnerId(req, res, next) {
|
|
65805
|
+
const validation = import_joi135.default.object({
|
|
65806
|
+
ownerId: import_joi135.default.string().hex().length(24).required(),
|
|
65807
|
+
page: import_joi135.default.number().integer().min(1).allow("", null).default(1),
|
|
65808
|
+
limit: import_joi135.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
65809
|
+
search: import_joi135.default.string().optional().allow("", null),
|
|
65810
|
+
filter: import_joi135.default.string().valid("recent", "price-low-high", "price-high-low").optional().allow("", null),
|
|
65811
|
+
site: import_joi135.default.string().hex().length(24).optional().allow("", null),
|
|
65812
|
+
status: import_joi135.default.alternatives().try(
|
|
65813
|
+
import_joi135.default.array().items(import_joi135.default.string().valid(...Object.values(PostStatus))),
|
|
65814
|
+
import_joi135.default.string().valid(...Object.values(PostStatus))
|
|
65815
|
+
).optional().allow(null),
|
|
65816
|
+
category: import_joi135.default.array().items(import_joi135.default.string().hex().length(24)).single().optional().allow(null)
|
|
65817
|
+
});
|
|
65818
|
+
const { error, value } = validation.validate(
|
|
65819
|
+
{ ...req.query, ownerId: req.params.ownerId },
|
|
65820
|
+
{ abortEarly: false }
|
|
65821
|
+
);
|
|
65822
|
+
if (error) {
|
|
65823
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
65824
|
+
import_node_server_utils238.logger.log({ level: "error", message: messages });
|
|
65825
|
+
next(new import_node_server_utils238.BadRequestError(messages));
|
|
65826
|
+
return;
|
|
65827
|
+
}
|
|
65828
|
+
const { ownerId, page, limit, search, filter, site, status, category } = value;
|
|
65829
|
+
try {
|
|
65830
|
+
const data = await _getByOwnerId(ownerId, {
|
|
65831
|
+
page,
|
|
65832
|
+
limit,
|
|
65833
|
+
search,
|
|
65834
|
+
filter,
|
|
65835
|
+
site,
|
|
65836
|
+
status: status ? Array.isArray(status) ? status : [status] : void 0,
|
|
65837
|
+
category: category ?? void 0
|
|
65838
|
+
});
|
|
65839
|
+
res.status(200).json(data);
|
|
65840
|
+
return;
|
|
65841
|
+
} catch (error2) {
|
|
65842
|
+
import_node_server_utils238.logger.log({ level: "error", message: error2.message });
|
|
65843
|
+
next(error2);
|
|
65844
|
+
return;
|
|
65845
|
+
}
|
|
65846
|
+
}
|
|
65734
65847
|
async function updateById(req, res, next) {
|
|
65735
65848
|
const _id = req.params.id;
|
|
65736
65849
|
const payload = { _id, ...req.body };
|
|
@@ -65801,6 +65914,7 @@ function usePostPrelovedController() {
|
|
|
65801
65914
|
add,
|
|
65802
65915
|
getById,
|
|
65803
65916
|
getAll,
|
|
65917
|
+
getByOwnerId,
|
|
65804
65918
|
updateById,
|
|
65805
65919
|
deleteById,
|
|
65806
65920
|
updateStatus
|