@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/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2278,6 +2278,7 @@ type TProperty = {
|
|
|
2278
2278
|
updatedAt?: Date;
|
|
2279
2279
|
deletedAt?: Date;
|
|
2280
2280
|
};
|
|
2281
|
+
declare const schemaPropertyUpdate: Joi.ObjectSchema<any>;
|
|
2281
2282
|
declare const schemaProperty: Joi.ObjectSchema<any>;
|
|
2282
2283
|
declare function modelProperty(value: TProperty): TProperty;
|
|
2283
2284
|
|
|
@@ -2286,7 +2287,12 @@ declare function usePropertyRepo(): {
|
|
|
2286
2287
|
add: (value: TProperty, session?: ClientSession) => Promise<ObjectId>;
|
|
2287
2288
|
deleteById: (_id: string | ObjectId) => Promise<mongodb.DeleteResult>;
|
|
2288
2289
|
updateById: (_id: string | ObjectId, value: TProperty, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
2289
|
-
getAll: (
|
|
2290
|
+
getAll: ({ page, limit, status, search, }?: {
|
|
2291
|
+
page?: number | undefined;
|
|
2292
|
+
limit?: number | undefined;
|
|
2293
|
+
status?: string | undefined;
|
|
2294
|
+
search?: string | undefined;
|
|
2295
|
+
}) => Promise<{}>;
|
|
2290
2296
|
getById: (_id: string | ObjectId) => Promise<mongodb.WithId<bson.Document> | TProperty>;
|
|
2291
2297
|
};
|
|
2292
2298
|
|
|
@@ -2295,6 +2301,7 @@ declare function usePropertyController(): {
|
|
|
2295
2301
|
updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2296
2302
|
getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2297
2303
|
getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2304
|
+
deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2298
2305
|
};
|
|
2299
2306
|
|
|
2300
2307
|
declare function usePaypalService(): {
|
|
@@ -2355,4 +2362,4 @@ declare const XENDIT_SECRET_KEY: string;
|
|
|
2355
2362
|
declare const XENDIT_BASE_URL: string;
|
|
2356
2363
|
declare const DOMAIN: string;
|
|
2357
2364
|
|
|
2358
|
-
export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, CardPayment, CardPaymentSchema, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, DirectDebit, DirectDebitSchema, EWalletPayment, EWalletPaymentSchema, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MAddress, MEntity, MFile, MMember, MONGO_DB, MONGO_URI, MOrder, MOrg, MPaymentMethod, MPromoCode, MRole, MSubscription, MToken, MUser, MUserRole, MVerification, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TAddress, TBillingRecipient, TCounter, TEntity, TFile, TInvoice, TMember, TMiniRole, TOrder, TOrderMetadata, TOrg, TPayment, TPaymentMethod$1 as TPaymentMethod, TPaymentMethodType, TPrice, TPriceType, TPromoCode, TPromoTier, TProperty, TRole, TSubscription, TToken, TUser, TUserRole, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, addressSchema, isDev, modelProperty, schema, schemaProperty, useAddressController, useAddressRepo, useAuthController, useAuthService, useCounterModel, useCounterRepo, useEntityController, useEntityRepo, useFileController, useFileRepo, useFileService, useInvoiceController, useInvoiceModel, useInvoiceRepo, useInvoiceService, useMemberController, useMemberRepo, useOrderController, useOrderRepo, useOrgController, useOrgRepo, useOrgService, usePaymentController, usePaymentMethodController, usePaymentMethodRepo, usePaymentMethodService, usePaymentModel, usePaymentRepo, usePaypalService, usePriceController, usePriceModel, usePriceRepo, usePromoCodeController, usePromoCodeRepo, usePropertyController, usePropertyRepo, useRoleController, useRoleRepo, useSubscriptionController, useSubscriptionRepo, useSubscriptionService, useTokenRepo, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService, useXenditService, validateCardPayment, validateDirectDebit, validateEWalletPayment };
|
|
2365
|
+
export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, CardPayment, CardPaymentSchema, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, DirectDebit, DirectDebitSchema, EWalletPayment, EWalletPaymentSchema, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MAddress, MEntity, MFile, MMember, MONGO_DB, MONGO_URI, MOrder, MOrg, MPaymentMethod, MPromoCode, MRole, MSubscription, MToken, MUser, MUserRole, MVerification, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REFRESH_TOKEN_EXPIRY, REFRESH_TOKEN_SECRET, SECRET_KEY, SPACES_ACCESS_KEY, SPACES_BUCKET, SPACES_ENDPOINT, SPACES_REGION, SPACES_SECRET_KEY, TAddress, TBillingRecipient, TCounter, TEntity, TFile, TInvoice, TMember, TMiniRole, TOrder, TOrderMetadata, TOrg, TPayment, TPaymentMethod$1 as TPaymentMethod, TPaymentMethodType, TPrice, TPriceType, TPromoCode, TPromoTier, TProperty, TRole, TSubscription, TToken, TUser, TUserRole, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, addressSchema, isDev, modelProperty, schema, schemaProperty, schemaPropertyUpdate, useAddressController, useAddressRepo, useAuthController, useAuthService, useCounterModel, useCounterRepo, useEntityController, useEntityRepo, useFileController, useFileRepo, useFileService, useInvoiceController, useInvoiceModel, useInvoiceRepo, useInvoiceService, useMemberController, useMemberRepo, useOrderController, useOrderRepo, useOrgController, useOrgRepo, useOrgService, usePaymentController, usePaymentMethodController, usePaymentMethodRepo, usePaymentMethodService, usePaymentModel, usePaymentRepo, usePaypalService, usePriceController, usePriceModel, usePriceRepo, usePromoCodeController, usePromoCodeRepo, usePropertyController, usePropertyRepo, useRoleController, useRoleRepo, useSubscriptionController, useSubscriptionRepo, useSubscriptionService, useTokenRepo, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService, useXenditService, validateCardPayment, validateDirectDebit, validateEWalletPayment };
|
package/dist/index.js
CHANGED
|
@@ -11599,6 +11599,7 @@ __export(src_exports, {
|
|
|
11599
11599
|
modelProperty: () => modelProperty,
|
|
11600
11600
|
schema: () => schema,
|
|
11601
11601
|
schemaProperty: () => schemaProperty,
|
|
11602
|
+
schemaPropertyUpdate: () => schemaPropertyUpdate,
|
|
11602
11603
|
useAddressController: () => useAddressController,
|
|
11603
11604
|
useAddressRepo: () => useAddressRepo,
|
|
11604
11605
|
useAuthController: () => useAuthController,
|
|
@@ -25693,6 +25694,27 @@ function usePriceController() {
|
|
|
25693
25694
|
var import_utils83 = require("@goweekdays/utils");
|
|
25694
25695
|
var import_joi28 = __toESM(require("joi"));
|
|
25695
25696
|
var import_mongodb34 = require("mongodb");
|
|
25697
|
+
var schemaPropertyUpdate = import_joi28.default.object({
|
|
25698
|
+
propertyName: import_joi28.default.string().trim().required(),
|
|
25699
|
+
propertyType: import_joi28.default.string().trim().required(),
|
|
25700
|
+
propertyDescription: import_joi28.default.string().trim().required(),
|
|
25701
|
+
streetAddress: import_joi28.default.string().trim().required(),
|
|
25702
|
+
barangay: import_joi28.default.string().trim().required(),
|
|
25703
|
+
city: import_joi28.default.string().trim().required(),
|
|
25704
|
+
province: import_joi28.default.string().trim().required(),
|
|
25705
|
+
region: import_joi28.default.string().trim().required(),
|
|
25706
|
+
zipCode: import_joi28.default.string().trim().optional().allow(""),
|
|
25707
|
+
latitude: import_joi28.default.string().trim().optional().allow(""),
|
|
25708
|
+
longitude: import_joi28.default.string().trim().optional().allow(""),
|
|
25709
|
+
ownerId: import_joi28.default.string().trim().optional().allow(""),
|
|
25710
|
+
managerName: import_joi28.default.string().trim().optional().allow(""),
|
|
25711
|
+
managerEmail: import_joi28.default.string().trim().email().optional().allow(""),
|
|
25712
|
+
managerPhone: import_joi28.default.string().trim().optional().allow(""),
|
|
25713
|
+
amenities: import_joi28.default.array().items(import_joi28.default.string().trim()).optional(),
|
|
25714
|
+
numberOfFloors: import_joi28.default.string().trim().required(),
|
|
25715
|
+
floorLabels: import_joi28.default.string().optional().allow(""),
|
|
25716
|
+
stayType: import_joi28.default.string().trim().required()
|
|
25717
|
+
});
|
|
25696
25718
|
var schemaProperty = import_joi28.default.object({
|
|
25697
25719
|
_id: import_joi28.default.string().optional(),
|
|
25698
25720
|
propertyName: import_joi28.default.string().trim().required(),
|
|
@@ -25713,20 +25735,8 @@ var schemaProperty = import_joi28.default.object({
|
|
|
25713
25735
|
amenities: import_joi28.default.array().items(import_joi28.default.string().trim()).optional(),
|
|
25714
25736
|
numberOfFloors: import_joi28.default.string().trim().required(),
|
|
25715
25737
|
floorLabels: import_joi28.default.string().optional().allow(""),
|
|
25716
|
-
coverPhoto: import_joi28.default.object({
|
|
25717
|
-
|
|
25718
|
-
size: import_joi28.default.string().trim().optional().allow(""),
|
|
25719
|
-
type: import_joi28.default.string().trim().optional().allow(""),
|
|
25720
|
-
webkitRelativePath: import_joi28.default.string().trim().optional().allow("")
|
|
25721
|
-
}),
|
|
25722
|
-
photoGallery: import_joi28.default.array().items(
|
|
25723
|
-
import_joi28.default.object({
|
|
25724
|
-
name: import_joi28.default.string().trim().optional().allow(""),
|
|
25725
|
-
size: import_joi28.default.string().trim().optional().allow(""),
|
|
25726
|
-
type: import_joi28.default.string().trim().optional().allow(""),
|
|
25727
|
-
webkitRelativePath: import_joi28.default.string().trim().optional().allow("")
|
|
25728
|
-
})
|
|
25729
|
-
).required(),
|
|
25738
|
+
coverPhoto: import_joi28.default.object({}),
|
|
25739
|
+
photoGallery: import_joi28.default.array().items(import_joi28.default.object({})),
|
|
25730
25740
|
stayType: import_joi28.default.string().trim().required(),
|
|
25731
25741
|
createdAt: import_joi28.default.date().optional(),
|
|
25732
25742
|
updatedAt: import_joi28.default.date().optional(),
|
|
@@ -25831,18 +25841,25 @@ function usePropertyRepo() {
|
|
|
25831
25841
|
async function updateById(_id, value, session) {
|
|
25832
25842
|
try {
|
|
25833
25843
|
_id = new import_mongodb35.ObjectId(_id);
|
|
25834
|
-
} catch (
|
|
25844
|
+
} catch (error2) {
|
|
25835
25845
|
throw new import_utils84.BadRequestError("Invalid ID.");
|
|
25836
25846
|
}
|
|
25847
|
+
const { error } = schemaPropertyUpdate.validate(value);
|
|
25848
|
+
if (error) {
|
|
25849
|
+
throw new import_utils84.BadRequestError(
|
|
25850
|
+
`Invalid property data: ${error.message}. Repository validation.`
|
|
25851
|
+
);
|
|
25852
|
+
}
|
|
25837
25853
|
try {
|
|
25854
|
+
value.updatedAt = /* @__PURE__ */ new Date();
|
|
25838
25855
|
const res = await collection.updateOne(
|
|
25839
25856
|
{ _id },
|
|
25840
|
-
{ $set:
|
|
25857
|
+
{ $set: value },
|
|
25841
25858
|
{ session }
|
|
25842
25859
|
);
|
|
25843
25860
|
delCachedData();
|
|
25844
25861
|
return res;
|
|
25845
|
-
} catch (
|
|
25862
|
+
} catch (error2) {
|
|
25846
25863
|
throw new import_utils84.InternalServerError("Failed to update property.");
|
|
25847
25864
|
}
|
|
25848
25865
|
}
|
|
@@ -25860,8 +25877,25 @@ function usePropertyRepo() {
|
|
|
25860
25877
|
throw new import_utils84.InternalServerError("Failed to delete property.");
|
|
25861
25878
|
}
|
|
25862
25879
|
}
|
|
25863
|
-
async function getAll(
|
|
25864
|
-
|
|
25880
|
+
async function getAll({
|
|
25881
|
+
page = 1,
|
|
25882
|
+
limit = 20,
|
|
25883
|
+
status = "active",
|
|
25884
|
+
search = ""
|
|
25885
|
+
} = {}) {
|
|
25886
|
+
page = page > 0 ? page - 1 : 0;
|
|
25887
|
+
const query = { status };
|
|
25888
|
+
const cacheKeyOptions = {
|
|
25889
|
+
action: "getAll",
|
|
25890
|
+
page,
|
|
25891
|
+
limit,
|
|
25892
|
+
status
|
|
25893
|
+
};
|
|
25894
|
+
if (search) {
|
|
25895
|
+
query.$text = { $search: search };
|
|
25896
|
+
cacheKeyOptions.search = search;
|
|
25897
|
+
}
|
|
25898
|
+
const cacheKey = (0, import_utils84.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
25865
25899
|
try {
|
|
25866
25900
|
const cached = await getCache(cacheKey);
|
|
25867
25901
|
if (cached) {
|
|
@@ -25871,8 +25905,14 @@ function usePropertyRepo() {
|
|
|
25871
25905
|
});
|
|
25872
25906
|
return cached;
|
|
25873
25907
|
}
|
|
25874
|
-
const
|
|
25875
|
-
|
|
25908
|
+
const items = await collection.aggregate([
|
|
25909
|
+
{ $match: query },
|
|
25910
|
+
{ $skip: page * limit },
|
|
25911
|
+
{ $limit: limit }
|
|
25912
|
+
]).toArray();
|
|
25913
|
+
const length = await collection.countDocuments(query);
|
|
25914
|
+
const data = (0, import_utils84.paginate)(items, page, limit, length);
|
|
25915
|
+
setCache(cacheKey, data, 300).then(() => {
|
|
25876
25916
|
import_utils84.logger.log({
|
|
25877
25917
|
level: "info",
|
|
25878
25918
|
message: `Cache set for getAll: ${cacheKey}`
|
|
@@ -25883,7 +25923,7 @@ function usePropertyRepo() {
|
|
|
25883
25923
|
message: `Failed to set cache: ${err.message}`
|
|
25884
25924
|
});
|
|
25885
25925
|
});
|
|
25886
|
-
return
|
|
25926
|
+
return data;
|
|
25887
25927
|
} catch (error) {
|
|
25888
25928
|
throw new import_utils84.InternalServerError(
|
|
25889
25929
|
`Failed to fetch properties: ${error.message}`
|
|
@@ -25949,7 +25989,8 @@ function usePropertyController() {
|
|
|
25949
25989
|
add: _add,
|
|
25950
25990
|
updateById: _updateById,
|
|
25951
25991
|
getAll: _getAll,
|
|
25952
|
-
getById: _getById
|
|
25992
|
+
getById: _getById,
|
|
25993
|
+
deleteById: _deleteById
|
|
25953
25994
|
} = usePropertyRepo();
|
|
25954
25995
|
async function add(req, res, next) {
|
|
25955
25996
|
const value = req.body;
|
|
@@ -25968,32 +26009,15 @@ function usePropertyController() {
|
|
|
25968
26009
|
}
|
|
25969
26010
|
async function updateById(req, res, next) {
|
|
25970
26011
|
const _id = req.params.id ?? "";
|
|
25971
|
-
const
|
|
25972
|
-
|
|
25973
|
-
_id: import_joi29.default.string().required(),
|
|
25974
|
-
name: import_joi29.default.string().trim().required(),
|
|
25975
|
-
type: import_joi29.default.string().trim().required(),
|
|
25976
|
-
description: import_joi29.default.string().trim().required(),
|
|
25977
|
-
street: import_joi29.default.string().trim().required(),
|
|
25978
|
-
barangay: import_joi29.default.string().trim().required(),
|
|
25979
|
-
cityMunicipality: import_joi29.default.string().trim().required(),
|
|
25980
|
-
province: import_joi29.default.string().trim().required(),
|
|
25981
|
-
region: import_joi29.default.string().trim().required(),
|
|
25982
|
-
zipCode: import_joi29.default.string().trim().optional().allow(""),
|
|
25983
|
-
latitude: import_joi29.default.string().trim().optional().allow(""),
|
|
25984
|
-
longitude: import_joi29.default.string().trim().optional().allow(""),
|
|
25985
|
-
ownerId: import_joi29.default.string().trim().optional().allow(""),
|
|
25986
|
-
ownerName: import_joi29.default.string().trim().optional().allow(""),
|
|
25987
|
-
email: import_joi29.default.string().trim().email().optional().allow(""),
|
|
25988
|
-
phone: import_joi29.default.string().trim().optional().allow(""),
|
|
25989
|
-
amenities: import_joi29.default.array().items(import_joi29.default.string().trim()).optional(),
|
|
25990
|
-
floorNumber: import_joi29.default.string().trim().required(),
|
|
25991
|
-
floorLabel: import_joi29.default.string().optional().allow(""),
|
|
25992
|
-
coverPhoto: import_joi29.default.string().trim().required(),
|
|
25993
|
-
photoGallery: import_joi29.default.array().items(import_joi29.default.string().trim()).required(),
|
|
25994
|
-
stayType: import_joi29.default.string().trim().required()
|
|
26012
|
+
const idValidation = import_joi29.default.object({
|
|
26013
|
+
_id: import_joi29.default.string().required()
|
|
25995
26014
|
});
|
|
25996
|
-
const { error } =
|
|
26015
|
+
const { error: idValidationError } = idValidation.validate({ _id });
|
|
26016
|
+
if (idValidationError) {
|
|
26017
|
+
throw new import_utils85.BadRequestError(`Invalid ID`);
|
|
26018
|
+
}
|
|
26019
|
+
const value = req.body;
|
|
26020
|
+
const { error } = schemaPropertyUpdate.validate(value);
|
|
25997
26021
|
if (error) {
|
|
25998
26022
|
throw new import_utils85.BadRequestError(`Invalid property data: ${error.message}`);
|
|
25999
26023
|
}
|
|
@@ -26005,12 +26029,23 @@ function usePropertyController() {
|
|
|
26005
26029
|
}
|
|
26006
26030
|
}
|
|
26007
26031
|
async function getAll(req, res, next) {
|
|
26032
|
+
const validation = import_joi29.default.object({
|
|
26033
|
+
page: import_joi29.default.number().integer().min(1).default(1),
|
|
26034
|
+
limit: import_joi29.default.number().integer().min(1).max(100).default(10),
|
|
26035
|
+
search: import_joi29.default.string().trim().allow("").default(""),
|
|
26036
|
+
status: import_joi29.default.string().default("active")
|
|
26037
|
+
});
|
|
26038
|
+
const { error, value } = validation.validate(req.query);
|
|
26039
|
+
if (error) {
|
|
26040
|
+
next(new import_utils85.BadRequestError(error.message));
|
|
26041
|
+
return;
|
|
26042
|
+
}
|
|
26008
26043
|
try {
|
|
26009
|
-
const properties = await _getAll();
|
|
26044
|
+
const properties = await _getAll(value);
|
|
26010
26045
|
res.json(properties);
|
|
26011
26046
|
return;
|
|
26012
|
-
} catch (
|
|
26013
|
-
next(
|
|
26047
|
+
} catch (error2) {
|
|
26048
|
+
next(error2);
|
|
26014
26049
|
}
|
|
26015
26050
|
}
|
|
26016
26051
|
async function getById(req, res, next) {
|
|
@@ -26027,11 +26062,26 @@ function usePropertyController() {
|
|
|
26027
26062
|
next(error);
|
|
26028
26063
|
}
|
|
26029
26064
|
}
|
|
26065
|
+
async function deleteById(req, res, next) {
|
|
26066
|
+
const id = req.params.id;
|
|
26067
|
+
if (!id) {
|
|
26068
|
+
next(new import_utils85.BadRequestError("Property ID is required."));
|
|
26069
|
+
return;
|
|
26070
|
+
}
|
|
26071
|
+
try {
|
|
26072
|
+
const message = await _deleteById(id);
|
|
26073
|
+
res.json(message);
|
|
26074
|
+
return;
|
|
26075
|
+
} catch (error) {
|
|
26076
|
+
next(error);
|
|
26077
|
+
}
|
|
26078
|
+
}
|
|
26030
26079
|
return {
|
|
26031
26080
|
add,
|
|
26032
26081
|
updateById,
|
|
26033
26082
|
getAll,
|
|
26034
|
-
getById
|
|
26083
|
+
getById,
|
|
26084
|
+
deleteById
|
|
26035
26085
|
};
|
|
26036
26086
|
}
|
|
26037
26087
|
|
|
@@ -26357,6 +26407,7 @@ function useUtilController() {
|
|
|
26357
26407
|
modelProperty,
|
|
26358
26408
|
schema,
|
|
26359
26409
|
schemaProperty,
|
|
26410
|
+
schemaPropertyUpdate,
|
|
26360
26411
|
useAddressController,
|
|
26361
26412
|
useAddressRepo,
|
|
26362
26413
|
useAuthController,
|