@eeplatform/core 1.7.2 → 1.8.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 +18 -0
- package/dist/index.d.ts +45 -2
- package/dist/index.js +311 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +319 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
- package/demo-transcription.js +0 -145
- package/test-first-phoneme.js +0 -92
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @eeplatform/core
|
|
2
2
|
|
|
3
|
+
## 1.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- de639da: PSGC mgmt - initial release
|
|
8
|
+
|
|
9
|
+
## 1.7.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 8816b2d: Add optional cache clear params to role repo
|
|
14
|
+
|
|
15
|
+
## 1.7.3
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 36493af: Add new services
|
|
20
|
+
|
|
3
21
|
## 1.7.2
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -281,7 +281,7 @@ declare function useRoleRepo(): {
|
|
|
281
281
|
createIndex: () => Promise<void>;
|
|
282
282
|
createTextIndex: () => Promise<void>;
|
|
283
283
|
createUniqueIndex: () => Promise<void>;
|
|
284
|
-
addRole: (value: TRole, session?: ClientSession) => Promise<ObjectId>;
|
|
284
|
+
addRole: (value: TRole, session?: ClientSession, clearCache?: boolean) => Promise<ObjectId>;
|
|
285
285
|
getRoles: ({ search, page, limit, sort, type, id, }?: {
|
|
286
286
|
search?: string;
|
|
287
287
|
page?: number;
|
|
@@ -300,6 +300,7 @@ declare function useRoleRepo(): {
|
|
|
300
300
|
updateRole: (_id: string | ObjectId, value: TMiniRole, session?: ClientSession) => Promise<string>;
|
|
301
301
|
deleteRole: (_id: ObjectId | string, session?: ClientSession) => Promise<string>;
|
|
302
302
|
updatePermissionsById: (_id: string | ObjectId, permissions: TRole["permissions"], session?: ClientSession) => Promise<string>;
|
|
303
|
+
delCachedData: () => void;
|
|
303
304
|
};
|
|
304
305
|
|
|
305
306
|
declare function useRoleController(): {
|
|
@@ -873,6 +874,48 @@ declare function useUtilController(): {
|
|
|
873
874
|
|
|
874
875
|
declare const transactionSchema: Joi.ObjectSchema<any>;
|
|
875
876
|
|
|
877
|
+
type TPSGC = {
|
|
878
|
+
_id?: ObjectId;
|
|
879
|
+
code: number;
|
|
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, status, }?: {
|
|
894
|
+
search?: string | undefined;
|
|
895
|
+
page?: number | undefined;
|
|
896
|
+
limit?: number | undefined;
|
|
897
|
+
sort?: {} | undefined;
|
|
898
|
+
status?: string | undefined;
|
|
899
|
+
}) => Promise<Record<string, any> | {
|
|
900
|
+
items: any[];
|
|
901
|
+
pages: number;
|
|
902
|
+
pageRange: string;
|
|
903
|
+
}>;
|
|
904
|
+
getById: (_id: string | ObjectId) => Promise<TPSGC>;
|
|
905
|
+
updateFieldById: ({ _id, field, value }?: {
|
|
906
|
+
_id: string | ObjectId;
|
|
907
|
+
field: string;
|
|
908
|
+
value: string;
|
|
909
|
+
}, session?: ClientSession) => Promise<string>;
|
|
910
|
+
deleteById: (_id: string | ObjectId) => Promise<string>;
|
|
911
|
+
getByName: ({ name, cityMunicipality, code, type }?: {
|
|
912
|
+
name: string;
|
|
913
|
+
cityMunicipality?: boolean;
|
|
914
|
+
code?: number;
|
|
915
|
+
type?: string;
|
|
916
|
+
}) => Promise<TPSGC | null>;
|
|
917
|
+
};
|
|
918
|
+
|
|
876
919
|
declare const MONGO_URI: string;
|
|
877
920
|
declare const MONGO_DB: string;
|
|
878
921
|
declare const PORT: number;
|
|
@@ -912,4 +955,4 @@ declare const GEMINI_API_KEY: string;
|
|
|
912
955
|
declare const ASSEMBLY_AI_API_KEY: string;
|
|
913
956
|
declare const DOMAIN: string;
|
|
914
957
|
|
|
915
|
-
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 };
|
|
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 };
|
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,7 @@ __export(src_exports, {
|
|
|
108
110
|
useOrgController: () => useOrgController,
|
|
109
111
|
useOrgRepo: () => useOrgRepo,
|
|
110
112
|
useOrgService: () => useOrgService,
|
|
113
|
+
usePSGCRepo: () => usePSGCRepo,
|
|
111
114
|
useRoleController: () => useRoleController,
|
|
112
115
|
useRoleRepo: () => useRoleRepo,
|
|
113
116
|
useTokenRepo: () => useTokenRepo,
|
|
@@ -2221,11 +2224,13 @@ function useRoleRepo() {
|
|
|
2221
2224
|
throw new import_nodejs_utils10.InternalServerError("Failed to create unique index on role.");
|
|
2222
2225
|
}
|
|
2223
2226
|
}
|
|
2224
|
-
async function addRole(value, session) {
|
|
2227
|
+
async function addRole(value, session, clearCache = true) {
|
|
2225
2228
|
value = new MRole(value);
|
|
2226
2229
|
try {
|
|
2227
2230
|
const res = await collection.insertOne(value, { session });
|
|
2228
|
-
|
|
2231
|
+
if (clearCache) {
|
|
2232
|
+
delCachedData();
|
|
2233
|
+
}
|
|
2229
2234
|
return res.insertedId;
|
|
2230
2235
|
} catch (error) {
|
|
2231
2236
|
import_nodejs_utils10.logger.log({ level: "error", message: `${error}` });
|
|
@@ -2498,7 +2503,8 @@ function useRoleRepo() {
|
|
|
2498
2503
|
getRoleByName,
|
|
2499
2504
|
updateRole,
|
|
2500
2505
|
deleteRole,
|
|
2501
|
-
updatePermissionsById
|
|
2506
|
+
updatePermissionsById,
|
|
2507
|
+
delCachedData
|
|
2502
2508
|
};
|
|
2503
2509
|
}
|
|
2504
2510
|
|
|
@@ -3875,6 +3881,7 @@ function useRoleController() {
|
|
|
3875
3881
|
// src/resources/file/file.service.ts
|
|
3876
3882
|
var import_nodejs_utils19 = require("@eeplatform/nodejs-utils");
|
|
3877
3883
|
var import_node_cron = __toESM(require("node-cron"));
|
|
3884
|
+
var fs = __toESM(require("fs"));
|
|
3878
3885
|
function useFileService() {
|
|
3879
3886
|
const {
|
|
3880
3887
|
createFile: _createFile,
|
|
@@ -3898,12 +3905,23 @@ function useFileService() {
|
|
|
3898
3905
|
};
|
|
3899
3906
|
try {
|
|
3900
3907
|
const id = await _createFile(file, session);
|
|
3908
|
+
const fileBuffer = value.buffer || await fs.promises.readFile(value.path);
|
|
3901
3909
|
await s3.uploadObject({
|
|
3902
3910
|
key: id,
|
|
3903
|
-
body:
|
|
3911
|
+
body: fileBuffer,
|
|
3904
3912
|
contentType: value.mimetype
|
|
3905
3913
|
});
|
|
3906
3914
|
await session?.commitTransaction();
|
|
3915
|
+
if (value.path) {
|
|
3916
|
+
try {
|
|
3917
|
+
await fs.promises.unlink(value.path);
|
|
3918
|
+
} catch (cleanupError) {
|
|
3919
|
+
console.error(
|
|
3920
|
+
`Failed to cleanup temporary file ${value.path}:`,
|
|
3921
|
+
cleanupError
|
|
3922
|
+
);
|
|
3923
|
+
}
|
|
3924
|
+
}
|
|
3907
3925
|
return id;
|
|
3908
3926
|
} catch (error) {
|
|
3909
3927
|
await session?.abortTransaction();
|
|
@@ -6257,7 +6275,7 @@ function useGitHubService() {
|
|
|
6257
6275
|
const octokit = new import_rest.Octokit({ auth: githubToken });
|
|
6258
6276
|
const { owner, repo } = parseRepoUrl(repoUrl);
|
|
6259
6277
|
await checkAdminPermission(owner, repo, octokit);
|
|
6260
|
-
const lines = keyValues.split(
|
|
6278
|
+
const lines = keyValues.split(";").map((l) => l.trim()).filter(Boolean);
|
|
6261
6279
|
for (const line of lines) {
|
|
6262
6280
|
const equalIndex = line.indexOf("=");
|
|
6263
6281
|
if (equalIndex === -1)
|
|
@@ -6873,7 +6891,7 @@ function useUtilController() {
|
|
|
6873
6891
|
availableEndpoints: [
|
|
6874
6892
|
"POST /github/variables - Set GitHub environment variables or secrets"
|
|
6875
6893
|
],
|
|
6876
|
-
keyValueFormat: "KEY=value pairs separated by
|
|
6894
|
+
keyValueFormat: "KEY=value pairs separated by semicolons"
|
|
6877
6895
|
}
|
|
6878
6896
|
});
|
|
6879
6897
|
} catch (error) {
|
|
@@ -6927,14 +6945,14 @@ function useUtilController() {
|
|
|
6927
6945
|
);
|
|
6928
6946
|
return;
|
|
6929
6947
|
}
|
|
6930
|
-
const lines = keyValues.split(
|
|
6948
|
+
const lines = keyValues.split(";").map((l) => l.trim()).filter(Boolean);
|
|
6931
6949
|
const invalidLines = lines.filter(
|
|
6932
6950
|
(line) => !line.includes("=") || line.indexOf("=") === -1
|
|
6933
6951
|
);
|
|
6934
6952
|
if (invalidLines.length > 0) {
|
|
6935
6953
|
next(
|
|
6936
6954
|
new import_nodejs_utils38.BadRequestError(
|
|
6937
|
-
"Invalid key-value format. Each pair should be in format: KEY=value. Pairs
|
|
6955
|
+
"Invalid key-value format. Each pair should be in format: KEY=value. Pairs should be separated by semicolons."
|
|
6938
6956
|
)
|
|
6939
6957
|
);
|
|
6940
6958
|
return;
|
|
@@ -7007,6 +7025,288 @@ var transactionSchema = import_joi17.default.object({
|
|
|
7007
7025
|
updatedAt: import_joi17.default.string().optional().allow("", null),
|
|
7008
7026
|
deletedAt: import_joi17.default.string().optional().allow("", null)
|
|
7009
7027
|
});
|
|
7028
|
+
|
|
7029
|
+
// src/resources/phillipine-std-geo-code/psgc.model.ts
|
|
7030
|
+
var import_joi18 = __toESM(require("joi"));
|
|
7031
|
+
var schemaPSGC = import_joi18.default.object({
|
|
7032
|
+
code: import_joi18.default.number().required(),
|
|
7033
|
+
name: import_joi18.default.string().required(),
|
|
7034
|
+
type: import_joi18.default.string().valid("Reg", "Prov", "City", "Mun", "Bgy").required()
|
|
7035
|
+
});
|
|
7036
|
+
function modelPSGC(data) {
|
|
7037
|
+
const { error } = schemaPSGC.validate(data);
|
|
7038
|
+
if (error) {
|
|
7039
|
+
throw new Error(`Invalid PSGC data: ${error.message}`);
|
|
7040
|
+
}
|
|
7041
|
+
return {
|
|
7042
|
+
code: data.code,
|
|
7043
|
+
name: data.name,
|
|
7044
|
+
type: data.type
|
|
7045
|
+
};
|
|
7046
|
+
}
|
|
7047
|
+
|
|
7048
|
+
// src/resources/phillipine-std-geo-code/psgc.repository.ts
|
|
7049
|
+
var import_nodejs_utils39 = require("@eeplatform/nodejs-utils");
|
|
7050
|
+
var import_mongodb21 = require("mongodb");
|
|
7051
|
+
function usePSGCRepo() {
|
|
7052
|
+
const db = import_nodejs_utils39.useAtlas.getDb();
|
|
7053
|
+
if (!db) {
|
|
7054
|
+
throw new Error("Unable to connect to server.");
|
|
7055
|
+
}
|
|
7056
|
+
const namespace_collection = "philippine.standard.geographic.codes";
|
|
7057
|
+
const collection = db.collection(namespace_collection);
|
|
7058
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils39.useCache)(namespace_collection);
|
|
7059
|
+
async function createIndexes() {
|
|
7060
|
+
try {
|
|
7061
|
+
await collection.createIndexes([
|
|
7062
|
+
{ key: { name: 1 } },
|
|
7063
|
+
{ key: { name: "text" } },
|
|
7064
|
+
{ key: { code: 1 }, unique: true, name: "unique_code" }
|
|
7065
|
+
]);
|
|
7066
|
+
} catch (error) {
|
|
7067
|
+
throw new Error("Failed to create index on PSGC.");
|
|
7068
|
+
}
|
|
7069
|
+
}
|
|
7070
|
+
function delCachedData() {
|
|
7071
|
+
delNamespace().then(() => {
|
|
7072
|
+
import_nodejs_utils39.logger.log({
|
|
7073
|
+
level: "info",
|
|
7074
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
7075
|
+
});
|
|
7076
|
+
}).catch((err) => {
|
|
7077
|
+
import_nodejs_utils39.logger.log({
|
|
7078
|
+
level: "error",
|
|
7079
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
7080
|
+
});
|
|
7081
|
+
});
|
|
7082
|
+
}
|
|
7083
|
+
async function add(value, session) {
|
|
7084
|
+
try {
|
|
7085
|
+
value = modelPSGC(value);
|
|
7086
|
+
const res = await collection.insertOne(value, { session });
|
|
7087
|
+
delCachedData();
|
|
7088
|
+
return res.insertedId;
|
|
7089
|
+
} catch (error) {
|
|
7090
|
+
import_nodejs_utils39.logger.log({
|
|
7091
|
+
level: "error",
|
|
7092
|
+
message: error.message
|
|
7093
|
+
});
|
|
7094
|
+
if (error instanceof import_nodejs_utils39.AppError) {
|
|
7095
|
+
throw error;
|
|
7096
|
+
} else {
|
|
7097
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
7098
|
+
if (isDuplicated) {
|
|
7099
|
+
throw new import_nodejs_utils39.BadRequestError("Region already exists.");
|
|
7100
|
+
}
|
|
7101
|
+
throw new Error("Failed to create PSGC.");
|
|
7102
|
+
}
|
|
7103
|
+
}
|
|
7104
|
+
}
|
|
7105
|
+
async function getAll({
|
|
7106
|
+
search = "",
|
|
7107
|
+
page = 1,
|
|
7108
|
+
limit = 10,
|
|
7109
|
+
sort = {},
|
|
7110
|
+
status = "active"
|
|
7111
|
+
} = {}) {
|
|
7112
|
+
page = page > 0 ? page - 1 : 0;
|
|
7113
|
+
const query = {
|
|
7114
|
+
deletedAt: { $in: ["", null] },
|
|
7115
|
+
status
|
|
7116
|
+
};
|
|
7117
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: 1 };
|
|
7118
|
+
const cacheKeyOptions = {
|
|
7119
|
+
status,
|
|
7120
|
+
page,
|
|
7121
|
+
limit,
|
|
7122
|
+
sort: JSON.stringify(sort)
|
|
7123
|
+
};
|
|
7124
|
+
if (search) {
|
|
7125
|
+
query.$text = { $search: search };
|
|
7126
|
+
cacheKeyOptions.search = search;
|
|
7127
|
+
}
|
|
7128
|
+
const cacheKey = (0, import_nodejs_utils39.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
7129
|
+
import_nodejs_utils39.logger.log({
|
|
7130
|
+
level: "info",
|
|
7131
|
+
message: `Cache key for getAll PSGC: ${cacheKey}`
|
|
7132
|
+
});
|
|
7133
|
+
try {
|
|
7134
|
+
const cached = await getCache(cacheKey);
|
|
7135
|
+
if (cached) {
|
|
7136
|
+
import_nodejs_utils39.logger.log({
|
|
7137
|
+
level: "info",
|
|
7138
|
+
message: `Cache hit for getAll PSGC: ${cacheKey}`
|
|
7139
|
+
});
|
|
7140
|
+
return cached;
|
|
7141
|
+
}
|
|
7142
|
+
const items = await collection.aggregate([
|
|
7143
|
+
{ $match: query },
|
|
7144
|
+
{ $sort: sort },
|
|
7145
|
+
{ $skip: page * limit },
|
|
7146
|
+
{ $limit: limit }
|
|
7147
|
+
]).toArray();
|
|
7148
|
+
const length = await collection.countDocuments(query);
|
|
7149
|
+
const data = (0, import_nodejs_utils39.paginate)(items, page, limit, length);
|
|
7150
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
7151
|
+
import_nodejs_utils39.logger.log({
|
|
7152
|
+
level: "info",
|
|
7153
|
+
message: `Cache set for getAll PSGC: ${cacheKey}`
|
|
7154
|
+
});
|
|
7155
|
+
}).catch((err) => {
|
|
7156
|
+
import_nodejs_utils39.logger.log({
|
|
7157
|
+
level: "error",
|
|
7158
|
+
message: `Failed to set cache for getAll PSGC: ${err.message}`
|
|
7159
|
+
});
|
|
7160
|
+
});
|
|
7161
|
+
return data;
|
|
7162
|
+
} catch (error) {
|
|
7163
|
+
import_nodejs_utils39.logger.log({ level: "error", message: `${error}` });
|
|
7164
|
+
throw error;
|
|
7165
|
+
}
|
|
7166
|
+
}
|
|
7167
|
+
async function getById(_id) {
|
|
7168
|
+
try {
|
|
7169
|
+
_id = new import_mongodb21.ObjectId(_id);
|
|
7170
|
+
} catch (error) {
|
|
7171
|
+
throw new import_nodejs_utils39.BadRequestError("Invalid ID.");
|
|
7172
|
+
}
|
|
7173
|
+
const cacheKey = (0, import_nodejs_utils39.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
7174
|
+
try {
|
|
7175
|
+
const cached = await getCache(cacheKey);
|
|
7176
|
+
if (cached) {
|
|
7177
|
+
import_nodejs_utils39.logger.log({
|
|
7178
|
+
level: "info",
|
|
7179
|
+
message: `Cache hit for getById PSGC: ${cacheKey}`
|
|
7180
|
+
});
|
|
7181
|
+
return cached;
|
|
7182
|
+
}
|
|
7183
|
+
const result = await collection.findOne({
|
|
7184
|
+
_id,
|
|
7185
|
+
deletedAt: { $in: ["", null] }
|
|
7186
|
+
});
|
|
7187
|
+
if (!result) {
|
|
7188
|
+
throw new import_nodejs_utils39.BadRequestError("Region not found.");
|
|
7189
|
+
}
|
|
7190
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
7191
|
+
import_nodejs_utils39.logger.log({
|
|
7192
|
+
level: "info",
|
|
7193
|
+
message: `Cache set for PSGC by id: ${cacheKey}`
|
|
7194
|
+
});
|
|
7195
|
+
}).catch((err) => {
|
|
7196
|
+
import_nodejs_utils39.logger.log({
|
|
7197
|
+
level: "error",
|
|
7198
|
+
message: `Failed to set cache for PSGC by id: ${err.message}`
|
|
7199
|
+
});
|
|
7200
|
+
});
|
|
7201
|
+
return result;
|
|
7202
|
+
} catch (error) {
|
|
7203
|
+
if (error instanceof import_nodejs_utils39.AppError) {
|
|
7204
|
+
throw error;
|
|
7205
|
+
} else {
|
|
7206
|
+
throw new import_nodejs_utils39.InternalServerError("Failed to get PSGC.");
|
|
7207
|
+
}
|
|
7208
|
+
}
|
|
7209
|
+
}
|
|
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;
|
|
7216
|
+
}
|
|
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;
|
|
7227
|
+
}
|
|
7228
|
+
const cacheKey = (0, import_nodejs_utils39.makeCacheKey)(namespace_collection, { name });
|
|
7229
|
+
try {
|
|
7230
|
+
const cached = await getCache(cacheKey);
|
|
7231
|
+
if (cached) {
|
|
7232
|
+
import_nodejs_utils39.logger.log({
|
|
7233
|
+
level: "info",
|
|
7234
|
+
message: `Cache hit for getByName PSGC: ${cacheKey}`
|
|
7235
|
+
});
|
|
7236
|
+
return cached;
|
|
7237
|
+
}
|
|
7238
|
+
const result = await collection.findOne(query);
|
|
7239
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
7240
|
+
import_nodejs_utils39.logger.log({
|
|
7241
|
+
level: "info",
|
|
7242
|
+
message: `Cache set for PSGC by name: ${cacheKey}`
|
|
7243
|
+
});
|
|
7244
|
+
}).catch((err) => {
|
|
7245
|
+
import_nodejs_utils39.logger.log({
|
|
7246
|
+
level: "error",
|
|
7247
|
+
message: `Failed to set cache for PSGC by name: ${err.message}`
|
|
7248
|
+
});
|
|
7249
|
+
});
|
|
7250
|
+
return result;
|
|
7251
|
+
} catch (error) {
|
|
7252
|
+
if (error instanceof import_nodejs_utils39.AppError) {
|
|
7253
|
+
throw error;
|
|
7254
|
+
} else {
|
|
7255
|
+
throw new import_nodejs_utils39.InternalServerError("Failed to get PSGC.");
|
|
7256
|
+
}
|
|
7257
|
+
}
|
|
7258
|
+
}
|
|
7259
|
+
async function updateFieldById({ _id, field, value } = {}, session) {
|
|
7260
|
+
const allowedFields = ["name"];
|
|
7261
|
+
if (!allowedFields.includes(field)) {
|
|
7262
|
+
throw new import_nodejs_utils39.BadRequestError(
|
|
7263
|
+
`Field "${field}" is not allowed to be updated.`
|
|
7264
|
+
);
|
|
7265
|
+
}
|
|
7266
|
+
try {
|
|
7267
|
+
_id = new import_mongodb21.ObjectId(_id);
|
|
7268
|
+
} catch (error) {
|
|
7269
|
+
throw new import_nodejs_utils39.BadRequestError("Invalid ID.");
|
|
7270
|
+
}
|
|
7271
|
+
try {
|
|
7272
|
+
await collection.updateOne(
|
|
7273
|
+
{ _id, deletedAt: { $in: ["", null] } },
|
|
7274
|
+
{ $set: { [field]: value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
7275
|
+
{ session }
|
|
7276
|
+
);
|
|
7277
|
+
delCachedData();
|
|
7278
|
+
return `Successfully updated PSGC ${field}.`;
|
|
7279
|
+
} catch (error) {
|
|
7280
|
+
throw new import_nodejs_utils39.InternalServerError(`Failed to update PSGC ${field}.`);
|
|
7281
|
+
}
|
|
7282
|
+
}
|
|
7283
|
+
async function deleteById(_id) {
|
|
7284
|
+
try {
|
|
7285
|
+
_id = new import_mongodb21.ObjectId(_id);
|
|
7286
|
+
} catch (error) {
|
|
7287
|
+
throw new import_nodejs_utils39.BadRequestError("Invalid ID.");
|
|
7288
|
+
}
|
|
7289
|
+
try {
|
|
7290
|
+
await collection.updateOne(
|
|
7291
|
+
{ _id },
|
|
7292
|
+
{ $set: { status: "deleted", deletedAt: (/* @__PURE__ */ new Date()).toISOString() } }
|
|
7293
|
+
);
|
|
7294
|
+
delCachedData();
|
|
7295
|
+
return "Successfully deleted PSGC.";
|
|
7296
|
+
} catch (error) {
|
|
7297
|
+
throw new import_nodejs_utils39.InternalServerError("Failed to delete PSGC.");
|
|
7298
|
+
}
|
|
7299
|
+
}
|
|
7300
|
+
return {
|
|
7301
|
+
createIndexes,
|
|
7302
|
+
add,
|
|
7303
|
+
getAll,
|
|
7304
|
+
getById,
|
|
7305
|
+
updateFieldById,
|
|
7306
|
+
deleteById,
|
|
7307
|
+
getByName
|
|
7308
|
+
};
|
|
7309
|
+
}
|
|
7010
7310
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7011
7311
|
0 && (module.exports = {
|
|
7012
7312
|
ACCESS_TOKEN_EXPIRY,
|
|
@@ -7059,9 +7359,11 @@ var transactionSchema = import_joi17.default.object({
|
|
|
7059
7359
|
XENDIT_SECRET_KEY,
|
|
7060
7360
|
addressSchema,
|
|
7061
7361
|
isDev,
|
|
7362
|
+
modelPSGC,
|
|
7062
7363
|
schemaBuilding,
|
|
7063
7364
|
schemaBuildingUnit,
|
|
7064
7365
|
schemaOrg,
|
|
7366
|
+
schemaPSGC,
|
|
7065
7367
|
schemaUpdateOptions,
|
|
7066
7368
|
transactionSchema,
|
|
7067
7369
|
useAddressController,
|
|
@@ -7087,6 +7389,7 @@ var transactionSchema = import_joi17.default.object({
|
|
|
7087
7389
|
useOrgController,
|
|
7088
7390
|
useOrgRepo,
|
|
7089
7391
|
useOrgService,
|
|
7392
|
+
usePSGCRepo,
|
|
7090
7393
|
useRoleController,
|
|
7091
7394
|
useRoleRepo,
|
|
7092
7395
|
useTokenRepo,
|