@7365admin1/core 2.63.0 → 2.65.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 +84 -1
- package/dist/index.js +584 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +582 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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,
|
|
@@ -248,6 +253,7 @@ __export(src_exports, {
|
|
|
248
253
|
schemaUpdatePatrolQuestion: () => schemaUpdatePatrolQuestion,
|
|
249
254
|
schemaUpdatePatrolRoute: () => schemaUpdatePatrolRoute,
|
|
250
255
|
schemaUpdatePerson: () => schemaUpdatePerson,
|
|
256
|
+
schemaUpdatePost: () => schemaUpdatePost,
|
|
251
257
|
schemaUpdateServiceProviderBilling: () => schemaUpdateServiceProviderBilling,
|
|
252
258
|
schemaUpdateSiteBillingConfiguration: () => schemaUpdateSiteBillingConfiguration,
|
|
253
259
|
schemaUpdateSiteBillingItem: () => schemaUpdateSiteBillingItem,
|
|
@@ -382,6 +388,8 @@ __export(src_exports, {
|
|
|
382
388
|
usePatrolRouteRepo: () => usePatrolRouteRepo,
|
|
383
389
|
usePersonController: () => usePersonController,
|
|
384
390
|
usePersonRepo: () => usePersonRepo,
|
|
391
|
+
usePostPrelovedController: () => usePostPrelovedController,
|
|
392
|
+
usePostPrelovedRepo: () => usePostPrelovedRepo,
|
|
385
393
|
usePriceController: () => usePriceController,
|
|
386
394
|
usePriceModel: () => usePriceModel,
|
|
387
395
|
usePriceRepo: () => usePriceRepo,
|
|
@@ -12566,6 +12574,33 @@ function useServiceProviderRepo() {
|
|
|
12566
12574
|
throw error;
|
|
12567
12575
|
}
|
|
12568
12576
|
}
|
|
12577
|
+
async function updateStatusById(_id, status) {
|
|
12578
|
+
try {
|
|
12579
|
+
_id = new import_mongodb34.ObjectId(_id);
|
|
12580
|
+
} catch (error) {
|
|
12581
|
+
throw new import_node_server_utils56.BadRequestError("Invalid service provider ID format.");
|
|
12582
|
+
}
|
|
12583
|
+
try {
|
|
12584
|
+
const result = await collection.updateOne(
|
|
12585
|
+
{ _id },
|
|
12586
|
+
{ $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } }
|
|
12587
|
+
);
|
|
12588
|
+
if (!result.matchedCount) {
|
|
12589
|
+
throw new import_node_server_utils56.NotFoundError("Service provider not found.");
|
|
12590
|
+
}
|
|
12591
|
+
delNamespace().then(() => {
|
|
12592
|
+
import_node_server_utils56.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
12593
|
+
}).catch((err) => {
|
|
12594
|
+
import_node_server_utils56.logger.error(
|
|
12595
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
12596
|
+
err
|
|
12597
|
+
);
|
|
12598
|
+
});
|
|
12599
|
+
return result;
|
|
12600
|
+
} catch (error) {
|
|
12601
|
+
throw error;
|
|
12602
|
+
}
|
|
12603
|
+
}
|
|
12569
12604
|
return {
|
|
12570
12605
|
createTextIndex,
|
|
12571
12606
|
createUniqueIndex,
|
|
@@ -12575,7 +12610,8 @@ function useServiceProviderRepo() {
|
|
|
12575
12610
|
getServiceProviderTypes,
|
|
12576
12611
|
getServiceProviderById,
|
|
12577
12612
|
getByServiceProviderOrgIdType,
|
|
12578
|
-
getByEmail
|
|
12613
|
+
getByEmail,
|
|
12614
|
+
updateStatusById
|
|
12579
12615
|
};
|
|
12580
12616
|
}
|
|
12581
12617
|
|
|
@@ -13351,7 +13387,8 @@ function useServiceProviderController() {
|
|
|
13351
13387
|
getServiceProviderTypes: _getServiceProviderTypes,
|
|
13352
13388
|
getServiceProviderById: _getServiceProviderById,
|
|
13353
13389
|
getServiceProviders: _getServiceProviders,
|
|
13354
|
-
getByServiceProviderOrgIdType: _getByServiceProviderOrgIdType
|
|
13390
|
+
getByServiceProviderOrgIdType: _getByServiceProviderOrgIdType,
|
|
13391
|
+
updateStatusById: _updateStatusById
|
|
13355
13392
|
} = useServiceProviderRepo();
|
|
13356
13393
|
const { createServiceProvider: _createServiceProvider } = useServiceProviderService();
|
|
13357
13394
|
const { createServiceProvider: _add } = useServiceProviderRepo();
|
|
@@ -13565,6 +13602,30 @@ function useServiceProviderController() {
|
|
|
13565
13602
|
return;
|
|
13566
13603
|
}
|
|
13567
13604
|
}
|
|
13605
|
+
async function updateStatusById(req, res, next) {
|
|
13606
|
+
const validation = import_joi31.default.object({
|
|
13607
|
+
id: import_joi31.default.string().hex().required(),
|
|
13608
|
+
status: import_joi31.default.string().valid("active", "inactive").required()
|
|
13609
|
+
});
|
|
13610
|
+
const { error, value } = validation.validate({
|
|
13611
|
+
id: req.params.id,
|
|
13612
|
+
status: req.body.status
|
|
13613
|
+
});
|
|
13614
|
+
if (error) {
|
|
13615
|
+
import_node_server_utils62.logger.log({ level: "error", message: error.message });
|
|
13616
|
+
next(new import_node_server_utils62.BadRequestError(error.message));
|
|
13617
|
+
return;
|
|
13618
|
+
}
|
|
13619
|
+
try {
|
|
13620
|
+
await _updateStatusById(value.id, value.status);
|
|
13621
|
+
res.json({ message: "Service provider status updated successfully." });
|
|
13622
|
+
return;
|
|
13623
|
+
} catch (error2) {
|
|
13624
|
+
import_node_server_utils62.logger.log({ level: "error", message: error2.message });
|
|
13625
|
+
next(error2);
|
|
13626
|
+
return;
|
|
13627
|
+
}
|
|
13628
|
+
}
|
|
13568
13629
|
return {
|
|
13569
13630
|
createServiceProvider,
|
|
13570
13631
|
getServiceProviders,
|
|
@@ -13573,7 +13634,8 @@ function useServiceProviderController() {
|
|
|
13573
13634
|
getServiceProviderTypes,
|
|
13574
13635
|
getServiceProviderById,
|
|
13575
13636
|
getByServiceProviderOrgIdType,
|
|
13576
|
-
add
|
|
13637
|
+
add,
|
|
13638
|
+
updateStatusById
|
|
13577
13639
|
};
|
|
13578
13640
|
}
|
|
13579
13641
|
|
|
@@ -53431,6 +53493,517 @@ function useRoleControllerV2() {
|
|
|
53431
53493
|
createRole
|
|
53432
53494
|
};
|
|
53433
53495
|
}
|
|
53496
|
+
|
|
53497
|
+
// src/models/post-preloved.model.ts
|
|
53498
|
+
var import_joi132 = __toESM(require("joi"));
|
|
53499
|
+
var import_mongodb129 = require("mongodb");
|
|
53500
|
+
var PostStatus = /* @__PURE__ */ ((PostStatus2) => {
|
|
53501
|
+
PostStatus2["PUBLISHED"] = "published";
|
|
53502
|
+
PostStatus2["RESERVED"] = "reserved";
|
|
53503
|
+
PostStatus2["SOLD"] = "sold";
|
|
53504
|
+
PostStatus2["DELETED"] = "deleted";
|
|
53505
|
+
return PostStatus2;
|
|
53506
|
+
})(PostStatus || {});
|
|
53507
|
+
var PostSort = /* @__PURE__ */ ((PostSort2) => {
|
|
53508
|
+
PostSort2["CREATED_AT"] = "createdAt";
|
|
53509
|
+
PostSort2["TITLE"] = "title";
|
|
53510
|
+
PostSort2["PRICE"] = "price";
|
|
53511
|
+
PostSort2["ID"] = "_id";
|
|
53512
|
+
return PostSort2;
|
|
53513
|
+
})(PostSort || {});
|
|
53514
|
+
var PostOrder = /* @__PURE__ */ ((PostOrder2) => {
|
|
53515
|
+
PostOrder2["ASC"] = "asc";
|
|
53516
|
+
PostOrder2["DESC"] = "desc";
|
|
53517
|
+
return PostOrder2;
|
|
53518
|
+
})(PostOrder || {});
|
|
53519
|
+
var schemaPost = import_joi132.default.object({
|
|
53520
|
+
_id: import_joi132.default.string().hex().optional().allow("", null),
|
|
53521
|
+
title: import_joi132.default.string().required(),
|
|
53522
|
+
description: import_joi132.default.string().optional().allow("", null),
|
|
53523
|
+
attachments: import_joi132.default.array().items(import_joi132.default.string().hex().optional()).optional().allow(null),
|
|
53524
|
+
category: import_joi132.default.array().items(import_joi132.default.string().hex().optional()).optional().allow(null),
|
|
53525
|
+
currency: import_joi132.default.string().optional().allow("", null),
|
|
53526
|
+
price: import_joi132.default.number().required(),
|
|
53527
|
+
status: import_joi132.default.string().valid(...Object.values(PostStatus)).optional().default("published" /* PUBLISHED */),
|
|
53528
|
+
reserverId: import_joi132.default.string().hex().optional().allow("", null),
|
|
53529
|
+
createdBy: import_joi132.default.string().hex().optional().allow("", null),
|
|
53530
|
+
site: import_joi132.default.string().hex().optional().allow("", null),
|
|
53531
|
+
createdAt: import_joi132.default.date().optional().allow(null),
|
|
53532
|
+
updatedAt: import_joi132.default.date().optional().allow(null),
|
|
53533
|
+
deletedAt: import_joi132.default.date().optional().allow(null)
|
|
53534
|
+
});
|
|
53535
|
+
var schemaUpdatePost = import_joi132.default.object({
|
|
53536
|
+
_id: import_joi132.default.string().hex().required(),
|
|
53537
|
+
title: import_joi132.default.string().optional().allow("", null),
|
|
53538
|
+
description: import_joi132.default.string().optional().allow("", null),
|
|
53539
|
+
attachments: import_joi132.default.array().items(import_joi132.default.string().hex().optional()).optional().allow(null),
|
|
53540
|
+
category: import_joi132.default.array().items(import_joi132.default.string().hex().optional()).optional().allow(null),
|
|
53541
|
+
currency: import_joi132.default.string().optional().allow("", null),
|
|
53542
|
+
price: import_joi132.default.number().optional(),
|
|
53543
|
+
status: import_joi132.default.string().valid(...Object.values(PostStatus)).optional().allow(null),
|
|
53544
|
+
reserverId: import_joi132.default.string().hex().optional().allow("", null)
|
|
53545
|
+
});
|
|
53546
|
+
function MPost(value) {
|
|
53547
|
+
const { error } = schemaPost.validate(value);
|
|
53548
|
+
if (error) {
|
|
53549
|
+
throw new Error(error.details[0].message);
|
|
53550
|
+
}
|
|
53551
|
+
if (value._id && typeof value._id === "string") {
|
|
53552
|
+
try {
|
|
53553
|
+
value._id = new import_mongodb129.ObjectId(value._id);
|
|
53554
|
+
} catch {
|
|
53555
|
+
throw new Error("Invalid ID.");
|
|
53556
|
+
}
|
|
53557
|
+
}
|
|
53558
|
+
if (value.site && typeof value.site === "string") {
|
|
53559
|
+
try {
|
|
53560
|
+
value.site = new import_mongodb129.ObjectId(value.site);
|
|
53561
|
+
} catch {
|
|
53562
|
+
throw new Error("Invalid site ID.");
|
|
53563
|
+
}
|
|
53564
|
+
}
|
|
53565
|
+
if (value.createdBy && typeof value.createdBy === "string") {
|
|
53566
|
+
try {
|
|
53567
|
+
value.createdBy = new import_mongodb129.ObjectId(value.createdBy);
|
|
53568
|
+
} catch {
|
|
53569
|
+
throw new Error("Invalid createdBy ID.");
|
|
53570
|
+
}
|
|
53571
|
+
}
|
|
53572
|
+
if (value.reserverId && typeof value.reserverId === "string") {
|
|
53573
|
+
try {
|
|
53574
|
+
value.reserverId = new import_mongodb129.ObjectId(value.reserverId);
|
|
53575
|
+
} catch {
|
|
53576
|
+
throw new Error("Invalid reserver ID.");
|
|
53577
|
+
}
|
|
53578
|
+
}
|
|
53579
|
+
if (value.attachments && Array.isArray(value.attachments)) {
|
|
53580
|
+
value.attachments = value.attachments.map((id) => {
|
|
53581
|
+
if (typeof id === "string") {
|
|
53582
|
+
try {
|
|
53583
|
+
return new import_mongodb129.ObjectId(id);
|
|
53584
|
+
} catch {
|
|
53585
|
+
throw new Error("Invalid attachment ID.");
|
|
53586
|
+
}
|
|
53587
|
+
}
|
|
53588
|
+
return id;
|
|
53589
|
+
});
|
|
53590
|
+
}
|
|
53591
|
+
if (value.category && Array.isArray(value.category)) {
|
|
53592
|
+
value.category = value.category.map((id) => {
|
|
53593
|
+
if (typeof id === "string") {
|
|
53594
|
+
try {
|
|
53595
|
+
return new import_mongodb129.ObjectId(id);
|
|
53596
|
+
} catch {
|
|
53597
|
+
throw new Error("Invalid category ID.");
|
|
53598
|
+
}
|
|
53599
|
+
}
|
|
53600
|
+
return id;
|
|
53601
|
+
});
|
|
53602
|
+
}
|
|
53603
|
+
return {
|
|
53604
|
+
_id: value._id ?? new import_mongodb129.ObjectId(),
|
|
53605
|
+
title: value.title ?? "",
|
|
53606
|
+
description: value.description ?? "",
|
|
53607
|
+
attachments: value.attachments ?? [],
|
|
53608
|
+
category: value.category ?? [],
|
|
53609
|
+
currency: value.currency ?? "",
|
|
53610
|
+
price: value.price ?? 0,
|
|
53611
|
+
status: value.status ?? "published" /* PUBLISHED */,
|
|
53612
|
+
reserverId: value.reserverId ?? null,
|
|
53613
|
+
createdBy: value.createdBy ?? "",
|
|
53614
|
+
site: value.site ?? "",
|
|
53615
|
+
createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
53616
|
+
updatedAt: value.updatedAt ?? null,
|
|
53617
|
+
deletedAt: value.deletedAt ?? null
|
|
53618
|
+
};
|
|
53619
|
+
}
|
|
53620
|
+
|
|
53621
|
+
// src/repositories/post-preloved.repo.ts
|
|
53622
|
+
var import_node_server_utils232 = require("@7365admin1/node-server-utils");
|
|
53623
|
+
var import_mongodb130 = require("mongodb");
|
|
53624
|
+
function usePostPrelovedRepo() {
|
|
53625
|
+
const db = import_node_server_utils232.useAtlas.getDb();
|
|
53626
|
+
if (!db) {
|
|
53627
|
+
throw new import_node_server_utils232.InternalServerError("Unable to connect to server.");
|
|
53628
|
+
}
|
|
53629
|
+
const POST_COLLECTION = "post-preloved";
|
|
53630
|
+
const USER_LOOKUP = {
|
|
53631
|
+
$lookup: {
|
|
53632
|
+
from: "users",
|
|
53633
|
+
localField: "createdBy",
|
|
53634
|
+
foreignField: "_id",
|
|
53635
|
+
pipeline: [
|
|
53636
|
+
{
|
|
53637
|
+
$project: {
|
|
53638
|
+
name: 1,
|
|
53639
|
+
profile: 1
|
|
53640
|
+
}
|
|
53641
|
+
}
|
|
53642
|
+
],
|
|
53643
|
+
as: "createdBy"
|
|
53644
|
+
}
|
|
53645
|
+
};
|
|
53646
|
+
const USER_UNWIND = {
|
|
53647
|
+
$unwind: {
|
|
53648
|
+
path: "$createdBy",
|
|
53649
|
+
preserveNullAndEmptyArrays: true
|
|
53650
|
+
}
|
|
53651
|
+
};
|
|
53652
|
+
const CATEGORY_LOOKUP = {
|
|
53653
|
+
$lookup: {
|
|
53654
|
+
from: "category-preloved",
|
|
53655
|
+
localField: "category",
|
|
53656
|
+
foreignField: "_id",
|
|
53657
|
+
as: "categories"
|
|
53658
|
+
}
|
|
53659
|
+
};
|
|
53660
|
+
const collection = db.collection(POST_COLLECTION);
|
|
53661
|
+
function buildSortObj(filter) {
|
|
53662
|
+
switch (filter) {
|
|
53663
|
+
case "price-low-high":
|
|
53664
|
+
return { price: 1 };
|
|
53665
|
+
case "price-high-low":
|
|
53666
|
+
return { price: -1 };
|
|
53667
|
+
case "recent":
|
|
53668
|
+
default:
|
|
53669
|
+
return { createdAt: -1 };
|
|
53670
|
+
}
|
|
53671
|
+
}
|
|
53672
|
+
async function add(value, session) {
|
|
53673
|
+
try {
|
|
53674
|
+
const doc = MPost(value);
|
|
53675
|
+
const res = await collection.insertOne(doc, { session });
|
|
53676
|
+
return res.insertedId;
|
|
53677
|
+
} catch (error) {
|
|
53678
|
+
const isDuplicated = error.message?.includes("duplicate");
|
|
53679
|
+
if (isDuplicated)
|
|
53680
|
+
throw new import_node_server_utils232.BadRequestError("Post already exists.");
|
|
53681
|
+
throw error;
|
|
53682
|
+
}
|
|
53683
|
+
}
|
|
53684
|
+
async function getById(_id) {
|
|
53685
|
+
try {
|
|
53686
|
+
_id = new import_mongodb130.ObjectId(_id);
|
|
53687
|
+
} catch {
|
|
53688
|
+
throw new import_node_server_utils232.BadRequestError("Invalid post ID format.");
|
|
53689
|
+
}
|
|
53690
|
+
try {
|
|
53691
|
+
const result = await collection.aggregate([
|
|
53692
|
+
{ $match: { _id, status: { $ne: "deleted" /* DELETED */ } } },
|
|
53693
|
+
USER_LOOKUP,
|
|
53694
|
+
USER_UNWIND,
|
|
53695
|
+
CATEGORY_LOOKUP
|
|
53696
|
+
]).toArray();
|
|
53697
|
+
const data = result[0] ?? null;
|
|
53698
|
+
if (!data)
|
|
53699
|
+
throw new import_node_server_utils232.NotFoundError("Post not found.");
|
|
53700
|
+
return data;
|
|
53701
|
+
} catch (error) {
|
|
53702
|
+
throw error;
|
|
53703
|
+
}
|
|
53704
|
+
}
|
|
53705
|
+
async function getAll({
|
|
53706
|
+
search = "",
|
|
53707
|
+
page = 1,
|
|
53708
|
+
limit = 10,
|
|
53709
|
+
filter,
|
|
53710
|
+
site,
|
|
53711
|
+
status,
|
|
53712
|
+
category
|
|
53713
|
+
}, session) {
|
|
53714
|
+
page = page > 0 ? page - 1 : 0;
|
|
53715
|
+
if (site) {
|
|
53716
|
+
try {
|
|
53717
|
+
site = new import_mongodb130.ObjectId(site);
|
|
53718
|
+
} catch {
|
|
53719
|
+
throw new import_node_server_utils232.BadRequestError("Invalid site ID format.");
|
|
53720
|
+
}
|
|
53721
|
+
}
|
|
53722
|
+
const categoryIds = category && Array.isArray(category) && category.length > 0 ? category.map((id) => {
|
|
53723
|
+
try {
|
|
53724
|
+
return new import_mongodb130.ObjectId(id);
|
|
53725
|
+
} catch {
|
|
53726
|
+
throw new import_node_server_utils232.BadRequestError("Invalid category ID format.");
|
|
53727
|
+
}
|
|
53728
|
+
}) : null;
|
|
53729
|
+
const query = {
|
|
53730
|
+
status: { $ne: "deleted" /* DELETED */ },
|
|
53731
|
+
...site && { site },
|
|
53732
|
+
...search && {
|
|
53733
|
+
$or: [
|
|
53734
|
+
{ title: { $regex: search, $options: "i" } },
|
|
53735
|
+
{ description: { $regex: search, $options: "i" } }
|
|
53736
|
+
]
|
|
53737
|
+
},
|
|
53738
|
+
...status && {
|
|
53739
|
+
status: { $in: Array.isArray(status) ? status : [status] }
|
|
53740
|
+
},
|
|
53741
|
+
...categoryIds && { category: { $in: categoryIds } }
|
|
53742
|
+
};
|
|
53743
|
+
const sortObj = buildSortObj(filter);
|
|
53744
|
+
try {
|
|
53745
|
+
const items = await collection.aggregate(
|
|
53746
|
+
[
|
|
53747
|
+
{ $match: query },
|
|
53748
|
+
USER_LOOKUP,
|
|
53749
|
+
USER_UNWIND,
|
|
53750
|
+
CATEGORY_LOOKUP,
|
|
53751
|
+
{ $sort: sortObj },
|
|
53752
|
+
{ $skip: page * limit },
|
|
53753
|
+
{ $limit: limit }
|
|
53754
|
+
],
|
|
53755
|
+
{ session }
|
|
53756
|
+
).toArray();
|
|
53757
|
+
const length = await collection.countDocuments(query, { session });
|
|
53758
|
+
return (0, import_node_server_utils232.paginate)(items, page, limit, length);
|
|
53759
|
+
} catch (error) {
|
|
53760
|
+
throw error;
|
|
53761
|
+
}
|
|
53762
|
+
}
|
|
53763
|
+
async function updateById(_id, value, session) {
|
|
53764
|
+
try {
|
|
53765
|
+
_id = new import_mongodb130.ObjectId(_id);
|
|
53766
|
+
} catch {
|
|
53767
|
+
throw new import_node_server_utils232.BadRequestError("Invalid post ID format.");
|
|
53768
|
+
}
|
|
53769
|
+
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
53770
|
+
try {
|
|
53771
|
+
const res = await collection.updateOne(
|
|
53772
|
+
{ _id },
|
|
53773
|
+
{ $set: value },
|
|
53774
|
+
{ session }
|
|
53775
|
+
);
|
|
53776
|
+
if (res.modifiedCount === 0) {
|
|
53777
|
+
throw new import_node_server_utils232.InternalServerError("Unable to update post.");
|
|
53778
|
+
}
|
|
53779
|
+
return res;
|
|
53780
|
+
} catch (error) {
|
|
53781
|
+
throw error;
|
|
53782
|
+
}
|
|
53783
|
+
}
|
|
53784
|
+
async function deleteById(_id, session) {
|
|
53785
|
+
try {
|
|
53786
|
+
_id = new import_mongodb130.ObjectId(_id);
|
|
53787
|
+
} catch {
|
|
53788
|
+
throw new import_node_server_utils232.BadRequestError("Invalid post ID format.");
|
|
53789
|
+
}
|
|
53790
|
+
try {
|
|
53791
|
+
const res = await collection.updateOne(
|
|
53792
|
+
{ _id },
|
|
53793
|
+
{
|
|
53794
|
+
$set: {
|
|
53795
|
+
status: "deleted" /* DELETED */,
|
|
53796
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
53797
|
+
deletedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
53798
|
+
}
|
|
53799
|
+
},
|
|
53800
|
+
{ session }
|
|
53801
|
+
);
|
|
53802
|
+
if (res.modifiedCount === 0) {
|
|
53803
|
+
throw new import_node_server_utils232.InternalServerError("Unable to delete post.");
|
|
53804
|
+
}
|
|
53805
|
+
return res.modifiedCount;
|
|
53806
|
+
} catch (error) {
|
|
53807
|
+
throw error;
|
|
53808
|
+
}
|
|
53809
|
+
}
|
|
53810
|
+
async function updateStatus(_id, status, session) {
|
|
53811
|
+
try {
|
|
53812
|
+
_id = new import_mongodb130.ObjectId(_id);
|
|
53813
|
+
} catch {
|
|
53814
|
+
throw new import_node_server_utils232.BadRequestError("Invalid post ID format.");
|
|
53815
|
+
}
|
|
53816
|
+
try {
|
|
53817
|
+
const res = await collection.updateOne(
|
|
53818
|
+
{ _id },
|
|
53819
|
+
{ $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
53820
|
+
{ session }
|
|
53821
|
+
);
|
|
53822
|
+
if (res.modifiedCount === 0)
|
|
53823
|
+
throw new import_node_server_utils232.InternalServerError("Unable to update post status.");
|
|
53824
|
+
return res;
|
|
53825
|
+
} catch (error) {
|
|
53826
|
+
throw error;
|
|
53827
|
+
}
|
|
53828
|
+
}
|
|
53829
|
+
return {
|
|
53830
|
+
add,
|
|
53831
|
+
getById,
|
|
53832
|
+
getAll,
|
|
53833
|
+
updateById,
|
|
53834
|
+
deleteById,
|
|
53835
|
+
updateStatus
|
|
53836
|
+
};
|
|
53837
|
+
}
|
|
53838
|
+
|
|
53839
|
+
// src/controllers/post-preloved.controller.ts
|
|
53840
|
+
var import_node_server_utils233 = require("@7365admin1/node-server-utils");
|
|
53841
|
+
var import_joi133 = __toESM(require("joi"));
|
|
53842
|
+
function usePostPrelovedController() {
|
|
53843
|
+
const {
|
|
53844
|
+
add: _add,
|
|
53845
|
+
getById: _getById,
|
|
53846
|
+
getAll: _getAll,
|
|
53847
|
+
updateById: _updateById,
|
|
53848
|
+
deleteById: _deleteById,
|
|
53849
|
+
updateStatus: _updateStatus
|
|
53850
|
+
} = usePostPrelovedRepo();
|
|
53851
|
+
async function add(req, res, next) {
|
|
53852
|
+
const { error, value } = schemaPost.validate(req.body, {
|
|
53853
|
+
abortEarly: false
|
|
53854
|
+
});
|
|
53855
|
+
if (error) {
|
|
53856
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
53857
|
+
import_node_server_utils233.logger.log({ level: "error", message: messages });
|
|
53858
|
+
next(new import_node_server_utils233.BadRequestError(messages));
|
|
53859
|
+
return;
|
|
53860
|
+
}
|
|
53861
|
+
try {
|
|
53862
|
+
const data = await _add(value);
|
|
53863
|
+
res.status(201).json(data);
|
|
53864
|
+
return;
|
|
53865
|
+
} catch (error2) {
|
|
53866
|
+
import_node_server_utils233.logger.log({ level: "error", message: error2.message });
|
|
53867
|
+
next(error2);
|
|
53868
|
+
return;
|
|
53869
|
+
}
|
|
53870
|
+
}
|
|
53871
|
+
async function getById(req, res, next) {
|
|
53872
|
+
const schema2 = import_joi133.default.object({
|
|
53873
|
+
_id: import_joi133.default.string().hex().length(24).required()
|
|
53874
|
+
});
|
|
53875
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
53876
|
+
if (error) {
|
|
53877
|
+
import_node_server_utils233.logger.log({ level: "error", message: error.message });
|
|
53878
|
+
next(new import_node_server_utils233.BadRequestError(error.message));
|
|
53879
|
+
return;
|
|
53880
|
+
}
|
|
53881
|
+
try {
|
|
53882
|
+
const data = await _getById(value._id);
|
|
53883
|
+
res.status(200).json(data);
|
|
53884
|
+
return;
|
|
53885
|
+
} catch (error2) {
|
|
53886
|
+
import_node_server_utils233.logger.log({ level: "error", message: error2.message });
|
|
53887
|
+
next(error2);
|
|
53888
|
+
return;
|
|
53889
|
+
}
|
|
53890
|
+
}
|
|
53891
|
+
async function getAll(req, res, next) {
|
|
53892
|
+
const validation = import_joi133.default.object({
|
|
53893
|
+
page: import_joi133.default.number().integer().min(1).allow("", null).default(1),
|
|
53894
|
+
limit: import_joi133.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
53895
|
+
search: import_joi133.default.string().optional().allow("", null),
|
|
53896
|
+
filter: import_joi133.default.string().valid("recent", "price-low-high", "price-high-low").optional().allow("", null),
|
|
53897
|
+
site: import_joi133.default.string().hex().length(24).optional().allow("", null),
|
|
53898
|
+
status: import_joi133.default.alternatives().try(
|
|
53899
|
+
import_joi133.default.array().items(import_joi133.default.string().valid(...Object.values(PostStatus))),
|
|
53900
|
+
import_joi133.default.string().valid(...Object.values(PostStatus))
|
|
53901
|
+
).optional().allow(null),
|
|
53902
|
+
category: import_joi133.default.alternatives().try(import_joi133.default.array().items(import_joi133.default.string().hex()), import_joi133.default.string().hex()).optional().allow(null)
|
|
53903
|
+
});
|
|
53904
|
+
const { error, value } = validation.validate(req.query, {
|
|
53905
|
+
abortEarly: false
|
|
53906
|
+
});
|
|
53907
|
+
if (error) {
|
|
53908
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
53909
|
+
import_node_server_utils233.logger.log({ level: "error", message: messages });
|
|
53910
|
+
next(new import_node_server_utils233.BadRequestError(messages));
|
|
53911
|
+
return;
|
|
53912
|
+
}
|
|
53913
|
+
const { page, limit, search, filter, site, status, category } = value;
|
|
53914
|
+
try {
|
|
53915
|
+
const data = await _getAll({
|
|
53916
|
+
page,
|
|
53917
|
+
limit,
|
|
53918
|
+
search,
|
|
53919
|
+
filter,
|
|
53920
|
+
site,
|
|
53921
|
+
status: status ? Array.isArray(status) ? status : [status] : void 0,
|
|
53922
|
+
category: category ? Array.isArray(category) ? category : [category] : void 0
|
|
53923
|
+
});
|
|
53924
|
+
res.status(200).json(data);
|
|
53925
|
+
return;
|
|
53926
|
+
} catch (error2) {
|
|
53927
|
+
import_node_server_utils233.logger.log({ level: "error", message: error2.message });
|
|
53928
|
+
next(error2);
|
|
53929
|
+
return;
|
|
53930
|
+
}
|
|
53931
|
+
}
|
|
53932
|
+
async function updateById(req, res, next) {
|
|
53933
|
+
const _id = req.params.id;
|
|
53934
|
+
const payload = { _id, ...req.body };
|
|
53935
|
+
const { error } = schemaUpdatePost.validate(payload, {
|
|
53936
|
+
abortEarly: false
|
|
53937
|
+
});
|
|
53938
|
+
if (error) {
|
|
53939
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
53940
|
+
import_node_server_utils233.logger.log({ level: "error", message: messages });
|
|
53941
|
+
next(new import_node_server_utils233.BadRequestError(messages));
|
|
53942
|
+
return;
|
|
53943
|
+
}
|
|
53944
|
+
try {
|
|
53945
|
+
const data = await _updateById(_id, req.body);
|
|
53946
|
+
res.status(200).json(data);
|
|
53947
|
+
return;
|
|
53948
|
+
} catch (error2) {
|
|
53949
|
+
import_node_server_utils233.logger.log({ level: "error", message: error2.message });
|
|
53950
|
+
next(error2);
|
|
53951
|
+
return;
|
|
53952
|
+
}
|
|
53953
|
+
}
|
|
53954
|
+
async function deleteById(req, res, next) {
|
|
53955
|
+
const schema2 = import_joi133.default.object({
|
|
53956
|
+
_id: import_joi133.default.string().hex().length(24).required()
|
|
53957
|
+
});
|
|
53958
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
53959
|
+
if (error) {
|
|
53960
|
+
import_node_server_utils233.logger.log({ level: "error", message: error.message });
|
|
53961
|
+
next(new import_node_server_utils233.BadRequestError(error.message));
|
|
53962
|
+
return;
|
|
53963
|
+
}
|
|
53964
|
+
try {
|
|
53965
|
+
const data = await _deleteById(value._id);
|
|
53966
|
+
res.status(200).json({ message: "Successfully deleted post." });
|
|
53967
|
+
return;
|
|
53968
|
+
} catch (error2) {
|
|
53969
|
+
import_node_server_utils233.logger.log({ level: "error", message: error2.message });
|
|
53970
|
+
next(error2);
|
|
53971
|
+
return;
|
|
53972
|
+
}
|
|
53973
|
+
}
|
|
53974
|
+
async function updateStatus(req, res, next) {
|
|
53975
|
+
const schema2 = import_joi133.default.object({
|
|
53976
|
+
_id: import_joi133.default.string().hex().length(24).required(),
|
|
53977
|
+
status: import_joi133.default.string().valid(...Object.values(PostStatus)).required()
|
|
53978
|
+
});
|
|
53979
|
+
const { error, value } = schema2.validate({
|
|
53980
|
+
_id: req.params.id,
|
|
53981
|
+
status: req.body.status
|
|
53982
|
+
});
|
|
53983
|
+
if (error) {
|
|
53984
|
+
import_node_server_utils233.logger.log({ level: "error", message: error.message });
|
|
53985
|
+
next(new import_node_server_utils233.BadRequestError(error.message));
|
|
53986
|
+
return;
|
|
53987
|
+
}
|
|
53988
|
+
try {
|
|
53989
|
+
const data = await _updateStatus(value._id, value.status);
|
|
53990
|
+
res.status(200).json(data);
|
|
53991
|
+
return;
|
|
53992
|
+
} catch (error2) {
|
|
53993
|
+
import_node_server_utils233.logger.log({ level: "error", message: error2.message });
|
|
53994
|
+
next(error2);
|
|
53995
|
+
return;
|
|
53996
|
+
}
|
|
53997
|
+
}
|
|
53998
|
+
return {
|
|
53999
|
+
add,
|
|
54000
|
+
getById,
|
|
54001
|
+
getAll,
|
|
54002
|
+
updateById,
|
|
54003
|
+
deleteById,
|
|
54004
|
+
updateStatus
|
|
54005
|
+
};
|
|
54006
|
+
}
|
|
53434
54007
|
// Annotate the CommonJS export names for ESM import in node:
|
|
53435
54008
|
0 && (module.exports = {
|
|
53436
54009
|
ANPRMode,
|
|
@@ -53502,6 +54075,7 @@ function useRoleControllerV2() {
|
|
|
53502
54075
|
MPatrolQuestion,
|
|
53503
54076
|
MPatrolRoute,
|
|
53504
54077
|
MPerson,
|
|
54078
|
+
MPost,
|
|
53505
54079
|
MPromoCode,
|
|
53506
54080
|
MRobot,
|
|
53507
54081
|
MRole,
|
|
@@ -53532,6 +54106,9 @@ function useRoleControllerV2() {
|
|
|
53532
54106
|
Period,
|
|
53533
54107
|
PersonStatus,
|
|
53534
54108
|
PersonTypes,
|
|
54109
|
+
PostOrder,
|
|
54110
|
+
PostSort,
|
|
54111
|
+
PostStatus,
|
|
53535
54112
|
SiteCategories,
|
|
53536
54113
|
SiteStatus,
|
|
53537
54114
|
SortFields,
|
|
@@ -53627,6 +54204,7 @@ function useRoleControllerV2() {
|
|
|
53627
54204
|
schemaPatrolRoute,
|
|
53628
54205
|
schemaPerson,
|
|
53629
54206
|
schemaPlate,
|
|
54207
|
+
schemaPost,
|
|
53630
54208
|
schemaServiceProvider,
|
|
53631
54209
|
schemaServiceProviderBilling,
|
|
53632
54210
|
schemaSiteCamera,
|
|
@@ -53651,6 +54229,7 @@ function useRoleControllerV2() {
|
|
|
53651
54229
|
schemaUpdatePatrolQuestion,
|
|
53652
54230
|
schemaUpdatePatrolRoute,
|
|
53653
54231
|
schemaUpdatePerson,
|
|
54232
|
+
schemaUpdatePost,
|
|
53654
54233
|
schemaUpdateServiceProviderBilling,
|
|
53655
54234
|
schemaUpdateSiteBillingConfiguration,
|
|
53656
54235
|
schemaUpdateSiteBillingItem,
|
|
@@ -53785,6 +54364,8 @@ function useRoleControllerV2() {
|
|
|
53785
54364
|
usePatrolRouteRepo,
|
|
53786
54365
|
usePersonController,
|
|
53787
54366
|
usePersonRepo,
|
|
54367
|
+
usePostPrelovedController,
|
|
54368
|
+
usePostPrelovedRepo,
|
|
53788
54369
|
usePriceController,
|
|
53789
54370
|
usePriceModel,
|
|
53790
54371
|
usePriceRepo,
|