@goweekdays/core 1.2.4 → 1.3.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 +9 -2
- package/dist/index.js +103 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +104 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -25752,6 +25752,27 @@ function usePriceController() {
|
|
|
25752
25752
|
import { BadRequestError as BadRequestError51 } from "@goweekdays/utils";
|
|
25753
25753
|
import Joi28 from "joi";
|
|
25754
25754
|
import { ObjectId as ObjectId34 } from "mongodb";
|
|
25755
|
+
var schemaPropertyUpdate = Joi28.object({
|
|
25756
|
+
propertyName: Joi28.string().trim().required(),
|
|
25757
|
+
propertyType: Joi28.string().trim().required(),
|
|
25758
|
+
propertyDescription: Joi28.string().trim().required(),
|
|
25759
|
+
streetAddress: Joi28.string().trim().required(),
|
|
25760
|
+
barangay: Joi28.string().trim().required(),
|
|
25761
|
+
city: Joi28.string().trim().required(),
|
|
25762
|
+
province: Joi28.string().trim().required(),
|
|
25763
|
+
region: Joi28.string().trim().required(),
|
|
25764
|
+
zipCode: Joi28.string().trim().optional().allow(""),
|
|
25765
|
+
latitude: Joi28.string().trim().optional().allow(""),
|
|
25766
|
+
longitude: Joi28.string().trim().optional().allow(""),
|
|
25767
|
+
ownerId: Joi28.string().trim().optional().allow(""),
|
|
25768
|
+
managerName: Joi28.string().trim().optional().allow(""),
|
|
25769
|
+
managerEmail: Joi28.string().trim().email().optional().allow(""),
|
|
25770
|
+
managerPhone: Joi28.string().trim().optional().allow(""),
|
|
25771
|
+
amenities: Joi28.array().items(Joi28.string().trim()).optional(),
|
|
25772
|
+
numberOfFloors: Joi28.string().trim().required(),
|
|
25773
|
+
floorLabels: Joi28.string().optional().allow(""),
|
|
25774
|
+
stayType: Joi28.string().trim().required()
|
|
25775
|
+
});
|
|
25755
25776
|
var schemaProperty = Joi28.object({
|
|
25756
25777
|
_id: Joi28.string().optional(),
|
|
25757
25778
|
propertyName: Joi28.string().trim().required(),
|
|
@@ -25772,20 +25793,8 @@ var schemaProperty = Joi28.object({
|
|
|
25772
25793
|
amenities: Joi28.array().items(Joi28.string().trim()).optional(),
|
|
25773
25794
|
numberOfFloors: Joi28.string().trim().required(),
|
|
25774
25795
|
floorLabels: Joi28.string().optional().allow(""),
|
|
25775
|
-
coverPhoto: Joi28.object({
|
|
25776
|
-
|
|
25777
|
-
size: Joi28.string().trim().optional().allow(""),
|
|
25778
|
-
type: Joi28.string().trim().optional().allow(""),
|
|
25779
|
-
webkitRelativePath: Joi28.string().trim().optional().allow("")
|
|
25780
|
-
}),
|
|
25781
|
-
photoGallery: Joi28.array().items(
|
|
25782
|
-
Joi28.object({
|
|
25783
|
-
name: Joi28.string().trim().optional().allow(""),
|
|
25784
|
-
size: Joi28.string().trim().optional().allow(""),
|
|
25785
|
-
type: Joi28.string().trim().optional().allow(""),
|
|
25786
|
-
webkitRelativePath: Joi28.string().trim().optional().allow("")
|
|
25787
|
-
})
|
|
25788
|
-
).required(),
|
|
25796
|
+
coverPhoto: Joi28.object({}),
|
|
25797
|
+
photoGallery: Joi28.array().items(Joi28.object({})),
|
|
25789
25798
|
stayType: Joi28.string().trim().required(),
|
|
25790
25799
|
createdAt: Joi28.date().optional(),
|
|
25791
25800
|
updatedAt: Joi28.date().optional(),
|
|
@@ -25839,7 +25848,8 @@ import {
|
|
|
25839
25848
|
useCache as useCache18,
|
|
25840
25849
|
makeCacheKey as makeCacheKey17,
|
|
25841
25850
|
logger as logger26,
|
|
25842
|
-
InternalServerError as InternalServerError24
|
|
25851
|
+
InternalServerError as InternalServerError24,
|
|
25852
|
+
paginate as paginate12
|
|
25843
25853
|
} from "@goweekdays/utils";
|
|
25844
25854
|
import { ObjectId as ObjectId35 } from "mongodb";
|
|
25845
25855
|
function usePropertyRepo() {
|
|
@@ -25897,18 +25907,25 @@ function usePropertyRepo() {
|
|
|
25897
25907
|
async function updateById(_id, value, session) {
|
|
25898
25908
|
try {
|
|
25899
25909
|
_id = new ObjectId35(_id);
|
|
25900
|
-
} catch (
|
|
25910
|
+
} catch (error2) {
|
|
25901
25911
|
throw new BadRequestError52("Invalid ID.");
|
|
25902
25912
|
}
|
|
25913
|
+
const { error } = schemaPropertyUpdate.validate(value);
|
|
25914
|
+
if (error) {
|
|
25915
|
+
throw new BadRequestError52(
|
|
25916
|
+
`Invalid property data: ${error.message}. Repository validation.`
|
|
25917
|
+
);
|
|
25918
|
+
}
|
|
25903
25919
|
try {
|
|
25920
|
+
value.updatedAt = /* @__PURE__ */ new Date();
|
|
25904
25921
|
const res = await collection.updateOne(
|
|
25905
25922
|
{ _id },
|
|
25906
|
-
{ $set:
|
|
25923
|
+
{ $set: value },
|
|
25907
25924
|
{ session }
|
|
25908
25925
|
);
|
|
25909
25926
|
delCachedData();
|
|
25910
25927
|
return res;
|
|
25911
|
-
} catch (
|
|
25928
|
+
} catch (error2) {
|
|
25912
25929
|
throw new InternalServerError24("Failed to update property.");
|
|
25913
25930
|
}
|
|
25914
25931
|
}
|
|
@@ -25926,8 +25943,25 @@ function usePropertyRepo() {
|
|
|
25926
25943
|
throw new InternalServerError24("Failed to delete property.");
|
|
25927
25944
|
}
|
|
25928
25945
|
}
|
|
25929
|
-
async function getAll(
|
|
25930
|
-
|
|
25946
|
+
async function getAll({
|
|
25947
|
+
page = 1,
|
|
25948
|
+
limit = 20,
|
|
25949
|
+
status = "active",
|
|
25950
|
+
search = ""
|
|
25951
|
+
} = {}) {
|
|
25952
|
+
page = page > 0 ? page - 1 : 0;
|
|
25953
|
+
const query = { status };
|
|
25954
|
+
const cacheKeyOptions = {
|
|
25955
|
+
action: "getAll",
|
|
25956
|
+
page,
|
|
25957
|
+
limit,
|
|
25958
|
+
status
|
|
25959
|
+
};
|
|
25960
|
+
if (search) {
|
|
25961
|
+
query.$text = { $search: search };
|
|
25962
|
+
cacheKeyOptions.search = search;
|
|
25963
|
+
}
|
|
25964
|
+
const cacheKey = makeCacheKey17(namespace_collection, cacheKeyOptions);
|
|
25931
25965
|
try {
|
|
25932
25966
|
const cached = await getCache(cacheKey);
|
|
25933
25967
|
if (cached) {
|
|
@@ -25937,8 +25971,14 @@ function usePropertyRepo() {
|
|
|
25937
25971
|
});
|
|
25938
25972
|
return cached;
|
|
25939
25973
|
}
|
|
25940
|
-
const
|
|
25941
|
-
|
|
25974
|
+
const items = await collection.aggregate([
|
|
25975
|
+
{ $match: query },
|
|
25976
|
+
{ $skip: page * limit },
|
|
25977
|
+
{ $limit: limit }
|
|
25978
|
+
]).toArray();
|
|
25979
|
+
const length = await collection.countDocuments(query);
|
|
25980
|
+
const data = paginate12(items, page, limit, length);
|
|
25981
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
25942
25982
|
logger26.log({
|
|
25943
25983
|
level: "info",
|
|
25944
25984
|
message: `Cache set for getAll: ${cacheKey}`
|
|
@@ -25949,7 +25989,7 @@ function usePropertyRepo() {
|
|
|
25949
25989
|
message: `Failed to set cache: ${err.message}`
|
|
25950
25990
|
});
|
|
25951
25991
|
});
|
|
25952
|
-
return
|
|
25992
|
+
return data;
|
|
25953
25993
|
} catch (error) {
|
|
25954
25994
|
throw new InternalServerError24(
|
|
25955
25995
|
`Failed to fetch properties: ${error.message}`
|
|
@@ -26015,7 +26055,8 @@ function usePropertyController() {
|
|
|
26015
26055
|
add: _add,
|
|
26016
26056
|
updateById: _updateById,
|
|
26017
26057
|
getAll: _getAll,
|
|
26018
|
-
getById: _getById
|
|
26058
|
+
getById: _getById,
|
|
26059
|
+
deleteById: _deleteById
|
|
26019
26060
|
} = usePropertyRepo();
|
|
26020
26061
|
async function add(req, res, next) {
|
|
26021
26062
|
const value = req.body;
|
|
@@ -26034,32 +26075,15 @@ function usePropertyController() {
|
|
|
26034
26075
|
}
|
|
26035
26076
|
async function updateById(req, res, next) {
|
|
26036
26077
|
const _id = req.params.id ?? "";
|
|
26037
|
-
const
|
|
26038
|
-
|
|
26039
|
-
_id: Joi29.string().required(),
|
|
26040
|
-
name: Joi29.string().trim().required(),
|
|
26041
|
-
type: Joi29.string().trim().required(),
|
|
26042
|
-
description: Joi29.string().trim().required(),
|
|
26043
|
-
street: Joi29.string().trim().required(),
|
|
26044
|
-
barangay: Joi29.string().trim().required(),
|
|
26045
|
-
cityMunicipality: Joi29.string().trim().required(),
|
|
26046
|
-
province: Joi29.string().trim().required(),
|
|
26047
|
-
region: Joi29.string().trim().required(),
|
|
26048
|
-
zipCode: Joi29.string().trim().optional().allow(""),
|
|
26049
|
-
latitude: Joi29.string().trim().optional().allow(""),
|
|
26050
|
-
longitude: Joi29.string().trim().optional().allow(""),
|
|
26051
|
-
ownerId: Joi29.string().trim().optional().allow(""),
|
|
26052
|
-
ownerName: Joi29.string().trim().optional().allow(""),
|
|
26053
|
-
email: Joi29.string().trim().email().optional().allow(""),
|
|
26054
|
-
phone: Joi29.string().trim().optional().allow(""),
|
|
26055
|
-
amenities: Joi29.array().items(Joi29.string().trim()).optional(),
|
|
26056
|
-
floorNumber: Joi29.string().trim().required(),
|
|
26057
|
-
floorLabel: Joi29.string().optional().allow(""),
|
|
26058
|
-
coverPhoto: Joi29.string().trim().required(),
|
|
26059
|
-
photoGallery: Joi29.array().items(Joi29.string().trim()).required(),
|
|
26060
|
-
stayType: Joi29.string().trim().required()
|
|
26078
|
+
const idValidation = Joi29.object({
|
|
26079
|
+
_id: Joi29.string().required()
|
|
26061
26080
|
});
|
|
26062
|
-
const { error } =
|
|
26081
|
+
const { error: idValidationError } = idValidation.validate({ _id });
|
|
26082
|
+
if (idValidationError) {
|
|
26083
|
+
throw new BadRequestError53(`Invalid ID`);
|
|
26084
|
+
}
|
|
26085
|
+
const value = req.body;
|
|
26086
|
+
const { error } = schemaPropertyUpdate.validate(value);
|
|
26063
26087
|
if (error) {
|
|
26064
26088
|
throw new BadRequestError53(`Invalid property data: ${error.message}`);
|
|
26065
26089
|
}
|
|
@@ -26071,12 +26095,23 @@ function usePropertyController() {
|
|
|
26071
26095
|
}
|
|
26072
26096
|
}
|
|
26073
26097
|
async function getAll(req, res, next) {
|
|
26098
|
+
const validation = Joi29.object({
|
|
26099
|
+
page: Joi29.number().integer().min(1).default(1),
|
|
26100
|
+
limit: Joi29.number().integer().min(1).max(100).default(10),
|
|
26101
|
+
search: Joi29.string().trim().allow("").default(""),
|
|
26102
|
+
status: Joi29.string().default("active")
|
|
26103
|
+
});
|
|
26104
|
+
const { error, value } = validation.validate(req.query);
|
|
26105
|
+
if (error) {
|
|
26106
|
+
next(new BadRequestError53(error.message));
|
|
26107
|
+
return;
|
|
26108
|
+
}
|
|
26074
26109
|
try {
|
|
26075
|
-
const properties = await _getAll();
|
|
26110
|
+
const properties = await _getAll(value);
|
|
26076
26111
|
res.json(properties);
|
|
26077
26112
|
return;
|
|
26078
|
-
} catch (
|
|
26079
|
-
next(
|
|
26113
|
+
} catch (error2) {
|
|
26114
|
+
next(error2);
|
|
26080
26115
|
}
|
|
26081
26116
|
}
|
|
26082
26117
|
async function getById(req, res, next) {
|
|
@@ -26093,11 +26128,26 @@ function usePropertyController() {
|
|
|
26093
26128
|
next(error);
|
|
26094
26129
|
}
|
|
26095
26130
|
}
|
|
26131
|
+
async function deleteById(req, res, next) {
|
|
26132
|
+
const id = req.params.id;
|
|
26133
|
+
if (!id) {
|
|
26134
|
+
next(new BadRequestError53("Property ID is required."));
|
|
26135
|
+
return;
|
|
26136
|
+
}
|
|
26137
|
+
try {
|
|
26138
|
+
const message = await _deleteById(id);
|
|
26139
|
+
res.json(message);
|
|
26140
|
+
return;
|
|
26141
|
+
} catch (error) {
|
|
26142
|
+
next(error);
|
|
26143
|
+
}
|
|
26144
|
+
}
|
|
26096
26145
|
return {
|
|
26097
26146
|
add,
|
|
26098
26147
|
updateById,
|
|
26099
26148
|
getAll,
|
|
26100
|
-
getById
|
|
26149
|
+
getById,
|
|
26150
|
+
deleteById
|
|
26101
26151
|
};
|
|
26102
26152
|
}
|
|
26103
26153
|
|
|
@@ -26427,6 +26477,7 @@ export {
|
|
|
26427
26477
|
modelProperty,
|
|
26428
26478
|
schema,
|
|
26429
26479
|
schemaProperty,
|
|
26480
|
+
schemaPropertyUpdate,
|
|
26430
26481
|
useAddressController,
|
|
26431
26482
|
useAddressRepo,
|
|
26432
26483
|
useAuthController,
|