@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.mjs
CHANGED
|
@@ -12314,6 +12314,33 @@ function useServiceProviderRepo() {
|
|
|
12314
12314
|
throw error;
|
|
12315
12315
|
}
|
|
12316
12316
|
}
|
|
12317
|
+
async function updateStatusById(_id, status) {
|
|
12318
|
+
try {
|
|
12319
|
+
_id = new ObjectId34(_id);
|
|
12320
|
+
} catch (error) {
|
|
12321
|
+
throw new BadRequestError54("Invalid service provider ID format.");
|
|
12322
|
+
}
|
|
12323
|
+
try {
|
|
12324
|
+
const result = await collection.updateOne(
|
|
12325
|
+
{ _id },
|
|
12326
|
+
{ $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } }
|
|
12327
|
+
);
|
|
12328
|
+
if (!result.matchedCount) {
|
|
12329
|
+
throw new NotFoundError14("Service provider not found.");
|
|
12330
|
+
}
|
|
12331
|
+
delNamespace().then(() => {
|
|
12332
|
+
logger40.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
12333
|
+
}).catch((err) => {
|
|
12334
|
+
logger40.error(
|
|
12335
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
12336
|
+
err
|
|
12337
|
+
);
|
|
12338
|
+
});
|
|
12339
|
+
return result;
|
|
12340
|
+
} catch (error) {
|
|
12341
|
+
throw error;
|
|
12342
|
+
}
|
|
12343
|
+
}
|
|
12317
12344
|
return {
|
|
12318
12345
|
createTextIndex,
|
|
12319
12346
|
createUniqueIndex,
|
|
@@ -12323,7 +12350,8 @@ function useServiceProviderRepo() {
|
|
|
12323
12350
|
getServiceProviderTypes,
|
|
12324
12351
|
getServiceProviderById,
|
|
12325
12352
|
getByServiceProviderOrgIdType,
|
|
12326
|
-
getByEmail
|
|
12353
|
+
getByEmail,
|
|
12354
|
+
updateStatusById
|
|
12327
12355
|
};
|
|
12328
12356
|
}
|
|
12329
12357
|
|
|
@@ -13102,7 +13130,8 @@ function useServiceProviderController() {
|
|
|
13102
13130
|
getServiceProviderTypes: _getServiceProviderTypes,
|
|
13103
13131
|
getServiceProviderById: _getServiceProviderById,
|
|
13104
13132
|
getServiceProviders: _getServiceProviders,
|
|
13105
|
-
getByServiceProviderOrgIdType: _getByServiceProviderOrgIdType
|
|
13133
|
+
getByServiceProviderOrgIdType: _getByServiceProviderOrgIdType,
|
|
13134
|
+
updateStatusById: _updateStatusById
|
|
13106
13135
|
} = useServiceProviderRepo();
|
|
13107
13136
|
const { createServiceProvider: _createServiceProvider } = useServiceProviderService();
|
|
13108
13137
|
const { createServiceProvider: _add } = useServiceProviderRepo();
|
|
@@ -13316,6 +13345,30 @@ function useServiceProviderController() {
|
|
|
13316
13345
|
return;
|
|
13317
13346
|
}
|
|
13318
13347
|
}
|
|
13348
|
+
async function updateStatusById(req, res, next) {
|
|
13349
|
+
const validation = Joi31.object({
|
|
13350
|
+
id: Joi31.string().hex().required(),
|
|
13351
|
+
status: Joi31.string().valid("active", "inactive").required()
|
|
13352
|
+
});
|
|
13353
|
+
const { error, value } = validation.validate({
|
|
13354
|
+
id: req.params.id,
|
|
13355
|
+
status: req.body.status
|
|
13356
|
+
});
|
|
13357
|
+
if (error) {
|
|
13358
|
+
logger43.log({ level: "error", message: error.message });
|
|
13359
|
+
next(new BadRequestError60(error.message));
|
|
13360
|
+
return;
|
|
13361
|
+
}
|
|
13362
|
+
try {
|
|
13363
|
+
await _updateStatusById(value.id, value.status);
|
|
13364
|
+
res.json({ message: "Service provider status updated successfully." });
|
|
13365
|
+
return;
|
|
13366
|
+
} catch (error2) {
|
|
13367
|
+
logger43.log({ level: "error", message: error2.message });
|
|
13368
|
+
next(error2);
|
|
13369
|
+
return;
|
|
13370
|
+
}
|
|
13371
|
+
}
|
|
13319
13372
|
return {
|
|
13320
13373
|
createServiceProvider,
|
|
13321
13374
|
getServiceProviders,
|
|
@@ -13324,7 +13377,8 @@ function useServiceProviderController() {
|
|
|
13324
13377
|
getServiceProviderTypes,
|
|
13325
13378
|
getServiceProviderById,
|
|
13326
13379
|
getByServiceProviderOrgIdType,
|
|
13327
|
-
add
|
|
13380
|
+
add,
|
|
13381
|
+
updateStatusById
|
|
13328
13382
|
};
|
|
13329
13383
|
}
|
|
13330
13384
|
|
|
@@ -53708,6 +53762,523 @@ function useRoleControllerV2() {
|
|
|
53708
53762
|
createRole
|
|
53709
53763
|
};
|
|
53710
53764
|
}
|
|
53765
|
+
|
|
53766
|
+
// src/models/post-preloved.model.ts
|
|
53767
|
+
import Joi132 from "joi";
|
|
53768
|
+
import { ObjectId as ObjectId129 } from "mongodb";
|
|
53769
|
+
var PostStatus = /* @__PURE__ */ ((PostStatus2) => {
|
|
53770
|
+
PostStatus2["PUBLISHED"] = "published";
|
|
53771
|
+
PostStatus2["RESERVED"] = "reserved";
|
|
53772
|
+
PostStatus2["SOLD"] = "sold";
|
|
53773
|
+
PostStatus2["DELETED"] = "deleted";
|
|
53774
|
+
return PostStatus2;
|
|
53775
|
+
})(PostStatus || {});
|
|
53776
|
+
var PostSort = /* @__PURE__ */ ((PostSort2) => {
|
|
53777
|
+
PostSort2["CREATED_AT"] = "createdAt";
|
|
53778
|
+
PostSort2["TITLE"] = "title";
|
|
53779
|
+
PostSort2["PRICE"] = "price";
|
|
53780
|
+
PostSort2["ID"] = "_id";
|
|
53781
|
+
return PostSort2;
|
|
53782
|
+
})(PostSort || {});
|
|
53783
|
+
var PostOrder = /* @__PURE__ */ ((PostOrder2) => {
|
|
53784
|
+
PostOrder2["ASC"] = "asc";
|
|
53785
|
+
PostOrder2["DESC"] = "desc";
|
|
53786
|
+
return PostOrder2;
|
|
53787
|
+
})(PostOrder || {});
|
|
53788
|
+
var schemaPost = Joi132.object({
|
|
53789
|
+
_id: Joi132.string().hex().optional().allow("", null),
|
|
53790
|
+
title: Joi132.string().required(),
|
|
53791
|
+
description: Joi132.string().optional().allow("", null),
|
|
53792
|
+
attachments: Joi132.array().items(Joi132.string().hex().optional()).optional().allow(null),
|
|
53793
|
+
category: Joi132.array().items(Joi132.string().hex().optional()).optional().allow(null),
|
|
53794
|
+
currency: Joi132.string().optional().allow("", null),
|
|
53795
|
+
price: Joi132.number().required(),
|
|
53796
|
+
status: Joi132.string().valid(...Object.values(PostStatus)).optional().default("published" /* PUBLISHED */),
|
|
53797
|
+
reserverId: Joi132.string().hex().optional().allow("", null),
|
|
53798
|
+
createdBy: Joi132.string().hex().optional().allow("", null),
|
|
53799
|
+
site: Joi132.string().hex().optional().allow("", null),
|
|
53800
|
+
createdAt: Joi132.date().optional().allow(null),
|
|
53801
|
+
updatedAt: Joi132.date().optional().allow(null),
|
|
53802
|
+
deletedAt: Joi132.date().optional().allow(null)
|
|
53803
|
+
});
|
|
53804
|
+
var schemaUpdatePost = Joi132.object({
|
|
53805
|
+
_id: Joi132.string().hex().required(),
|
|
53806
|
+
title: Joi132.string().optional().allow("", null),
|
|
53807
|
+
description: Joi132.string().optional().allow("", null),
|
|
53808
|
+
attachments: Joi132.array().items(Joi132.string().hex().optional()).optional().allow(null),
|
|
53809
|
+
category: Joi132.array().items(Joi132.string().hex().optional()).optional().allow(null),
|
|
53810
|
+
currency: Joi132.string().optional().allow("", null),
|
|
53811
|
+
price: Joi132.number().optional(),
|
|
53812
|
+
status: Joi132.string().valid(...Object.values(PostStatus)).optional().allow(null),
|
|
53813
|
+
reserverId: Joi132.string().hex().optional().allow("", null)
|
|
53814
|
+
});
|
|
53815
|
+
function MPost(value) {
|
|
53816
|
+
const { error } = schemaPost.validate(value);
|
|
53817
|
+
if (error) {
|
|
53818
|
+
throw new Error(error.details[0].message);
|
|
53819
|
+
}
|
|
53820
|
+
if (value._id && typeof value._id === "string") {
|
|
53821
|
+
try {
|
|
53822
|
+
value._id = new ObjectId129(value._id);
|
|
53823
|
+
} catch {
|
|
53824
|
+
throw new Error("Invalid ID.");
|
|
53825
|
+
}
|
|
53826
|
+
}
|
|
53827
|
+
if (value.site && typeof value.site === "string") {
|
|
53828
|
+
try {
|
|
53829
|
+
value.site = new ObjectId129(value.site);
|
|
53830
|
+
} catch {
|
|
53831
|
+
throw new Error("Invalid site ID.");
|
|
53832
|
+
}
|
|
53833
|
+
}
|
|
53834
|
+
if (value.createdBy && typeof value.createdBy === "string") {
|
|
53835
|
+
try {
|
|
53836
|
+
value.createdBy = new ObjectId129(value.createdBy);
|
|
53837
|
+
} catch {
|
|
53838
|
+
throw new Error("Invalid createdBy ID.");
|
|
53839
|
+
}
|
|
53840
|
+
}
|
|
53841
|
+
if (value.reserverId && typeof value.reserverId === "string") {
|
|
53842
|
+
try {
|
|
53843
|
+
value.reserverId = new ObjectId129(value.reserverId);
|
|
53844
|
+
} catch {
|
|
53845
|
+
throw new Error("Invalid reserver ID.");
|
|
53846
|
+
}
|
|
53847
|
+
}
|
|
53848
|
+
if (value.attachments && Array.isArray(value.attachments)) {
|
|
53849
|
+
value.attachments = value.attachments.map((id) => {
|
|
53850
|
+
if (typeof id === "string") {
|
|
53851
|
+
try {
|
|
53852
|
+
return new ObjectId129(id);
|
|
53853
|
+
} catch {
|
|
53854
|
+
throw new Error("Invalid attachment ID.");
|
|
53855
|
+
}
|
|
53856
|
+
}
|
|
53857
|
+
return id;
|
|
53858
|
+
});
|
|
53859
|
+
}
|
|
53860
|
+
if (value.category && Array.isArray(value.category)) {
|
|
53861
|
+
value.category = value.category.map((id) => {
|
|
53862
|
+
if (typeof id === "string") {
|
|
53863
|
+
try {
|
|
53864
|
+
return new ObjectId129(id);
|
|
53865
|
+
} catch {
|
|
53866
|
+
throw new Error("Invalid category ID.");
|
|
53867
|
+
}
|
|
53868
|
+
}
|
|
53869
|
+
return id;
|
|
53870
|
+
});
|
|
53871
|
+
}
|
|
53872
|
+
return {
|
|
53873
|
+
_id: value._id ?? new ObjectId129(),
|
|
53874
|
+
title: value.title ?? "",
|
|
53875
|
+
description: value.description ?? "",
|
|
53876
|
+
attachments: value.attachments ?? [],
|
|
53877
|
+
category: value.category ?? [],
|
|
53878
|
+
currency: value.currency ?? "",
|
|
53879
|
+
price: value.price ?? 0,
|
|
53880
|
+
status: value.status ?? "published" /* PUBLISHED */,
|
|
53881
|
+
reserverId: value.reserverId ?? null,
|
|
53882
|
+
createdBy: value.createdBy ?? "",
|
|
53883
|
+
site: value.site ?? "",
|
|
53884
|
+
createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
53885
|
+
updatedAt: value.updatedAt ?? null,
|
|
53886
|
+
deletedAt: value.deletedAt ?? null
|
|
53887
|
+
};
|
|
53888
|
+
}
|
|
53889
|
+
|
|
53890
|
+
// src/repositories/post-preloved.repo.ts
|
|
53891
|
+
import {
|
|
53892
|
+
BadRequestError as BadRequestError210,
|
|
53893
|
+
InternalServerError as InternalServerError74,
|
|
53894
|
+
NotFoundError as NotFoundError57,
|
|
53895
|
+
paginate as paginate59,
|
|
53896
|
+
useAtlas as useAtlas117
|
|
53897
|
+
} from "@7365admin1/node-server-utils";
|
|
53898
|
+
import { ObjectId as ObjectId130 } from "mongodb";
|
|
53899
|
+
function usePostPrelovedRepo() {
|
|
53900
|
+
const db = useAtlas117.getDb();
|
|
53901
|
+
if (!db) {
|
|
53902
|
+
throw new InternalServerError74("Unable to connect to server.");
|
|
53903
|
+
}
|
|
53904
|
+
const POST_COLLECTION = "post-preloved";
|
|
53905
|
+
const USER_LOOKUP = {
|
|
53906
|
+
$lookup: {
|
|
53907
|
+
from: "users",
|
|
53908
|
+
localField: "createdBy",
|
|
53909
|
+
foreignField: "_id",
|
|
53910
|
+
pipeline: [
|
|
53911
|
+
{
|
|
53912
|
+
$project: {
|
|
53913
|
+
name: 1,
|
|
53914
|
+
profile: 1
|
|
53915
|
+
}
|
|
53916
|
+
}
|
|
53917
|
+
],
|
|
53918
|
+
as: "createdBy"
|
|
53919
|
+
}
|
|
53920
|
+
};
|
|
53921
|
+
const USER_UNWIND = {
|
|
53922
|
+
$unwind: {
|
|
53923
|
+
path: "$createdBy",
|
|
53924
|
+
preserveNullAndEmptyArrays: true
|
|
53925
|
+
}
|
|
53926
|
+
};
|
|
53927
|
+
const CATEGORY_LOOKUP = {
|
|
53928
|
+
$lookup: {
|
|
53929
|
+
from: "category-preloved",
|
|
53930
|
+
localField: "category",
|
|
53931
|
+
foreignField: "_id",
|
|
53932
|
+
as: "categories"
|
|
53933
|
+
}
|
|
53934
|
+
};
|
|
53935
|
+
const collection = db.collection(POST_COLLECTION);
|
|
53936
|
+
function buildSortObj(filter) {
|
|
53937
|
+
switch (filter) {
|
|
53938
|
+
case "price-low-high":
|
|
53939
|
+
return { price: 1 };
|
|
53940
|
+
case "price-high-low":
|
|
53941
|
+
return { price: -1 };
|
|
53942
|
+
case "recent":
|
|
53943
|
+
default:
|
|
53944
|
+
return { createdAt: -1 };
|
|
53945
|
+
}
|
|
53946
|
+
}
|
|
53947
|
+
async function add(value, session) {
|
|
53948
|
+
try {
|
|
53949
|
+
const doc = MPost(value);
|
|
53950
|
+
const res = await collection.insertOne(doc, { session });
|
|
53951
|
+
return res.insertedId;
|
|
53952
|
+
} catch (error) {
|
|
53953
|
+
const isDuplicated = error.message?.includes("duplicate");
|
|
53954
|
+
if (isDuplicated)
|
|
53955
|
+
throw new BadRequestError210("Post already exists.");
|
|
53956
|
+
throw error;
|
|
53957
|
+
}
|
|
53958
|
+
}
|
|
53959
|
+
async function getById(_id) {
|
|
53960
|
+
try {
|
|
53961
|
+
_id = new ObjectId130(_id);
|
|
53962
|
+
} catch {
|
|
53963
|
+
throw new BadRequestError210("Invalid post ID format.");
|
|
53964
|
+
}
|
|
53965
|
+
try {
|
|
53966
|
+
const result = await collection.aggregate([
|
|
53967
|
+
{ $match: { _id, status: { $ne: "deleted" /* DELETED */ } } },
|
|
53968
|
+
USER_LOOKUP,
|
|
53969
|
+
USER_UNWIND,
|
|
53970
|
+
CATEGORY_LOOKUP
|
|
53971
|
+
]).toArray();
|
|
53972
|
+
const data = result[0] ?? null;
|
|
53973
|
+
if (!data)
|
|
53974
|
+
throw new NotFoundError57("Post not found.");
|
|
53975
|
+
return data;
|
|
53976
|
+
} catch (error) {
|
|
53977
|
+
throw error;
|
|
53978
|
+
}
|
|
53979
|
+
}
|
|
53980
|
+
async function getAll({
|
|
53981
|
+
search = "",
|
|
53982
|
+
page = 1,
|
|
53983
|
+
limit = 10,
|
|
53984
|
+
filter,
|
|
53985
|
+
site,
|
|
53986
|
+
status,
|
|
53987
|
+
category
|
|
53988
|
+
}, session) {
|
|
53989
|
+
page = page > 0 ? page - 1 : 0;
|
|
53990
|
+
if (site) {
|
|
53991
|
+
try {
|
|
53992
|
+
site = new ObjectId130(site);
|
|
53993
|
+
} catch {
|
|
53994
|
+
throw new BadRequestError210("Invalid site ID format.");
|
|
53995
|
+
}
|
|
53996
|
+
}
|
|
53997
|
+
const categoryIds = category && Array.isArray(category) && category.length > 0 ? category.map((id) => {
|
|
53998
|
+
try {
|
|
53999
|
+
return new ObjectId130(id);
|
|
54000
|
+
} catch {
|
|
54001
|
+
throw new BadRequestError210("Invalid category ID format.");
|
|
54002
|
+
}
|
|
54003
|
+
}) : null;
|
|
54004
|
+
const query = {
|
|
54005
|
+
status: { $ne: "deleted" /* DELETED */ },
|
|
54006
|
+
...site && { site },
|
|
54007
|
+
...search && {
|
|
54008
|
+
$or: [
|
|
54009
|
+
{ title: { $regex: search, $options: "i" } },
|
|
54010
|
+
{ description: { $regex: search, $options: "i" } }
|
|
54011
|
+
]
|
|
54012
|
+
},
|
|
54013
|
+
...status && {
|
|
54014
|
+
status: { $in: Array.isArray(status) ? status : [status] }
|
|
54015
|
+
},
|
|
54016
|
+
...categoryIds && { category: { $in: categoryIds } }
|
|
54017
|
+
};
|
|
54018
|
+
const sortObj = buildSortObj(filter);
|
|
54019
|
+
try {
|
|
54020
|
+
const items = await collection.aggregate(
|
|
54021
|
+
[
|
|
54022
|
+
{ $match: query },
|
|
54023
|
+
USER_LOOKUP,
|
|
54024
|
+
USER_UNWIND,
|
|
54025
|
+
CATEGORY_LOOKUP,
|
|
54026
|
+
{ $sort: sortObj },
|
|
54027
|
+
{ $skip: page * limit },
|
|
54028
|
+
{ $limit: limit }
|
|
54029
|
+
],
|
|
54030
|
+
{ session }
|
|
54031
|
+
).toArray();
|
|
54032
|
+
const length = await collection.countDocuments(query, { session });
|
|
54033
|
+
return paginate59(items, page, limit, length);
|
|
54034
|
+
} catch (error) {
|
|
54035
|
+
throw error;
|
|
54036
|
+
}
|
|
54037
|
+
}
|
|
54038
|
+
async function updateById(_id, value, session) {
|
|
54039
|
+
try {
|
|
54040
|
+
_id = new ObjectId130(_id);
|
|
54041
|
+
} catch {
|
|
54042
|
+
throw new BadRequestError210("Invalid post ID format.");
|
|
54043
|
+
}
|
|
54044
|
+
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
54045
|
+
try {
|
|
54046
|
+
const res = await collection.updateOne(
|
|
54047
|
+
{ _id },
|
|
54048
|
+
{ $set: value },
|
|
54049
|
+
{ session }
|
|
54050
|
+
);
|
|
54051
|
+
if (res.modifiedCount === 0) {
|
|
54052
|
+
throw new InternalServerError74("Unable to update post.");
|
|
54053
|
+
}
|
|
54054
|
+
return res;
|
|
54055
|
+
} catch (error) {
|
|
54056
|
+
throw error;
|
|
54057
|
+
}
|
|
54058
|
+
}
|
|
54059
|
+
async function deleteById(_id, session) {
|
|
54060
|
+
try {
|
|
54061
|
+
_id = new ObjectId130(_id);
|
|
54062
|
+
} catch {
|
|
54063
|
+
throw new BadRequestError210("Invalid post ID format.");
|
|
54064
|
+
}
|
|
54065
|
+
try {
|
|
54066
|
+
const res = await collection.updateOne(
|
|
54067
|
+
{ _id },
|
|
54068
|
+
{
|
|
54069
|
+
$set: {
|
|
54070
|
+
status: "deleted" /* DELETED */,
|
|
54071
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
54072
|
+
deletedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
54073
|
+
}
|
|
54074
|
+
},
|
|
54075
|
+
{ session }
|
|
54076
|
+
);
|
|
54077
|
+
if (res.modifiedCount === 0) {
|
|
54078
|
+
throw new InternalServerError74("Unable to delete post.");
|
|
54079
|
+
}
|
|
54080
|
+
return res.modifiedCount;
|
|
54081
|
+
} catch (error) {
|
|
54082
|
+
throw error;
|
|
54083
|
+
}
|
|
54084
|
+
}
|
|
54085
|
+
async function updateStatus(_id, status, session) {
|
|
54086
|
+
try {
|
|
54087
|
+
_id = new ObjectId130(_id);
|
|
54088
|
+
} catch {
|
|
54089
|
+
throw new BadRequestError210("Invalid post ID format.");
|
|
54090
|
+
}
|
|
54091
|
+
try {
|
|
54092
|
+
const res = await collection.updateOne(
|
|
54093
|
+
{ _id },
|
|
54094
|
+
{ $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
54095
|
+
{ session }
|
|
54096
|
+
);
|
|
54097
|
+
if (res.modifiedCount === 0)
|
|
54098
|
+
throw new InternalServerError74("Unable to update post status.");
|
|
54099
|
+
return res;
|
|
54100
|
+
} catch (error) {
|
|
54101
|
+
throw error;
|
|
54102
|
+
}
|
|
54103
|
+
}
|
|
54104
|
+
return {
|
|
54105
|
+
add,
|
|
54106
|
+
getById,
|
|
54107
|
+
getAll,
|
|
54108
|
+
updateById,
|
|
54109
|
+
deleteById,
|
|
54110
|
+
updateStatus
|
|
54111
|
+
};
|
|
54112
|
+
}
|
|
54113
|
+
|
|
54114
|
+
// src/controllers/post-preloved.controller.ts
|
|
54115
|
+
import { BadRequestError as BadRequestError211, logger as logger186 } from "@7365admin1/node-server-utils";
|
|
54116
|
+
import Joi133 from "joi";
|
|
54117
|
+
function usePostPrelovedController() {
|
|
54118
|
+
const {
|
|
54119
|
+
add: _add,
|
|
54120
|
+
getById: _getById,
|
|
54121
|
+
getAll: _getAll,
|
|
54122
|
+
updateById: _updateById,
|
|
54123
|
+
deleteById: _deleteById,
|
|
54124
|
+
updateStatus: _updateStatus
|
|
54125
|
+
} = usePostPrelovedRepo();
|
|
54126
|
+
async function add(req, res, next) {
|
|
54127
|
+
const { error, value } = schemaPost.validate(req.body, {
|
|
54128
|
+
abortEarly: false
|
|
54129
|
+
});
|
|
54130
|
+
if (error) {
|
|
54131
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
54132
|
+
logger186.log({ level: "error", message: messages });
|
|
54133
|
+
next(new BadRequestError211(messages));
|
|
54134
|
+
return;
|
|
54135
|
+
}
|
|
54136
|
+
try {
|
|
54137
|
+
const data = await _add(value);
|
|
54138
|
+
res.status(201).json(data);
|
|
54139
|
+
return;
|
|
54140
|
+
} catch (error2) {
|
|
54141
|
+
logger186.log({ level: "error", message: error2.message });
|
|
54142
|
+
next(error2);
|
|
54143
|
+
return;
|
|
54144
|
+
}
|
|
54145
|
+
}
|
|
54146
|
+
async function getById(req, res, next) {
|
|
54147
|
+
const schema2 = Joi133.object({
|
|
54148
|
+
_id: Joi133.string().hex().length(24).required()
|
|
54149
|
+
});
|
|
54150
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
54151
|
+
if (error) {
|
|
54152
|
+
logger186.log({ level: "error", message: error.message });
|
|
54153
|
+
next(new BadRequestError211(error.message));
|
|
54154
|
+
return;
|
|
54155
|
+
}
|
|
54156
|
+
try {
|
|
54157
|
+
const data = await _getById(value._id);
|
|
54158
|
+
res.status(200).json(data);
|
|
54159
|
+
return;
|
|
54160
|
+
} catch (error2) {
|
|
54161
|
+
logger186.log({ level: "error", message: error2.message });
|
|
54162
|
+
next(error2);
|
|
54163
|
+
return;
|
|
54164
|
+
}
|
|
54165
|
+
}
|
|
54166
|
+
async function getAll(req, res, next) {
|
|
54167
|
+
const validation = Joi133.object({
|
|
54168
|
+
page: Joi133.number().integer().min(1).allow("", null).default(1),
|
|
54169
|
+
limit: Joi133.number().integer().min(1).max(100).allow("", null).default(10),
|
|
54170
|
+
search: Joi133.string().optional().allow("", null),
|
|
54171
|
+
filter: Joi133.string().valid("recent", "price-low-high", "price-high-low").optional().allow("", null),
|
|
54172
|
+
site: Joi133.string().hex().length(24).optional().allow("", null),
|
|
54173
|
+
status: Joi133.alternatives().try(
|
|
54174
|
+
Joi133.array().items(Joi133.string().valid(...Object.values(PostStatus))),
|
|
54175
|
+
Joi133.string().valid(...Object.values(PostStatus))
|
|
54176
|
+
).optional().allow(null),
|
|
54177
|
+
category: Joi133.alternatives().try(Joi133.array().items(Joi133.string().hex()), Joi133.string().hex()).optional().allow(null)
|
|
54178
|
+
});
|
|
54179
|
+
const { error, value } = validation.validate(req.query, {
|
|
54180
|
+
abortEarly: false
|
|
54181
|
+
});
|
|
54182
|
+
if (error) {
|
|
54183
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
54184
|
+
logger186.log({ level: "error", message: messages });
|
|
54185
|
+
next(new BadRequestError211(messages));
|
|
54186
|
+
return;
|
|
54187
|
+
}
|
|
54188
|
+
const { page, limit, search, filter, site, status, category } = value;
|
|
54189
|
+
try {
|
|
54190
|
+
const data = await _getAll({
|
|
54191
|
+
page,
|
|
54192
|
+
limit,
|
|
54193
|
+
search,
|
|
54194
|
+
filter,
|
|
54195
|
+
site,
|
|
54196
|
+
status: status ? Array.isArray(status) ? status : [status] : void 0,
|
|
54197
|
+
category: category ? Array.isArray(category) ? category : [category] : void 0
|
|
54198
|
+
});
|
|
54199
|
+
res.status(200).json(data);
|
|
54200
|
+
return;
|
|
54201
|
+
} catch (error2) {
|
|
54202
|
+
logger186.log({ level: "error", message: error2.message });
|
|
54203
|
+
next(error2);
|
|
54204
|
+
return;
|
|
54205
|
+
}
|
|
54206
|
+
}
|
|
54207
|
+
async function updateById(req, res, next) {
|
|
54208
|
+
const _id = req.params.id;
|
|
54209
|
+
const payload = { _id, ...req.body };
|
|
54210
|
+
const { error } = schemaUpdatePost.validate(payload, {
|
|
54211
|
+
abortEarly: false
|
|
54212
|
+
});
|
|
54213
|
+
if (error) {
|
|
54214
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
54215
|
+
logger186.log({ level: "error", message: messages });
|
|
54216
|
+
next(new BadRequestError211(messages));
|
|
54217
|
+
return;
|
|
54218
|
+
}
|
|
54219
|
+
try {
|
|
54220
|
+
const data = await _updateById(_id, req.body);
|
|
54221
|
+
res.status(200).json(data);
|
|
54222
|
+
return;
|
|
54223
|
+
} catch (error2) {
|
|
54224
|
+
logger186.log({ level: "error", message: error2.message });
|
|
54225
|
+
next(error2);
|
|
54226
|
+
return;
|
|
54227
|
+
}
|
|
54228
|
+
}
|
|
54229
|
+
async function deleteById(req, res, next) {
|
|
54230
|
+
const schema2 = Joi133.object({
|
|
54231
|
+
_id: Joi133.string().hex().length(24).required()
|
|
54232
|
+
});
|
|
54233
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
54234
|
+
if (error) {
|
|
54235
|
+
logger186.log({ level: "error", message: error.message });
|
|
54236
|
+
next(new BadRequestError211(error.message));
|
|
54237
|
+
return;
|
|
54238
|
+
}
|
|
54239
|
+
try {
|
|
54240
|
+
const data = await _deleteById(value._id);
|
|
54241
|
+
res.status(200).json({ message: "Successfully deleted post." });
|
|
54242
|
+
return;
|
|
54243
|
+
} catch (error2) {
|
|
54244
|
+
logger186.log({ level: "error", message: error2.message });
|
|
54245
|
+
next(error2);
|
|
54246
|
+
return;
|
|
54247
|
+
}
|
|
54248
|
+
}
|
|
54249
|
+
async function updateStatus(req, res, next) {
|
|
54250
|
+
const schema2 = Joi133.object({
|
|
54251
|
+
_id: Joi133.string().hex().length(24).required(),
|
|
54252
|
+
status: Joi133.string().valid(...Object.values(PostStatus)).required()
|
|
54253
|
+
});
|
|
54254
|
+
const { error, value } = schema2.validate({
|
|
54255
|
+
_id: req.params.id,
|
|
54256
|
+
status: req.body.status
|
|
54257
|
+
});
|
|
54258
|
+
if (error) {
|
|
54259
|
+
logger186.log({ level: "error", message: error.message });
|
|
54260
|
+
next(new BadRequestError211(error.message));
|
|
54261
|
+
return;
|
|
54262
|
+
}
|
|
54263
|
+
try {
|
|
54264
|
+
const data = await _updateStatus(value._id, value.status);
|
|
54265
|
+
res.status(200).json(data);
|
|
54266
|
+
return;
|
|
54267
|
+
} catch (error2) {
|
|
54268
|
+
logger186.log({ level: "error", message: error2.message });
|
|
54269
|
+
next(error2);
|
|
54270
|
+
return;
|
|
54271
|
+
}
|
|
54272
|
+
}
|
|
54273
|
+
return {
|
|
54274
|
+
add,
|
|
54275
|
+
getById,
|
|
54276
|
+
getAll,
|
|
54277
|
+
updateById,
|
|
54278
|
+
deleteById,
|
|
54279
|
+
updateStatus
|
|
54280
|
+
};
|
|
54281
|
+
}
|
|
53711
54282
|
export {
|
|
53712
54283
|
ANPRMode,
|
|
53713
54284
|
AccessTypeProps,
|
|
@@ -53778,6 +54349,7 @@ export {
|
|
|
53778
54349
|
MPatrolQuestion,
|
|
53779
54350
|
MPatrolRoute,
|
|
53780
54351
|
MPerson,
|
|
54352
|
+
MPost,
|
|
53781
54353
|
MPromoCode,
|
|
53782
54354
|
MRobot,
|
|
53783
54355
|
MRole,
|
|
@@ -53808,6 +54380,9 @@ export {
|
|
|
53808
54380
|
Period,
|
|
53809
54381
|
PersonStatus,
|
|
53810
54382
|
PersonTypes,
|
|
54383
|
+
PostOrder,
|
|
54384
|
+
PostSort,
|
|
54385
|
+
PostStatus,
|
|
53811
54386
|
SiteCategories,
|
|
53812
54387
|
SiteStatus,
|
|
53813
54388
|
SortFields,
|
|
@@ -53903,6 +54478,7 @@ export {
|
|
|
53903
54478
|
schemaPatrolRoute,
|
|
53904
54479
|
schemaPerson,
|
|
53905
54480
|
schemaPlate,
|
|
54481
|
+
schemaPost,
|
|
53906
54482
|
schemaServiceProvider,
|
|
53907
54483
|
schemaServiceProviderBilling,
|
|
53908
54484
|
schemaSiteCamera,
|
|
@@ -53927,6 +54503,7 @@ export {
|
|
|
53927
54503
|
schemaUpdatePatrolQuestion,
|
|
53928
54504
|
schemaUpdatePatrolRoute,
|
|
53929
54505
|
schemaUpdatePerson,
|
|
54506
|
+
schemaUpdatePost,
|
|
53930
54507
|
schemaUpdateServiceProviderBilling,
|
|
53931
54508
|
schemaUpdateSiteBillingConfiguration,
|
|
53932
54509
|
schemaUpdateSiteBillingItem,
|
|
@@ -54061,6 +54638,8 @@ export {
|
|
|
54061
54638
|
usePatrolRouteRepo,
|
|
54062
54639
|
usePersonController,
|
|
54063
54640
|
usePersonRepo,
|
|
54641
|
+
usePostPrelovedController,
|
|
54642
|
+
usePostPrelovedRepo,
|
|
54064
54643
|
usePriceController,
|
|
54065
54644
|
usePriceModel,
|
|
54066
54645
|
usePriceRepo,
|