@goweekdays/core 1.2.5 → 1.3.1

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @goweekdays/core
2
2
 
3
+ ## 1.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 216fd0d: Add default query
8
+
9
+ ## 1.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - f8f8694: Property management initial release
14
+
3
15
  ## 1.2.5
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -2274,10 +2274,12 @@ type TProperty = {
2274
2274
  coverPhoto: object;
2275
2275
  photoGallery: Array<object>;
2276
2276
  stayType: string;
2277
+ status?: string;
2277
2278
  createdAt?: Date;
2278
2279
  updatedAt?: Date;
2279
2280
  deletedAt?: Date;
2280
2281
  };
2282
+ declare const schemaPropertyUpdate: Joi.ObjectSchema<any>;
2281
2283
  declare const schemaProperty: Joi.ObjectSchema<any>;
2282
2284
  declare function modelProperty(value: TProperty): TProperty;
2283
2285
 
@@ -2286,7 +2288,12 @@ declare function usePropertyRepo(): {
2286
2288
  add: (value: TProperty, session?: ClientSession) => Promise<ObjectId>;
2287
2289
  deleteById: (_id: string | ObjectId) => Promise<mongodb.DeleteResult>;
2288
2290
  updateById: (_id: string | ObjectId, value: TProperty, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
2289
- getAll: () => Promise<mongodb.WithId<bson.Document>[] | TProperty[]>;
2291
+ getAll: ({ page, limit, status, search, }?: {
2292
+ page?: number | undefined;
2293
+ limit?: number | undefined;
2294
+ status?: string | undefined;
2295
+ search?: string | undefined;
2296
+ }) => Promise<{}>;
2290
2297
  getById: (_id: string | ObjectId) => Promise<mongodb.WithId<bson.Document> | TProperty>;
2291
2298
  };
2292
2299
 
@@ -2295,6 +2302,7 @@ declare function usePropertyController(): {
2295
2302
  updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2296
2303
  getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2297
2304
  getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2305
+ deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2298
2306
  };
2299
2307
 
2300
2308
  declare function usePaypalService(): {
@@ -2355,4 +2363,4 @@ declare const XENDIT_SECRET_KEY: string;
2355
2363
  declare const XENDIT_BASE_URL: string;
2356
2364
  declare const DOMAIN: string;
2357
2365
 
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 };
2366
+ 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
- name: import_joi28.default.string().trim().optional().allow(""),
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.string().optional().allow("", null),
25739
+ photoGallery: import_joi28.default.array().items(import_joi28.default.string()),
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(),
@@ -25767,6 +25777,7 @@ function modelProperty(value) {
25767
25777
  coverPhoto: value.coverPhoto,
25768
25778
  photoGallery: value.photoGallery ?? [],
25769
25779
  stayType: value.stayType,
25780
+ status: value.status ?? "active",
25770
25781
  createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
25771
25782
  updatedAt: value.updatedAt,
25772
25783
  deletedAt: value.deletedAt
@@ -25831,18 +25842,25 @@ function usePropertyRepo() {
25831
25842
  async function updateById(_id, value, session) {
25832
25843
  try {
25833
25844
  _id = new import_mongodb35.ObjectId(_id);
25834
- } catch (error) {
25845
+ } catch (error2) {
25835
25846
  throw new import_utils84.BadRequestError("Invalid ID.");
25836
25847
  }
25848
+ const { error } = schemaPropertyUpdate.validate(value);
25849
+ if (error) {
25850
+ throw new import_utils84.BadRequestError(
25851
+ `Invalid property data: ${error.message}. Repository validation.`
25852
+ );
25853
+ }
25837
25854
  try {
25855
+ value.updatedAt = /* @__PURE__ */ new Date();
25838
25856
  const res = await collection.updateOne(
25839
25857
  { _id },
25840
- { $set: { value, updatedAt: /* @__PURE__ */ new Date() } },
25858
+ { $set: value },
25841
25859
  { session }
25842
25860
  );
25843
25861
  delCachedData();
25844
25862
  return res;
25845
- } catch (error) {
25863
+ } catch (error2) {
25846
25864
  throw new import_utils84.InternalServerError("Failed to update property.");
25847
25865
  }
25848
25866
  }
@@ -25860,8 +25878,25 @@ function usePropertyRepo() {
25860
25878
  throw new import_utils84.InternalServerError("Failed to delete property.");
25861
25879
  }
25862
25880
  }
25863
- async function getAll() {
25864
- const cacheKey = (0, import_utils84.makeCacheKey)(namespace_collection, { action: "getAll" });
25881
+ async function getAll({
25882
+ page = 1,
25883
+ limit = 20,
25884
+ status = "active",
25885
+ search = ""
25886
+ } = {}) {
25887
+ page = page > 0 ? page - 1 : 0;
25888
+ const query = { status };
25889
+ const cacheKeyOptions = {
25890
+ action: "getAll",
25891
+ page,
25892
+ limit,
25893
+ status
25894
+ };
25895
+ if (search) {
25896
+ query.$text = { $search: search };
25897
+ cacheKeyOptions.search = search;
25898
+ }
25899
+ const cacheKey = (0, import_utils84.makeCacheKey)(namespace_collection, cacheKeyOptions);
25865
25900
  try {
25866
25901
  const cached = await getCache(cacheKey);
25867
25902
  if (cached) {
@@ -25871,8 +25906,14 @@ function usePropertyRepo() {
25871
25906
  });
25872
25907
  return cached;
25873
25908
  }
25874
- const properties = await collection.find({}).toArray();
25875
- setCache(cacheKey, properties, 300).then(() => {
25909
+ const items = await collection.aggregate([
25910
+ { $match: query },
25911
+ { $skip: page * limit },
25912
+ { $limit: limit }
25913
+ ]).toArray();
25914
+ const length = await collection.countDocuments(query);
25915
+ const data = (0, import_utils84.paginate)(items, page, limit, length);
25916
+ setCache(cacheKey, data, 300).then(() => {
25876
25917
  import_utils84.logger.log({
25877
25918
  level: "info",
25878
25919
  message: `Cache set for getAll: ${cacheKey}`
@@ -25883,7 +25924,7 @@ function usePropertyRepo() {
25883
25924
  message: `Failed to set cache: ${err.message}`
25884
25925
  });
25885
25926
  });
25886
- return properties;
25927
+ return data;
25887
25928
  } catch (error) {
25888
25929
  throw new import_utils84.InternalServerError(
25889
25930
  `Failed to fetch properties: ${error.message}`
@@ -25949,7 +25990,8 @@ function usePropertyController() {
25949
25990
  add: _add,
25950
25991
  updateById: _updateById,
25951
25992
  getAll: _getAll,
25952
- getById: _getById
25993
+ getById: _getById,
25994
+ deleteById: _deleteById
25953
25995
  } = usePropertyRepo();
25954
25996
  async function add(req, res, next) {
25955
25997
  const value = req.body;
@@ -25968,32 +26010,15 @@ function usePropertyController() {
25968
26010
  }
25969
26011
  async function updateById(req, res, next) {
25970
26012
  const _id = req.params.id ?? "";
25971
- const value = { _id, ...req.body };
25972
- const validation = import_joi29.default.object({
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()
26013
+ const idValidation = import_joi29.default.object({
26014
+ _id: import_joi29.default.string().required()
25995
26015
  });
25996
- const { error } = validation.validate(value);
26016
+ const { error: idValidationError } = idValidation.validate({ _id });
26017
+ if (idValidationError) {
26018
+ throw new import_utils85.BadRequestError(`Invalid ID`);
26019
+ }
26020
+ const value = req.body;
26021
+ const { error } = schemaPropertyUpdate.validate(value);
25997
26022
  if (error) {
25998
26023
  throw new import_utils85.BadRequestError(`Invalid property data: ${error.message}`);
25999
26024
  }
@@ -26005,12 +26030,23 @@ function usePropertyController() {
26005
26030
  }
26006
26031
  }
26007
26032
  async function getAll(req, res, next) {
26033
+ const validation = import_joi29.default.object({
26034
+ page: import_joi29.default.number().integer().min(1).default(1),
26035
+ limit: import_joi29.default.number().integer().min(1).max(100).default(10),
26036
+ search: import_joi29.default.string().trim().allow("").default(""),
26037
+ status: import_joi29.default.string().default("active")
26038
+ });
26039
+ const { error, value } = validation.validate(req.query);
26040
+ if (error) {
26041
+ next(new import_utils85.BadRequestError(error.message));
26042
+ return;
26043
+ }
26008
26044
  try {
26009
- const properties = await _getAll();
26045
+ const properties = await _getAll(value);
26010
26046
  res.json(properties);
26011
26047
  return;
26012
- } catch (error) {
26013
- next(error);
26048
+ } catch (error2) {
26049
+ next(error2);
26014
26050
  }
26015
26051
  }
26016
26052
  async function getById(req, res, next) {
@@ -26027,11 +26063,26 @@ function usePropertyController() {
26027
26063
  next(error);
26028
26064
  }
26029
26065
  }
26066
+ async function deleteById(req, res, next) {
26067
+ const id = req.params.id;
26068
+ if (!id) {
26069
+ next(new import_utils85.BadRequestError("Property ID is required."));
26070
+ return;
26071
+ }
26072
+ try {
26073
+ const message = await _deleteById(id);
26074
+ res.json(message);
26075
+ return;
26076
+ } catch (error) {
26077
+ next(error);
26078
+ }
26079
+ }
26030
26080
  return {
26031
26081
  add,
26032
26082
  updateById,
26033
26083
  getAll,
26034
- getById
26084
+ getById,
26085
+ deleteById
26035
26086
  };
26036
26087
  }
26037
26088
 
@@ -26357,6 +26408,7 @@ function useUtilController() {
26357
26408
  modelProperty,
26358
26409
  schema,
26359
26410
  schemaProperty,
26411
+ schemaPropertyUpdate,
26360
26412
  useAddressController,
26361
26413
  useAddressRepo,
26362
26414
  useAuthController,