@eeplatform/core 1.7.4 → 1.8.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
  # @eeplatform/core
2
2
 
3
+ ## 1.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - aff1249: Revise PSGC implementation
8
+
9
+ ## 1.8.0
10
+
11
+ ### Minor Changes
12
+
13
+ - de639da: PSGC mgmt - initial release
14
+
3
15
  ## 1.7.4
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -874,6 +874,57 @@ declare function useUtilController(): {
874
874
 
875
875
  declare const transactionSchema: Joi.ObjectSchema<any>;
876
876
 
877
+ type TPSGC = {
878
+ _id?: ObjectId;
879
+ code: string;
880
+ name: string;
881
+ type: string;
882
+ };
883
+ declare const schemaPSGC: Joi.ObjectSchema<any>;
884
+ declare function modelPSGC(data: any): {
885
+ code: any;
886
+ name: any;
887
+ type: any;
888
+ };
889
+
890
+ declare function usePSGCRepo(): {
891
+ createIndexes: () => Promise<void>;
892
+ add: (value: TPSGC, session?: ClientSession) => Promise<ObjectId>;
893
+ getAll: ({ search, page, limit, sort, type, prefix, }?: {
894
+ search?: string | undefined;
895
+ page?: number | undefined;
896
+ limit?: number | undefined;
897
+ sort?: {} | undefined;
898
+ type?: string | undefined;
899
+ prefix?: string | undefined;
900
+ }) => Promise<Record<string, any> | {
901
+ items: any[];
902
+ pages: number;
903
+ pageRange: string;
904
+ }>;
905
+ getById: (_id: string | ObjectId) => Promise<TPSGC>;
906
+ updateFieldById: ({ _id, field, value }?: {
907
+ _id: string | ObjectId;
908
+ field: string;
909
+ value: string;
910
+ }, session?: ClientSession) => Promise<string>;
911
+ deleteById: (_id: string | ObjectId) => Promise<string>;
912
+ getByName: ({ name, prefix, type }?: {
913
+ name: string;
914
+ prefix?: string;
915
+ type?: string;
916
+ }) => Promise<TPSGC | null>;
917
+ };
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
+
877
928
  declare const MONGO_URI: string;
878
929
  declare const MONGO_DB: string;
879
930
  declare const PORT: number;
@@ -913,4 +964,4 @@ declare const GEMINI_API_KEY: string;
913
964
  declare const ASSEMBLY_AI_API_KEY: string;
914
965
  declare const DOMAIN: string;
915
966
 
916
- 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, TRole, TToken, TUser, TUserRole, TVerification, TVerificationMetadata, VERIFICATION_FORGET_PASSWORD_DURATION, VERIFICATION_USER_INVITE_DURATION, XENDIT_BASE_URL, XENDIT_SECRET_KEY, addressSchema, isDev, schemaBuilding, schemaBuildingUnit, schemaOrg, 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, 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
@@ -80,9 +80,11 @@ __export(src_exports, {
80
80
  XENDIT_SECRET_KEY: () => XENDIT_SECRET_KEY,
81
81
  addressSchema: () => addressSchema,
82
82
  isDev: () => isDev,
83
+ modelPSGC: () => modelPSGC,
83
84
  schemaBuilding: () => schemaBuilding,
84
85
  schemaBuildingUnit: () => schemaBuildingUnit,
85
86
  schemaOrg: () => schemaOrg,
87
+ schemaPSGC: () => schemaPSGC,
86
88
  schemaUpdateOptions: () => schemaUpdateOptions,
87
89
  transactionSchema: () => transactionSchema,
88
90
  useAddressController: () => useAddressController,
@@ -108,6 +110,8 @@ __export(src_exports, {
108
110
  useOrgController: () => useOrgController,
109
111
  useOrgRepo: () => useOrgRepo,
110
112
  useOrgService: () => useOrgService,
113
+ usePSGCController: () => usePSGCController,
114
+ usePSGCRepo: () => usePSGCRepo,
111
115
  useRoleController: () => useRoleController,
112
116
  useRoleRepo: () => useRoleRepo,
113
117
  useTokenRepo: () => useTokenRepo,
@@ -7022,6 +7026,452 @@ var transactionSchema = import_joi17.default.object({
7022
7026
  updatedAt: import_joi17.default.string().optional().allow("", null),
7023
7027
  deletedAt: import_joi17.default.string().optional().allow("", null)
7024
7028
  });
7029
+
7030
+ // src/resources/psgc/psgc.model.ts
7031
+ var import_joi18 = __toESM(require("joi"));
7032
+ var schemaPSGC = import_joi18.default.object({
7033
+ code: import_joi18.default.string().length(10).required(),
7034
+ name: import_joi18.default.string().required(),
7035
+ type: import_joi18.default.string().valid("Reg", "Prov", "City", "Mun", "Bgy").required()
7036
+ });
7037
+ function modelPSGC(data) {
7038
+ const { error } = schemaPSGC.validate(data);
7039
+ if (error) {
7040
+ throw new Error(`Invalid PSGC data: ${error.message}`);
7041
+ }
7042
+ return {
7043
+ code: data.code,
7044
+ name: data.name,
7045
+ type: data.type
7046
+ };
7047
+ }
7048
+
7049
+ // src/resources/psgc/psgc.repository.ts
7050
+ var import_nodejs_utils39 = require("@eeplatform/nodejs-utils");
7051
+ var import_mongodb21 = require("mongodb");
7052
+ function usePSGCRepo() {
7053
+ const db = import_nodejs_utils39.useAtlas.getDb();
7054
+ if (!db) {
7055
+ throw new Error("Unable to connect to server.");
7056
+ }
7057
+ const namespace_collection = "psgc";
7058
+ const collection = db.collection(namespace_collection);
7059
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils39.useCache)(namespace_collection);
7060
+ async function createIndexes() {
7061
+ try {
7062
+ await collection.createIndexes([
7063
+ { key: { name: 1 } },
7064
+ { key: { name: "text" } },
7065
+ { key: { code: 1 }, unique: true, name: "unique_code" }
7066
+ ]);
7067
+ } catch (error) {
7068
+ throw new Error("Failed to create index on PSGC.");
7069
+ }
7070
+ }
7071
+ function delCachedData() {
7072
+ delNamespace().then(() => {
7073
+ import_nodejs_utils39.logger.log({
7074
+ level: "info",
7075
+ message: `Cache namespace cleared for ${namespace_collection}`
7076
+ });
7077
+ }).catch((err) => {
7078
+ import_nodejs_utils39.logger.log({
7079
+ level: "error",
7080
+ message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
7081
+ });
7082
+ });
7083
+ }
7084
+ async function add(value, session) {
7085
+ try {
7086
+ value = modelPSGC(value);
7087
+ const res = await collection.insertOne(value, { session });
7088
+ delCachedData();
7089
+ return res.insertedId;
7090
+ } catch (error) {
7091
+ import_nodejs_utils39.logger.log({
7092
+ level: "error",
7093
+ message: error.message
7094
+ });
7095
+ if (error instanceof import_nodejs_utils39.AppError) {
7096
+ throw error;
7097
+ } else {
7098
+ const isDuplicated = error.message.includes("duplicate");
7099
+ if (isDuplicated) {
7100
+ throw new import_nodejs_utils39.BadRequestError("Region already exists.");
7101
+ }
7102
+ throw new Error("Failed to create PSGC.");
7103
+ }
7104
+ }
7105
+ }
7106
+ async function getAll({
7107
+ search = "",
7108
+ page = 1,
7109
+ limit = 10,
7110
+ sort = {},
7111
+ type = "",
7112
+ prefix = ""
7113
+ } = {}) {
7114
+ page = page > 0 ? page - 1 : 0;
7115
+ const query = {
7116
+ type
7117
+ };
7118
+ const cacheKeyOptions = {
7119
+ type,
7120
+ page,
7121
+ limit,
7122
+ sort: JSON.stringify(sort)
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 };
7132
+ if (search) {
7133
+ query.$text = { $search: search };
7134
+ cacheKeyOptions.search = search;
7135
+ }
7136
+ const cacheKey = (0, import_nodejs_utils39.makeCacheKey)(namespace_collection, cacheKeyOptions);
7137
+ import_nodejs_utils39.logger.log({
7138
+ level: "info",
7139
+ message: `Cache key for getAll PSGC: ${cacheKey}`
7140
+ });
7141
+ try {
7142
+ const cached = await getCache(cacheKey);
7143
+ if (cached) {
7144
+ import_nodejs_utils39.logger.log({
7145
+ level: "info",
7146
+ message: `Cache hit for getAll PSGC: ${cacheKey}`
7147
+ });
7148
+ return cached;
7149
+ }
7150
+ const items = await collection.aggregate([
7151
+ { $match: query },
7152
+ { $sort: sort },
7153
+ { $skip: page * limit },
7154
+ { $limit: limit }
7155
+ ]).toArray();
7156
+ const length = await collection.countDocuments(query);
7157
+ const data = (0, import_nodejs_utils39.paginate)(items, page, limit, length);
7158
+ setCache(cacheKey, data, 600).then(() => {
7159
+ import_nodejs_utils39.logger.log({
7160
+ level: "info",
7161
+ message: `Cache set for getAll PSGC: ${cacheKey}`
7162
+ });
7163
+ }).catch((err) => {
7164
+ import_nodejs_utils39.logger.log({
7165
+ level: "error",
7166
+ message: `Failed to set cache for getAll PSGC: ${err.message}`
7167
+ });
7168
+ });
7169
+ return data;
7170
+ } catch (error) {
7171
+ import_nodejs_utils39.logger.log({ level: "error", message: `${error}` });
7172
+ throw error;
7173
+ }
7174
+ }
7175
+ async function getById(_id) {
7176
+ try {
7177
+ _id = new import_mongodb21.ObjectId(_id);
7178
+ } catch (error) {
7179
+ throw new import_nodejs_utils39.BadRequestError("Invalid ID.");
7180
+ }
7181
+ const cacheKey = (0, import_nodejs_utils39.makeCacheKey)(namespace_collection, { _id: String(_id) });
7182
+ try {
7183
+ const cached = await getCache(cacheKey);
7184
+ if (cached) {
7185
+ import_nodejs_utils39.logger.log({
7186
+ level: "info",
7187
+ message: `Cache hit for getById PSGC: ${cacheKey}`
7188
+ });
7189
+ return cached;
7190
+ }
7191
+ const result = await collection.findOne({
7192
+ _id,
7193
+ deletedAt: { $in: ["", null] }
7194
+ });
7195
+ if (!result) {
7196
+ throw new import_nodejs_utils39.BadRequestError("Region not found.");
7197
+ }
7198
+ setCache(cacheKey, result, 300).then(() => {
7199
+ import_nodejs_utils39.logger.log({
7200
+ level: "info",
7201
+ message: `Cache set for PSGC by id: ${cacheKey}`
7202
+ });
7203
+ }).catch((err) => {
7204
+ import_nodejs_utils39.logger.log({
7205
+ level: "error",
7206
+ message: `Failed to set cache for PSGC by id: ${err.message}`
7207
+ });
7208
+ });
7209
+ return result;
7210
+ } catch (error) {
7211
+ if (error instanceof import_nodejs_utils39.AppError) {
7212
+ throw error;
7213
+ } else {
7214
+ throw new import_nodejs_utils39.InternalServerError("Failed to get PSGC.");
7215
+ }
7216
+ }
7217
+ }
7218
+ async function getByName({ name, prefix = "", type = "" } = {}) {
7219
+ const query = { $text: { $search: name } };
7220
+ const cacheKeyOptions = { name };
7221
+ if (["City", "Mun"].includes(type)) {
7222
+ query.type = { $in: ["City", "Mun"] };
7223
+ cacheKeyOptions.type = type;
7224
+ }
7225
+ if (prefix) {
7226
+ query.code = { $regex: `^${prefix}` };
7227
+ cacheKeyOptions.prefix = prefix;
7228
+ }
7229
+ const cacheKey = (0, import_nodejs_utils39.makeCacheKey)(namespace_collection, { name });
7230
+ try {
7231
+ const cached = await getCache(cacheKey);
7232
+ if (cached) {
7233
+ import_nodejs_utils39.logger.log({
7234
+ level: "info",
7235
+ message: `Cache hit for getByName PSGC: ${cacheKey}`
7236
+ });
7237
+ return cached;
7238
+ }
7239
+ const result = await collection.findOne(query);
7240
+ setCache(cacheKey, result, 300).then(() => {
7241
+ import_nodejs_utils39.logger.log({
7242
+ level: "info",
7243
+ message: `Cache set for PSGC by name: ${cacheKey}`
7244
+ });
7245
+ }).catch((err) => {
7246
+ import_nodejs_utils39.logger.log({
7247
+ level: "error",
7248
+ message: `Failed to set cache for PSGC by name: ${err.message}`
7249
+ });
7250
+ });
7251
+ return result;
7252
+ } catch (error) {
7253
+ if (error instanceof import_nodejs_utils39.AppError) {
7254
+ throw error;
7255
+ } else {
7256
+ throw new import_nodejs_utils39.InternalServerError("Failed to get PSGC.");
7257
+ }
7258
+ }
7259
+ }
7260
+ async function updateFieldById({ _id, field, value } = {}, session) {
7261
+ const allowedFields = ["name"];
7262
+ if (!allowedFields.includes(field)) {
7263
+ throw new import_nodejs_utils39.BadRequestError(
7264
+ `Field "${field}" is not allowed to be updated.`
7265
+ );
7266
+ }
7267
+ try {
7268
+ _id = new import_mongodb21.ObjectId(_id);
7269
+ } catch (error) {
7270
+ throw new import_nodejs_utils39.BadRequestError("Invalid ID.");
7271
+ }
7272
+ try {
7273
+ await collection.updateOne(
7274
+ { _id, deletedAt: { $in: ["", null] } },
7275
+ { $set: { [field]: value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
7276
+ { session }
7277
+ );
7278
+ delCachedData();
7279
+ return `Successfully updated PSGC ${field}.`;
7280
+ } catch (error) {
7281
+ throw new import_nodejs_utils39.InternalServerError(`Failed to update PSGC ${field}.`);
7282
+ }
7283
+ }
7284
+ async function deleteById(_id) {
7285
+ try {
7286
+ _id = new import_mongodb21.ObjectId(_id);
7287
+ } catch (error) {
7288
+ throw new import_nodejs_utils39.BadRequestError("Invalid ID.");
7289
+ }
7290
+ try {
7291
+ await collection.updateOne(
7292
+ { _id },
7293
+ { $set: { status: "deleted", deletedAt: (/* @__PURE__ */ new Date()).toISOString() } }
7294
+ );
7295
+ delCachedData();
7296
+ return "Successfully deleted PSGC.";
7297
+ } catch (error) {
7298
+ throw new import_nodejs_utils39.InternalServerError("Failed to delete PSGC.");
7299
+ }
7300
+ }
7301
+ return {
7302
+ createIndexes,
7303
+ add,
7304
+ getAll,
7305
+ getById,
7306
+ updateFieldById,
7307
+ deleteById,
7308
+ getByName
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
+ }
7025
7475
  // Annotate the CommonJS export names for ESM import in node:
7026
7476
  0 && (module.exports = {
7027
7477
  ACCESS_TOKEN_EXPIRY,
@@ -7074,9 +7524,11 @@ var transactionSchema = import_joi17.default.object({
7074
7524
  XENDIT_SECRET_KEY,
7075
7525
  addressSchema,
7076
7526
  isDev,
7527
+ modelPSGC,
7077
7528
  schemaBuilding,
7078
7529
  schemaBuildingUnit,
7079
7530
  schemaOrg,
7531
+ schemaPSGC,
7080
7532
  schemaUpdateOptions,
7081
7533
  transactionSchema,
7082
7534
  useAddressController,
@@ -7102,6 +7554,8 @@ var transactionSchema = import_joi17.default.object({
7102
7554
  useOrgController,
7103
7555
  useOrgRepo,
7104
7556
  useOrgService,
7557
+ usePSGCController,
7558
+ usePSGCRepo,
7105
7559
  useRoleController,
7106
7560
  useRoleRepo,
7107
7561
  useTokenRepo,