@eeplatform/core 1.8.0 → 1.8.2

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
  # @eeplatform/core
2
2
 
3
+ ## 1.8.2
4
+
5
+ ### Patch Changes
6
+
7
+ - a51c5b5: Update PSDGC get all query
8
+
9
+ ## 1.8.1
10
+
11
+ ### Patch Changes
12
+
13
+ - aff1249: Revise PSGC implementation
14
+
3
15
  ## 1.8.0
4
16
 
5
17
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -876,7 +876,7 @@ declare const transactionSchema: Joi.ObjectSchema<any>;
876
876
 
877
877
  type TPSGC = {
878
878
  _id?: ObjectId;
879
- code: number;
879
+ code: string;
880
880
  name: string;
881
881
  type: string;
882
882
  };
@@ -890,12 +890,13 @@ declare function modelPSGC(data: any): {
890
890
  declare function usePSGCRepo(): {
891
891
  createIndexes: () => Promise<void>;
892
892
  add: (value: TPSGC, session?: ClientSession) => Promise<ObjectId>;
893
- getAll: ({ search, page, limit, sort, status, }?: {
893
+ getAll: ({ search, page, limit, sort, type, prefix, }?: {
894
894
  search?: string | undefined;
895
895
  page?: number | undefined;
896
896
  limit?: number | undefined;
897
897
  sort?: {} | undefined;
898
- status?: string | undefined;
898
+ type?: string | undefined;
899
+ prefix?: string | undefined;
899
900
  }) => Promise<Record<string, any> | {
900
901
  items: any[];
901
902
  pages: number;
@@ -908,14 +909,22 @@ declare function usePSGCRepo(): {
908
909
  value: string;
909
910
  }, session?: ClientSession) => Promise<string>;
910
911
  deleteById: (_id: string | ObjectId) => Promise<string>;
911
- getByName: ({ name, cityMunicipality, code, type }?: {
912
+ getByName: ({ name, prefix, type }?: {
912
913
  name: string;
913
- cityMunicipality?: boolean;
914
- code?: number;
914
+ prefix?: string;
915
915
  type?: string;
916
916
  }) => Promise<TPSGC | null>;
917
917
  };
918
918
 
919
+ declare function usePSGCController(): {
920
+ add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
921
+ getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
922
+ getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
923
+ getByName: (req: Request, res: Response, next: NextFunction) => Promise<void>;
924
+ updateField: (req: Request, res: Response, next: NextFunction) => Promise<void>;
925
+ deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
926
+ };
927
+
919
928
  declare const MONGO_URI: string;
920
929
  declare const MONGO_DB: string;
921
930
  declare const PORT: number;
@@ -955,4 +964,4 @@ declare const GEMINI_API_KEY: string;
955
964
  declare const ASSEMBLY_AI_API_KEY: string;
956
965
  declare const DOMAIN: string;
957
966
 
958
- export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, ASSEMBLY_AI_API_KEY, AudioFileData, AudioTranscriptionOptions, AudioTranscriptionResult, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, GEMINI_API_KEY, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MAddress, MBuilding, MBuildingUnit, MFile, MMember, MONGO_DB, MONGO_URI, MOrg, MRole, MToken, MUser, MUserRole, MVerification, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT, PhonemeMatchOptions, PhonemeMatchResult, 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, TBuilding, TBuildingUnit, TCounter, TFile, TMember, TMiniRole, TOrg, TPSGC, TRole, TToken, TUser, TUserRole, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, addressSchema, isDev, modelPSGC, schemaBuilding, schemaBuildingUnit, schemaOrg, schemaPSGC, schemaUpdateOptions, transactionSchema, useAddressController, useAddressRepo, useAudioTranscriptionController, useAuthController, useAuthService, useBuildingController, useBuildingRepo, useBuildingService, useBuildingUnitController, useBuildingUnitRepo, useBuildingUnitService, useCounterModel, useCounterRepo, useFileController, useFileRepo, useFileService, useGeminiAiService, useGitHubService, useMemberController, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePSGCRepo, useRoleController, useRoleRepo, useTokenRepo, useTranscribeService, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService };
967
+ export { ACCESS_TOKEN_EXPIRY, ACCESS_TOKEN_SECRET, APP_ACCOUNT, APP_MAIN, ASSEMBLY_AI_API_KEY, AudioFileData, AudioTranscriptionOptions, AudioTranscriptionResult, DEFAULT_USER_EMAIL, DEFAULT_USER_FIRST_NAME, DEFAULT_USER_LAST_NAME, DEFAULT_USER_PASSWORD, DOMAIN, GEMINI_API_KEY, MAILER_EMAIL, MAILER_PASSWORD, MAILER_TRANSPORT_HOST, MAILER_TRANSPORT_PORT, MAILER_TRANSPORT_SECURE, MAddress, MBuilding, MBuildingUnit, MFile, MMember, MONGO_DB, MONGO_URI, MOrg, MRole, MToken, MUser, MUserRole, MVerification, PAYPAL_API_URL, PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT, PhonemeMatchOptions, PhonemeMatchResult, 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, TBuilding, TBuildingUnit, TCounter, TFile, TMember, TMiniRole, TOrg, TPSGC, TRole, TToken, TUser, TUserRole, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, addressSchema, isDev, modelPSGC, schemaBuilding, schemaBuildingUnit, schemaOrg, schemaPSGC, schemaUpdateOptions, transactionSchema, useAddressController, useAddressRepo, useAudioTranscriptionController, useAuthController, useAuthService, useBuildingController, useBuildingRepo, useBuildingService, useBuildingUnitController, useBuildingUnitRepo, useBuildingUnitService, useCounterModel, useCounterRepo, useFileController, useFileRepo, useFileService, useGeminiAiService, useGitHubService, useMemberController, useMemberRepo, useOrgController, useOrgRepo, useOrgService, usePSGCController, usePSGCRepo, useRoleController, useRoleRepo, useTokenRepo, useTranscribeService, useUserController, useUserRepo, useUserService, useUtilController, useVerificationController, useVerificationRepo, useVerificationService };
package/dist/index.js CHANGED
@@ -110,6 +110,7 @@ __export(src_exports, {
110
110
  useOrgController: () => useOrgController,
111
111
  useOrgRepo: () => useOrgRepo,
112
112
  useOrgService: () => useOrgService,
113
+ usePSGCController: () => usePSGCController,
113
114
  usePSGCRepo: () => usePSGCRepo,
114
115
  useRoleController: () => useRoleController,
115
116
  useRoleRepo: () => useRoleRepo,
@@ -7026,10 +7027,10 @@ var transactionSchema = import_joi17.default.object({
7026
7027
  deletedAt: import_joi17.default.string().optional().allow("", null)
7027
7028
  });
7028
7029
 
7029
- // src/resources/phillipine-std-geo-code/psgc.model.ts
7030
+ // src/resources/psgc/psgc.model.ts
7030
7031
  var import_joi18 = __toESM(require("joi"));
7031
7032
  var schemaPSGC = import_joi18.default.object({
7032
- code: import_joi18.default.number().required(),
7033
+ code: import_joi18.default.string().length(10).required(),
7033
7034
  name: import_joi18.default.string().required(),
7034
7035
  type: import_joi18.default.string().valid("Reg", "Prov", "City", "Mun", "Bgy").required()
7035
7036
  });
@@ -7045,7 +7046,7 @@ function modelPSGC(data) {
7045
7046
  };
7046
7047
  }
7047
7048
 
7048
- // src/resources/phillipine-std-geo-code/psgc.repository.ts
7049
+ // src/resources/psgc/psgc.repository.ts
7049
7050
  var import_nodejs_utils39 = require("@eeplatform/nodejs-utils");
7050
7051
  var import_mongodb21 = require("mongodb");
7051
7052
  function usePSGCRepo() {
@@ -7053,7 +7054,7 @@ function usePSGCRepo() {
7053
7054
  if (!db) {
7054
7055
  throw new Error("Unable to connect to server.");
7055
7056
  }
7056
- const namespace_collection = "philippine.standard.geographic.codes";
7057
+ const namespace_collection = "psgc";
7057
7058
  const collection = db.collection(namespace_collection);
7058
7059
  const { getCache, setCache, delNamespace } = (0, import_nodejs_utils39.useCache)(namespace_collection);
7059
7060
  async function createIndexes() {
@@ -7107,20 +7108,27 @@ function usePSGCRepo() {
7107
7108
  page = 1,
7108
7109
  limit = 10,
7109
7110
  sort = {},
7110
- status = "active"
7111
+ type = "",
7112
+ prefix = ""
7111
7113
  } = {}) {
7112
7114
  page = page > 0 ? page - 1 : 0;
7113
7115
  const query = {
7114
- deletedAt: { $in: ["", null] },
7115
- status
7116
+ type
7116
7117
  };
7117
- sort = Object.keys(sort).length > 0 ? sort : { _id: 1 };
7118
7118
  const cacheKeyOptions = {
7119
- status,
7119
+ type,
7120
7120
  page,
7121
7121
  limit,
7122
7122
  sort: JSON.stringify(sort)
7123
7123
  };
7124
+ if (prefix) {
7125
+ query.code = { $regex: `^${prefix}` };
7126
+ cacheKeyOptions.prefix = prefix;
7127
+ }
7128
+ if (type === "City" || type === "Mun") {
7129
+ query.type = { $in: ["City", "Mun"] };
7130
+ }
7131
+ sort = Object.keys(sort).length > 0 ? sort : { _id: 1 };
7124
7132
  if (search) {
7125
7133
  query.$text = { $search: search };
7126
7134
  cacheKeyOptions.search = search;
@@ -7207,23 +7215,16 @@ function usePSGCRepo() {
7207
7215
  }
7208
7216
  }
7209
7217
  }
7210
- async function getByName({ name, cityMunicipality = false, code = 0, type = "" } = {}) {
7211
- const query = { $text: { $search: name } };
7212
- const cacheKeyOptions = { name };
7213
- if (cityMunicipality) {
7214
- query.type = { $in: ["City", "Mun"] };
7215
- cacheKeyOptions.type = cityMunicipality;
7218
+ async function getByName({ name, prefix = "", type = "" } = {}) {
7219
+ const query = { $text: { $search: name }, type };
7220
+ const cacheKeyOptions = { name, type };
7221
+ const _types = ["City", "Mun"];
7222
+ if (_types.includes(type)) {
7223
+ query.type = { $in: _types };
7216
7224
  }
7217
- if (type && !cityMunicipality) {
7218
- query.type = type;
7219
- cacheKeyOptions.type = type;
7220
- }
7221
- if (code) {
7222
- query.code = { $gt: code };
7223
- if (cityMunicipality) {
7224
- query.code.$lt = code + 1e6;
7225
- }
7226
- cacheKeyOptions.code = code;
7225
+ if (prefix) {
7226
+ query.code = { $regex: `^${prefix}` };
7227
+ cacheKeyOptions.prefix = prefix;
7227
7228
  }
7228
7229
  const cacheKey = (0, import_nodejs_utils39.makeCacheKey)(namespace_collection, { name });
7229
7230
  try {
@@ -7307,6 +7308,170 @@ function usePSGCRepo() {
7307
7308
  getByName
7308
7309
  };
7309
7310
  }
7311
+
7312
+ // src/resources/psgc/psgc.controller.ts
7313
+ var import_nodejs_utils40 = require("@eeplatform/nodejs-utils");
7314
+ var import_joi19 = __toESM(require("joi"));
7315
+ function usePSGCController() {
7316
+ const {
7317
+ add: _add,
7318
+ getAll: _getAll,
7319
+ getById: _getById,
7320
+ getByName: _getByName,
7321
+ updateFieldById: _updateFieldById,
7322
+ deleteById: _deleteById
7323
+ } = usePSGCRepo();
7324
+ async function add(req, res, next) {
7325
+ const value = req.body;
7326
+ const { error } = schemaPSGC.validate(value);
7327
+ if (error) {
7328
+ next(new import_nodejs_utils40.BadRequestError(error.message));
7329
+ return;
7330
+ }
7331
+ try {
7332
+ const data = await _add(value);
7333
+ res.json({
7334
+ message: "Successfully created region.",
7335
+ data
7336
+ });
7337
+ return;
7338
+ } catch (error2) {
7339
+ next(error2);
7340
+ }
7341
+ }
7342
+ async function getAll(req, res, next) {
7343
+ const query = req.query;
7344
+ const validation = import_joi19.default.object({
7345
+ page: import_joi19.default.number().min(1).optional().allow("", null),
7346
+ limit: import_joi19.default.number().min(1).optional().allow("", null),
7347
+ search: import_joi19.default.string().optional().allow("", null),
7348
+ type: import_joi19.default.string().valid("Reg", "Prov", "City", "Mun", "Bgy").required(),
7349
+ prefix: import_joi19.default.string().optional().allow("", null)
7350
+ });
7351
+ const { error } = validation.validate(query);
7352
+ const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
7353
+ const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
7354
+ const search = req.query.search ?? "";
7355
+ const type = req.query.type ?? "";
7356
+ const prefix = req.query.prefix ? String(req.query.prefix) : "";
7357
+ const isPageNumber = isFinite(page);
7358
+ if (!isPageNumber) {
7359
+ next(new import_nodejs_utils40.BadRequestError("Invalid page number."));
7360
+ return;
7361
+ }
7362
+ const isLimitNumber = isFinite(limit);
7363
+ if (!isLimitNumber) {
7364
+ next(new import_nodejs_utils40.BadRequestError("Invalid limit number."));
7365
+ return;
7366
+ }
7367
+ if (error) {
7368
+ next(new import_nodejs_utils40.BadRequestError(error.message));
7369
+ return;
7370
+ }
7371
+ try {
7372
+ const data = await _getAll({
7373
+ page,
7374
+ limit,
7375
+ search,
7376
+ type,
7377
+ prefix
7378
+ });
7379
+ res.json(data);
7380
+ return;
7381
+ } catch (error2) {
7382
+ next(error2);
7383
+ }
7384
+ }
7385
+ async function getById(req, res, next) {
7386
+ const id = req.params.id;
7387
+ const validation = import_joi19.default.object({
7388
+ id: import_joi19.default.string().hex().required()
7389
+ });
7390
+ const { error } = validation.validate({ id });
7391
+ if (error) {
7392
+ next(new import_nodejs_utils40.BadRequestError(error.message));
7393
+ return;
7394
+ }
7395
+ try {
7396
+ const data = await _getById(id);
7397
+ res.json({
7398
+ message: "Successfully retrieved region.",
7399
+ data
7400
+ });
7401
+ return;
7402
+ } catch (error2) {
7403
+ next(error2);
7404
+ }
7405
+ }
7406
+ async function getByName(req, res, next) {
7407
+ const name = req.params.name;
7408
+ const validation = import_joi19.default.object({
7409
+ name: import_joi19.default.string().required()
7410
+ });
7411
+ const { error } = validation.validate({ name });
7412
+ if (error) {
7413
+ next(new import_nodejs_utils40.BadRequestError(error.message));
7414
+ return;
7415
+ }
7416
+ try {
7417
+ const data = await _getByName({ name });
7418
+ res.json({
7419
+ message: "Successfully retrieved region.",
7420
+ data
7421
+ });
7422
+ return;
7423
+ } catch (error2) {
7424
+ next(error2);
7425
+ }
7426
+ }
7427
+ async function updateField(req, res, next) {
7428
+ const _id = req.params.id;
7429
+ const { field, value } = req.body;
7430
+ const validation = import_joi19.default.object({
7431
+ _id: import_joi19.default.string().hex().required(),
7432
+ field: import_joi19.default.string().valid("name", "director", "directorName").required(),
7433
+ value: import_joi19.default.string().required()
7434
+ });
7435
+ const { error } = validation.validate({ _id, field, value });
7436
+ if (error) {
7437
+ next(new import_nodejs_utils40.BadRequestError(error.message));
7438
+ return;
7439
+ }
7440
+ try {
7441
+ const message = await _updateFieldById({ _id, field, value });
7442
+ res.json({ message });
7443
+ return;
7444
+ } catch (error2) {
7445
+ next(error2);
7446
+ }
7447
+ }
7448
+ async function deleteById(req, res, next) {
7449
+ const _id = req.params.id;
7450
+ const validation = import_joi19.default.object({
7451
+ _id: import_joi19.default.string().hex().required()
7452
+ });
7453
+ const { error } = validation.validate({ _id });
7454
+ if (error) {
7455
+ next(new import_nodejs_utils40.BadRequestError(error.message));
7456
+ return;
7457
+ }
7458
+ try {
7459
+ const message = await _deleteById(_id);
7460
+ res.json({ message });
7461
+ return;
7462
+ } catch (error2) {
7463
+ next(error2);
7464
+ }
7465
+ }
7466
+ return {
7467
+ add,
7468
+ getAll,
7469
+ getById,
7470
+ getByName,
7471
+ updateField,
7472
+ deleteById
7473
+ };
7474
+ }
7310
7475
  // Annotate the CommonJS export names for ESM import in node:
7311
7476
  0 && (module.exports = {
7312
7477
  ACCESS_TOKEN_EXPIRY,
@@ -7389,6 +7554,7 @@ function usePSGCRepo() {
7389
7554
  useOrgController,
7390
7555
  useOrgRepo,
7391
7556
  useOrgService,
7557
+ usePSGCController,
7392
7558
  usePSGCRepo,
7393
7559
  useRoleController,
7394
7560
  useRoleRepo,