@eeplatform/core 1.4.3 → 1.4.4
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 +6 -0
- package/dist/index.d.ts +55 -1
- package/dist/index.js +694 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +702 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -11354,6 +11354,7 @@ __export(src_exports, {
|
|
|
11354
11354
|
MOrder: () => MOrder,
|
|
11355
11355
|
MOrg: () => MOrg,
|
|
11356
11356
|
MPaymentMethod: () => MPaymentMethod,
|
|
11357
|
+
MPlantilla: () => MPlantilla,
|
|
11357
11358
|
MPromoCode: () => MPromoCode,
|
|
11358
11359
|
MRegion: () => MRegion,
|
|
11359
11360
|
MRole: () => MRole,
|
|
@@ -11391,6 +11392,7 @@ __export(src_exports, {
|
|
|
11391
11392
|
schemaBuilding: () => schemaBuilding,
|
|
11392
11393
|
schemaBuildingUnit: () => schemaBuildingUnit,
|
|
11393
11394
|
schemaDivision: () => schemaDivision,
|
|
11395
|
+
schemaPlantilla: () => schemaPlantilla,
|
|
11394
11396
|
schemaRegion: () => schemaRegion,
|
|
11395
11397
|
schemaSchool: () => schemaSchool,
|
|
11396
11398
|
schemaStockCard: () => schemaStockCard,
|
|
@@ -11415,6 +11417,7 @@ __export(src_exports, {
|
|
|
11415
11417
|
useFileController: () => useFileController,
|
|
11416
11418
|
useFileRepo: () => useFileRepo,
|
|
11417
11419
|
useFileService: () => useFileService,
|
|
11420
|
+
useGitHubService: () => useGitHubService,
|
|
11418
11421
|
useInvoiceController: () => useInvoiceController,
|
|
11419
11422
|
useInvoiceModel: () => useInvoiceModel,
|
|
11420
11423
|
useInvoiceRepo: () => useInvoiceRepo,
|
|
@@ -11433,6 +11436,8 @@ __export(src_exports, {
|
|
|
11433
11436
|
usePaymentModel: () => usePaymentModel,
|
|
11434
11437
|
usePaymentRepo: () => usePaymentRepo,
|
|
11435
11438
|
usePaypalService: () => usePaypalService,
|
|
11439
|
+
usePlantillaController: () => usePlantillaController,
|
|
11440
|
+
usePlantillaRepo: () => usePlantillaRepo,
|
|
11436
11441
|
usePriceController: () => usePriceController,
|
|
11437
11442
|
usePriceModel: () => usePriceModel,
|
|
11438
11443
|
usePriceRepo: () => usePriceRepo,
|
|
@@ -11455,6 +11460,7 @@ __export(src_exports, {
|
|
|
11455
11460
|
useUserController: () => useUserController,
|
|
11456
11461
|
useUserRepo: () => useUserRepo,
|
|
11457
11462
|
useUserService: () => useUserService,
|
|
11463
|
+
useUtilController: () => useUtilController,
|
|
11458
11464
|
useVerificationController: () => useVerificationController,
|
|
11459
11465
|
useVerificationRepo: () => useVerificationRepo,
|
|
11460
11466
|
useVerificationService: () => useVerificationService,
|
|
@@ -25650,7 +25656,7 @@ function useRegionService() {
|
|
|
25650
25656
|
{
|
|
25651
25657
|
id: region.toString(),
|
|
25652
25658
|
name: "Admin",
|
|
25653
|
-
type: "
|
|
25659
|
+
type: "basic-edu-ro",
|
|
25654
25660
|
permissions: ["*"],
|
|
25655
25661
|
status: "active",
|
|
25656
25662
|
default: true
|
|
@@ -26202,7 +26208,7 @@ function useDivisionService() {
|
|
|
26202
26208
|
{
|
|
26203
26209
|
id: division.toString(),
|
|
26204
26210
|
name: "Admin",
|
|
26205
|
-
type: "
|
|
26211
|
+
type: "basic-edu-sdo",
|
|
26206
26212
|
permissions: ["*"],
|
|
26207
26213
|
status: "active",
|
|
26208
26214
|
default: true
|
|
@@ -29166,6 +29172,686 @@ function useStockCardController() {
|
|
|
29166
29172
|
getSuppliers
|
|
29167
29173
|
};
|
|
29168
29174
|
}
|
|
29175
|
+
|
|
29176
|
+
// src/services/github.service.ts
|
|
29177
|
+
var import_nodejs_utils80 = require("@eeplatform/nodejs-utils");
|
|
29178
|
+
var import_rest = require("@octokit/rest");
|
|
29179
|
+
var import_libsodium_wrappers = __toESM(require("libsodium-wrappers"));
|
|
29180
|
+
function useGitHubService() {
|
|
29181
|
+
function parseRepoUrl(url2) {
|
|
29182
|
+
const match = url2.match(/github\.com[:\/]([^\/]+)\/(.+)\.git$/);
|
|
29183
|
+
if (!match)
|
|
29184
|
+
throw new Error("Invalid GitHub repo URL");
|
|
29185
|
+
return { owner: match[1], repo: match[2] };
|
|
29186
|
+
}
|
|
29187
|
+
async function checkAdminPermission(owner, repo, octokit) {
|
|
29188
|
+
try {
|
|
29189
|
+
const { data: repoData } = await octokit.repos.get({ owner, repo });
|
|
29190
|
+
if (!repoData.permissions?.admin) {
|
|
29191
|
+
throw new import_nodejs_utils80.BadRequestError(
|
|
29192
|
+
"You do not have admin access to this repository."
|
|
29193
|
+
);
|
|
29194
|
+
}
|
|
29195
|
+
} catch (error) {
|
|
29196
|
+
if (error.status === 404) {
|
|
29197
|
+
throw new import_nodejs_utils80.BadRequestError(
|
|
29198
|
+
"Repository not found or you don't have access to it."
|
|
29199
|
+
);
|
|
29200
|
+
} else if (error.status === 401) {
|
|
29201
|
+
throw new import_nodejs_utils80.BadRequestError(
|
|
29202
|
+
"Invalid GitHub token or insufficient permissions."
|
|
29203
|
+
);
|
|
29204
|
+
} else if (error.message.includes("admin access")) {
|
|
29205
|
+
throw error;
|
|
29206
|
+
} else {
|
|
29207
|
+
throw new import_nodejs_utils80.BadRequestError(
|
|
29208
|
+
`Failed to check repository permissions: ${error.message}`
|
|
29209
|
+
);
|
|
29210
|
+
}
|
|
29211
|
+
}
|
|
29212
|
+
}
|
|
29213
|
+
async function setVariables(params) {
|
|
29214
|
+
try {
|
|
29215
|
+
const { githubToken, repoUrl, environment, type, keyValues } = params;
|
|
29216
|
+
const octokit = new import_rest.Octokit({ auth: githubToken });
|
|
29217
|
+
const { owner, repo } = parseRepoUrl(repoUrl);
|
|
29218
|
+
await checkAdminPermission(owner, repo, octokit);
|
|
29219
|
+
const lines = keyValues.split(/[\n\r\s\t]+/).map((l) => l.trim()).filter(Boolean);
|
|
29220
|
+
for (const line of lines) {
|
|
29221
|
+
const equalIndex = line.indexOf("=");
|
|
29222
|
+
if (equalIndex === -1)
|
|
29223
|
+
continue;
|
|
29224
|
+
const key = line.substring(0, equalIndex).trim();
|
|
29225
|
+
const value = line.substring(equalIndex + 1).trim();
|
|
29226
|
+
if (!key || !value)
|
|
29227
|
+
continue;
|
|
29228
|
+
if (type === "secret") {
|
|
29229
|
+
const { data: publicKeyRes } = await octokit.actions.getEnvironmentPublicKey({
|
|
29230
|
+
owner,
|
|
29231
|
+
repo,
|
|
29232
|
+
environment_name: environment
|
|
29233
|
+
});
|
|
29234
|
+
try {
|
|
29235
|
+
await import_libsodium_wrappers.default.ready;
|
|
29236
|
+
const sodium = import_libsodium_wrappers.default;
|
|
29237
|
+
const publicKeyBase64 = publicKeyRes.key;
|
|
29238
|
+
if (!publicKeyBase64) {
|
|
29239
|
+
throw new Error("No public key received from GitHub");
|
|
29240
|
+
}
|
|
29241
|
+
const keyBytes = new Uint8Array(
|
|
29242
|
+
Buffer.from(publicKeyBase64, "base64")
|
|
29243
|
+
);
|
|
29244
|
+
const valueBytes = new Uint8Array(Buffer.from(value, "utf8"));
|
|
29245
|
+
const encryptedBytes = sodium.crypto_box_seal(valueBytes, keyBytes);
|
|
29246
|
+
const encryptedValue = Buffer.from(encryptedBytes).toString("base64");
|
|
29247
|
+
await octokit.actions.createOrUpdateEnvironmentSecret({
|
|
29248
|
+
owner,
|
|
29249
|
+
repo,
|
|
29250
|
+
environment_name: environment,
|
|
29251
|
+
secret_name: key,
|
|
29252
|
+
encrypted_value: encryptedValue,
|
|
29253
|
+
key_id: publicKeyRes.key_id
|
|
29254
|
+
});
|
|
29255
|
+
} catch (encryptionError) {
|
|
29256
|
+
throw new import_nodejs_utils80.BadRequestError(
|
|
29257
|
+
`Failed to encrypt secret '${key}': ${encryptionError.message}`
|
|
29258
|
+
);
|
|
29259
|
+
}
|
|
29260
|
+
} else if (type === "env") {
|
|
29261
|
+
await octokit.actions.createEnvironmentVariable({
|
|
29262
|
+
owner,
|
|
29263
|
+
repo,
|
|
29264
|
+
environment_name: environment,
|
|
29265
|
+
name: key,
|
|
29266
|
+
value
|
|
29267
|
+
});
|
|
29268
|
+
}
|
|
29269
|
+
}
|
|
29270
|
+
return `Successfully set ${lines.length} ${type} variables/secrets in environment '${environment}'`;
|
|
29271
|
+
} catch (error) {
|
|
29272
|
+
if (error instanceof import_nodejs_utils80.AppError)
|
|
29273
|
+
throw error;
|
|
29274
|
+
if (error.status === 422) {
|
|
29275
|
+
throw new import_nodejs_utils80.BadRequestError(
|
|
29276
|
+
`GitHub API validation error: ${error.message}`
|
|
29277
|
+
);
|
|
29278
|
+
} else if (error.status === 404) {
|
|
29279
|
+
throw new import_nodejs_utils80.BadRequestError("Environment or repository not found.");
|
|
29280
|
+
} else if (error.status === 403) {
|
|
29281
|
+
throw new import_nodejs_utils80.BadRequestError(
|
|
29282
|
+
"Forbidden: Insufficient permissions or rate limit exceeded."
|
|
29283
|
+
);
|
|
29284
|
+
} else if (error.message.includes("admin access") || error.message.includes("permissions")) {
|
|
29285
|
+
throw error;
|
|
29286
|
+
} else {
|
|
29287
|
+
throw new import_nodejs_utils80.BadRequestError(
|
|
29288
|
+
`Failed to set GitHub variables: ${error.message}`
|
|
29289
|
+
);
|
|
29290
|
+
}
|
|
29291
|
+
}
|
|
29292
|
+
}
|
|
29293
|
+
return {
|
|
29294
|
+
setVariables
|
|
29295
|
+
};
|
|
29296
|
+
}
|
|
29297
|
+
|
|
29298
|
+
// src/controllers/util.controller.ts
|
|
29299
|
+
var import_joi40 = __toESM(require("joi"));
|
|
29300
|
+
var import_nodejs_utils81 = require("@eeplatform/nodejs-utils");
|
|
29301
|
+
function useUtilController() {
|
|
29302
|
+
async function healthCheck(req, res, next) {
|
|
29303
|
+
try {
|
|
29304
|
+
res.status(200).json({
|
|
29305
|
+
success: true,
|
|
29306
|
+
message: "Util service is healthy",
|
|
29307
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
29308
|
+
data: {
|
|
29309
|
+
availableEndpoints: [
|
|
29310
|
+
"POST /github/variables - Set GitHub environment variables or secrets"
|
|
29311
|
+
],
|
|
29312
|
+
keyValueFormat: "KEY=value pairs separated by newlines, spaces, or tabs"
|
|
29313
|
+
}
|
|
29314
|
+
});
|
|
29315
|
+
} catch (error) {
|
|
29316
|
+
import_nodejs_utils81.logger.error("Health check failed", { error: error.message });
|
|
29317
|
+
next(new import_nodejs_utils81.InternalServerError("Health check failed"));
|
|
29318
|
+
}
|
|
29319
|
+
}
|
|
29320
|
+
async function setGitHubVariables(req, res, next) {
|
|
29321
|
+
try {
|
|
29322
|
+
const { githubToken, repoUrl, environment, type, keyValues } = req.body;
|
|
29323
|
+
const validation = import_joi40.default.object({
|
|
29324
|
+
githubToken: import_joi40.default.string().required().messages({
|
|
29325
|
+
"string.empty": "GitHub token is required",
|
|
29326
|
+
"any.required": "GitHub token is required"
|
|
29327
|
+
}),
|
|
29328
|
+
repoUrl: import_joi40.default.string().uri().required().messages({
|
|
29329
|
+
"string.empty": "Repository URL is required",
|
|
29330
|
+
"string.uri": "Repository URL must be a valid URL",
|
|
29331
|
+
"any.required": "Repository URL is required"
|
|
29332
|
+
}),
|
|
29333
|
+
environment: import_joi40.default.string().required().messages({
|
|
29334
|
+
"string.empty": "Environment name is required",
|
|
29335
|
+
"any.required": "Environment name is required"
|
|
29336
|
+
}),
|
|
29337
|
+
type: import_joi40.default.string().valid("env", "secret").required().messages({
|
|
29338
|
+
"any.only": 'Type must be either "env" or "secret"',
|
|
29339
|
+
"any.required": "Type is required"
|
|
29340
|
+
}),
|
|
29341
|
+
keyValues: import_joi40.default.string().required().messages({
|
|
29342
|
+
"string.empty": "Key-value pairs are required",
|
|
29343
|
+
"any.required": "Key-value pairs are required"
|
|
29344
|
+
})
|
|
29345
|
+
});
|
|
29346
|
+
const { error } = validation.validate({
|
|
29347
|
+
githubToken,
|
|
29348
|
+
repoUrl,
|
|
29349
|
+
environment,
|
|
29350
|
+
type,
|
|
29351
|
+
keyValues
|
|
29352
|
+
});
|
|
29353
|
+
if (error) {
|
|
29354
|
+
next(new import_nodejs_utils81.BadRequestError(error.message));
|
|
29355
|
+
return;
|
|
29356
|
+
}
|
|
29357
|
+
const repoUrlPattern = /github\.com[:\/]([^\/]+)\/(.+)\.git$/;
|
|
29358
|
+
if (!repoUrlPattern.test(repoUrl)) {
|
|
29359
|
+
next(
|
|
29360
|
+
new import_nodejs_utils81.BadRequestError(
|
|
29361
|
+
"Invalid GitHub repository URL format. Expected format: https://github.com/owner/repo.git"
|
|
29362
|
+
)
|
|
29363
|
+
);
|
|
29364
|
+
return;
|
|
29365
|
+
}
|
|
29366
|
+
const lines = keyValues.split(/[\n\r\s\t]+/).map((l) => l.trim()).filter(Boolean);
|
|
29367
|
+
const invalidLines = lines.filter(
|
|
29368
|
+
(line) => !line.includes("=") || line.indexOf("=") === -1
|
|
29369
|
+
);
|
|
29370
|
+
if (invalidLines.length > 0) {
|
|
29371
|
+
next(
|
|
29372
|
+
new import_nodejs_utils81.BadRequestError(
|
|
29373
|
+
"Invalid key-value format. Each pair should be in format: KEY=value. Pairs can be separated by newlines, spaces, or tabs."
|
|
29374
|
+
)
|
|
29375
|
+
);
|
|
29376
|
+
return;
|
|
29377
|
+
}
|
|
29378
|
+
const githubService = useGitHubService();
|
|
29379
|
+
const result = await githubService.setVariables({
|
|
29380
|
+
githubToken,
|
|
29381
|
+
repoUrl,
|
|
29382
|
+
environment,
|
|
29383
|
+
type,
|
|
29384
|
+
keyValues
|
|
29385
|
+
});
|
|
29386
|
+
import_nodejs_utils81.logger.info(`GitHub variables set successfully`, {
|
|
29387
|
+
repoUrl,
|
|
29388
|
+
environment,
|
|
29389
|
+
type,
|
|
29390
|
+
count: lines.length
|
|
29391
|
+
});
|
|
29392
|
+
res.status(200).json({
|
|
29393
|
+
success: true,
|
|
29394
|
+
message: result,
|
|
29395
|
+
data: {
|
|
29396
|
+
repoUrl,
|
|
29397
|
+
environment,
|
|
29398
|
+
type,
|
|
29399
|
+
variablesSet: lines.length
|
|
29400
|
+
}
|
|
29401
|
+
});
|
|
29402
|
+
} catch (error) {
|
|
29403
|
+
import_nodejs_utils81.logger.error("Failed to set GitHub variables", {
|
|
29404
|
+
error: error.message,
|
|
29405
|
+
stack: error.stack
|
|
29406
|
+
});
|
|
29407
|
+
if (error instanceof import_nodejs_utils81.AppError) {
|
|
29408
|
+
next(error);
|
|
29409
|
+
} else {
|
|
29410
|
+
next(
|
|
29411
|
+
new import_nodejs_utils81.InternalServerError(
|
|
29412
|
+
`Failed to set GitHub variables: ${error.message}`
|
|
29413
|
+
)
|
|
29414
|
+
);
|
|
29415
|
+
}
|
|
29416
|
+
}
|
|
29417
|
+
}
|
|
29418
|
+
return {
|
|
29419
|
+
healthCheck,
|
|
29420
|
+
setGitHubVariables
|
|
29421
|
+
};
|
|
29422
|
+
}
|
|
29423
|
+
|
|
29424
|
+
// src/models/plantilla.model.ts
|
|
29425
|
+
var import_nodejs_utils82 = require("@eeplatform/nodejs-utils");
|
|
29426
|
+
var import_joi41 = __toESM(require("joi"));
|
|
29427
|
+
var import_mongodb46 = require("mongodb");
|
|
29428
|
+
var schemaPlantilla = import_joi41.default.object({
|
|
29429
|
+
_id: import_joi41.default.string().hex().optional().allow(null, ""),
|
|
29430
|
+
itemNumber: import_joi41.default.string().required(),
|
|
29431
|
+
positionTitle: import_joi41.default.string().required(),
|
|
29432
|
+
officeAssignmentType: import_joi41.default.string().required(),
|
|
29433
|
+
officeAssignment: import_joi41.default.string().required(),
|
|
29434
|
+
status: import_joi41.default.string().required(),
|
|
29435
|
+
employeeId: import_joi41.default.string().hex().optional().allow(null, ""),
|
|
29436
|
+
createdAt: import_joi41.default.date().iso().optional().allow(null, ""),
|
|
29437
|
+
updatedAt: import_joi41.default.date().iso().optional().allow(null, ""),
|
|
29438
|
+
deletedAt: import_joi41.default.date().iso().optional().allow(null, "")
|
|
29439
|
+
});
|
|
29440
|
+
function MPlantilla(data) {
|
|
29441
|
+
const { error } = schemaPlantilla.validate(data);
|
|
29442
|
+
if (error) {
|
|
29443
|
+
throw new import_nodejs_utils82.BadRequestError(error.message);
|
|
29444
|
+
}
|
|
29445
|
+
if (data._id && typeof data._id === "string") {
|
|
29446
|
+
try {
|
|
29447
|
+
data._id = new import_mongodb46.ObjectId(data._id);
|
|
29448
|
+
} catch (error2) {
|
|
29449
|
+
throw new import_nodejs_utils82.BadRequestError("Invalid _id.");
|
|
29450
|
+
}
|
|
29451
|
+
}
|
|
29452
|
+
if (data.employeeId && typeof data.employeeId === "string") {
|
|
29453
|
+
try {
|
|
29454
|
+
data.employeeId = new import_mongodb46.ObjectId(data.employeeId);
|
|
29455
|
+
} catch (error2) {
|
|
29456
|
+
throw new import_nodejs_utils82.BadRequestError("Invalid employeeId.");
|
|
29457
|
+
}
|
|
29458
|
+
}
|
|
29459
|
+
return {
|
|
29460
|
+
_id: data._id,
|
|
29461
|
+
itemNumber: data.itemNumber ?? "",
|
|
29462
|
+
positionTitle: data.positionTitle ?? "",
|
|
29463
|
+
officeAssignmentType: data.officeAssignmentType ?? "",
|
|
29464
|
+
officeAssignment: data.officeAssignment ?? "",
|
|
29465
|
+
status: data.status ?? "active",
|
|
29466
|
+
employeeId: data.employeeId,
|
|
29467
|
+
createdAt: data.createdAt ? new Date(data.createdAt) : /* @__PURE__ */ new Date(),
|
|
29468
|
+
updatedAt: data.updatedAt ? new Date(data.updatedAt) : "",
|
|
29469
|
+
deletedAt: data.deletedAt ? new Date(data.deletedAt) : ""
|
|
29470
|
+
};
|
|
29471
|
+
}
|
|
29472
|
+
|
|
29473
|
+
// src/repositories/plantilla.repository.ts
|
|
29474
|
+
var import_nodejs_utils83 = require("@eeplatform/nodejs-utils");
|
|
29475
|
+
var import_mongodb47 = require("mongodb");
|
|
29476
|
+
function usePlantillaRepo() {
|
|
29477
|
+
const db = import_nodejs_utils83.useAtlas.getDb();
|
|
29478
|
+
if (!db) {
|
|
29479
|
+
throw new Error("Unable to connect to server.");
|
|
29480
|
+
}
|
|
29481
|
+
const namespace_collection = "plantillas";
|
|
29482
|
+
const collection = db.collection(namespace_collection);
|
|
29483
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils83.useCache)(namespace_collection);
|
|
29484
|
+
async function createIndexes() {
|
|
29485
|
+
try {
|
|
29486
|
+
await collection.createIndexes([
|
|
29487
|
+
{ key: { name: 1 }, unique: true, name: "unique_name_index" },
|
|
29488
|
+
{ key: { school: 1 } },
|
|
29489
|
+
{ key: { status: 1 } }
|
|
29490
|
+
]);
|
|
29491
|
+
} catch (error) {
|
|
29492
|
+
throw new Error("Failed to create index on plantillas.");
|
|
29493
|
+
}
|
|
29494
|
+
}
|
|
29495
|
+
async function add(value, session) {
|
|
29496
|
+
try {
|
|
29497
|
+
value = MPlantilla(value);
|
|
29498
|
+
const res = await collection.insertOne(value, { session });
|
|
29499
|
+
delCachedData();
|
|
29500
|
+
return res.insertedId;
|
|
29501
|
+
} catch (error) {
|
|
29502
|
+
import_nodejs_utils83.logger.log({
|
|
29503
|
+
level: "error",
|
|
29504
|
+
message: error.message
|
|
29505
|
+
});
|
|
29506
|
+
if (error instanceof import_nodejs_utils83.AppError) {
|
|
29507
|
+
throw error;
|
|
29508
|
+
} else {
|
|
29509
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
29510
|
+
if (isDuplicated) {
|
|
29511
|
+
throw new import_nodejs_utils83.BadRequestError("Plantilla already exists.");
|
|
29512
|
+
}
|
|
29513
|
+
throw new Error("Failed to create plantilla.");
|
|
29514
|
+
}
|
|
29515
|
+
}
|
|
29516
|
+
}
|
|
29517
|
+
async function updateById(_id, value, session) {
|
|
29518
|
+
try {
|
|
29519
|
+
_id = new import_mongodb47.ObjectId(_id);
|
|
29520
|
+
} catch (error) {
|
|
29521
|
+
throw new import_nodejs_utils83.BadRequestError("Invalid ID.");
|
|
29522
|
+
}
|
|
29523
|
+
value.updatedAt = /* @__PURE__ */ new Date();
|
|
29524
|
+
try {
|
|
29525
|
+
const res = await collection.updateOne(
|
|
29526
|
+
{ _id },
|
|
29527
|
+
{ $set: value },
|
|
29528
|
+
{ session }
|
|
29529
|
+
);
|
|
29530
|
+
delCachedData();
|
|
29531
|
+
return res;
|
|
29532
|
+
} catch (error) {
|
|
29533
|
+
import_nodejs_utils83.logger.log({
|
|
29534
|
+
level: "error",
|
|
29535
|
+
message: error.message
|
|
29536
|
+
});
|
|
29537
|
+
if (error instanceof import_nodejs_utils83.AppError) {
|
|
29538
|
+
throw error;
|
|
29539
|
+
} else {
|
|
29540
|
+
throw new Error("Failed to update plantilla.");
|
|
29541
|
+
}
|
|
29542
|
+
}
|
|
29543
|
+
}
|
|
29544
|
+
async function getAll({
|
|
29545
|
+
search = "",
|
|
29546
|
+
page = 1,
|
|
29547
|
+
limit = 10,
|
|
29548
|
+
sort = {},
|
|
29549
|
+
org = "",
|
|
29550
|
+
status = "active"
|
|
29551
|
+
} = {}) {
|
|
29552
|
+
page = page > 0 ? page - 1 : 0;
|
|
29553
|
+
const query = {
|
|
29554
|
+
status
|
|
29555
|
+
};
|
|
29556
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
29557
|
+
if (search) {
|
|
29558
|
+
query.$text = { $search: search };
|
|
29559
|
+
}
|
|
29560
|
+
if (org) {
|
|
29561
|
+
try {
|
|
29562
|
+
query.org = new import_mongodb47.ObjectId(org);
|
|
29563
|
+
} catch (error) {
|
|
29564
|
+
throw new import_nodejs_utils83.BadRequestError("Invalid org ID.");
|
|
29565
|
+
}
|
|
29566
|
+
}
|
|
29567
|
+
const cacheParams = {
|
|
29568
|
+
page,
|
|
29569
|
+
limit,
|
|
29570
|
+
sort: JSON.stringify(sort)
|
|
29571
|
+
};
|
|
29572
|
+
if (search)
|
|
29573
|
+
cacheParams.search = search;
|
|
29574
|
+
if (org)
|
|
29575
|
+
cacheParams.org = org;
|
|
29576
|
+
if (status !== "active")
|
|
29577
|
+
cacheParams.status = status;
|
|
29578
|
+
const cacheKey = (0, import_nodejs_utils83.makeCacheKey)(namespace_collection, cacheParams);
|
|
29579
|
+
import_nodejs_utils83.logger.log({
|
|
29580
|
+
level: "info",
|
|
29581
|
+
message: `Cache key for getAll plantillas: ${cacheKey}`
|
|
29582
|
+
});
|
|
29583
|
+
try {
|
|
29584
|
+
const cached = await getCache(cacheKey);
|
|
29585
|
+
if (cached) {
|
|
29586
|
+
import_nodejs_utils83.logger.log({
|
|
29587
|
+
level: "info",
|
|
29588
|
+
message: `Cache hit for getAll plantillas: ${cacheKey}`
|
|
29589
|
+
});
|
|
29590
|
+
return cached;
|
|
29591
|
+
}
|
|
29592
|
+
const items = await collection.aggregate([
|
|
29593
|
+
{ $match: query },
|
|
29594
|
+
{ $sort: sort },
|
|
29595
|
+
{ $skip: page * limit },
|
|
29596
|
+
{ $limit: limit }
|
|
29597
|
+
]).toArray();
|
|
29598
|
+
const length = await collection.countDocuments(query);
|
|
29599
|
+
const data = (0, import_nodejs_utils83.paginate)(items, page, limit, length);
|
|
29600
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
29601
|
+
import_nodejs_utils83.logger.log({
|
|
29602
|
+
level: "info",
|
|
29603
|
+
message: `Cache set for getAll plantillas: ${cacheKey}`
|
|
29604
|
+
});
|
|
29605
|
+
}).catch((err) => {
|
|
29606
|
+
import_nodejs_utils83.logger.log({
|
|
29607
|
+
level: "error",
|
|
29608
|
+
message: `Failed to set cache for getAll plantillas: ${err.message}`
|
|
29609
|
+
});
|
|
29610
|
+
});
|
|
29611
|
+
return data;
|
|
29612
|
+
} catch (error) {
|
|
29613
|
+
import_nodejs_utils83.logger.log({ level: "error", message: `${error}` });
|
|
29614
|
+
throw error;
|
|
29615
|
+
}
|
|
29616
|
+
}
|
|
29617
|
+
async function getById(_id) {
|
|
29618
|
+
try {
|
|
29619
|
+
_id = new import_mongodb47.ObjectId(_id);
|
|
29620
|
+
} catch (error) {
|
|
29621
|
+
throw new import_nodejs_utils83.BadRequestError("Invalid ID.");
|
|
29622
|
+
}
|
|
29623
|
+
const cacheKey = (0, import_nodejs_utils83.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
29624
|
+
try {
|
|
29625
|
+
const cached = await getCache(cacheKey);
|
|
29626
|
+
if (cached) {
|
|
29627
|
+
import_nodejs_utils83.logger.log({
|
|
29628
|
+
level: "info",
|
|
29629
|
+
message: `Cache hit for getById plantilla: ${cacheKey}`
|
|
29630
|
+
});
|
|
29631
|
+
return cached;
|
|
29632
|
+
}
|
|
29633
|
+
const result = await collection.findOne({
|
|
29634
|
+
_id
|
|
29635
|
+
});
|
|
29636
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
29637
|
+
import_nodejs_utils83.logger.log({
|
|
29638
|
+
level: "info",
|
|
29639
|
+
message: `Cache set for plantilla by id: ${cacheKey}`
|
|
29640
|
+
});
|
|
29641
|
+
}).catch((err) => {
|
|
29642
|
+
import_nodejs_utils83.logger.log({
|
|
29643
|
+
level: "error",
|
|
29644
|
+
message: `Failed to set cache for plantilla by id: ${err.message}`
|
|
29645
|
+
});
|
|
29646
|
+
});
|
|
29647
|
+
return result;
|
|
29648
|
+
} catch (error) {
|
|
29649
|
+
if (error instanceof import_nodejs_utils83.AppError) {
|
|
29650
|
+
throw error;
|
|
29651
|
+
} else {
|
|
29652
|
+
throw new import_nodejs_utils83.InternalServerError("Failed to get plantilla.");
|
|
29653
|
+
}
|
|
29654
|
+
}
|
|
29655
|
+
}
|
|
29656
|
+
async function deleteById(_id, session) {
|
|
29657
|
+
try {
|
|
29658
|
+
_id = new import_mongodb47.ObjectId(_id);
|
|
29659
|
+
} catch (error) {
|
|
29660
|
+
throw new import_nodejs_utils83.BadRequestError("Invalid ID.");
|
|
29661
|
+
}
|
|
29662
|
+
try {
|
|
29663
|
+
const res = await collection.updateOne(
|
|
29664
|
+
{ _id },
|
|
29665
|
+
{ $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } }
|
|
29666
|
+
);
|
|
29667
|
+
delCachedData();
|
|
29668
|
+
return res;
|
|
29669
|
+
} catch (error) {
|
|
29670
|
+
import_nodejs_utils83.logger.log({
|
|
29671
|
+
level: "error",
|
|
29672
|
+
message: error.message
|
|
29673
|
+
});
|
|
29674
|
+
if (error instanceof import_nodejs_utils83.AppError) {
|
|
29675
|
+
throw error;
|
|
29676
|
+
} else {
|
|
29677
|
+
throw new import_nodejs_utils83.InternalServerError("Failed to delete plantilla.");
|
|
29678
|
+
}
|
|
29679
|
+
}
|
|
29680
|
+
}
|
|
29681
|
+
function delCachedData() {
|
|
29682
|
+
delNamespace().then(() => {
|
|
29683
|
+
import_nodejs_utils83.logger.log({
|
|
29684
|
+
level: "info",
|
|
29685
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
29686
|
+
});
|
|
29687
|
+
}).catch((err) => {
|
|
29688
|
+
import_nodejs_utils83.logger.log({
|
|
29689
|
+
level: "error",
|
|
29690
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
29691
|
+
});
|
|
29692
|
+
});
|
|
29693
|
+
}
|
|
29694
|
+
return {
|
|
29695
|
+
createIndexes,
|
|
29696
|
+
add,
|
|
29697
|
+
getAll,
|
|
29698
|
+
getById,
|
|
29699
|
+
updateById,
|
|
29700
|
+
deleteById
|
|
29701
|
+
};
|
|
29702
|
+
}
|
|
29703
|
+
|
|
29704
|
+
// src/controllers/plantilla.controller.ts
|
|
29705
|
+
var import_nodejs_utils84 = require("@eeplatform/nodejs-utils");
|
|
29706
|
+
var import_joi42 = __toESM(require("joi"));
|
|
29707
|
+
function usePlantillaController() {
|
|
29708
|
+
const {
|
|
29709
|
+
add: _addPlantilla,
|
|
29710
|
+
getAll: _getAllPlantillas,
|
|
29711
|
+
getById: _getPlantillaById,
|
|
29712
|
+
updateById: _updatePlantillaById,
|
|
29713
|
+
deleteById: _deletePlantillaById
|
|
29714
|
+
} = usePlantillaRepo();
|
|
29715
|
+
async function createPlantilla(req, res, next) {
|
|
29716
|
+
const value = req.body;
|
|
29717
|
+
const validation = import_joi42.default.object({
|
|
29718
|
+
itemNumber: import_joi42.default.string().required(),
|
|
29719
|
+
positionTitle: import_joi42.default.string().required(),
|
|
29720
|
+
officeAssignmentType: import_joi42.default.string().required(),
|
|
29721
|
+
officeAssignment: import_joi42.default.string().required(),
|
|
29722
|
+
status: import_joi42.default.string().required(),
|
|
29723
|
+
employeeId: import_joi42.default.string().hex().optional().allow(null, "")
|
|
29724
|
+
});
|
|
29725
|
+
const { error } = validation.validate(value);
|
|
29726
|
+
if (error) {
|
|
29727
|
+
next(new import_nodejs_utils84.BadRequestError(error.message));
|
|
29728
|
+
return;
|
|
29729
|
+
}
|
|
29730
|
+
try {
|
|
29731
|
+
const id = await _addPlantilla(value);
|
|
29732
|
+
res.json({ message: "Plantilla created successfully", id });
|
|
29733
|
+
return;
|
|
29734
|
+
} catch (error2) {
|
|
29735
|
+
next(error2);
|
|
29736
|
+
}
|
|
29737
|
+
}
|
|
29738
|
+
async function getAllPlantillas(req, res, next) {
|
|
29739
|
+
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
29740
|
+
const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
|
|
29741
|
+
const search = req.query.search ?? "";
|
|
29742
|
+
const org = req.query.org ?? "";
|
|
29743
|
+
const isPageNumber = isFinite(page);
|
|
29744
|
+
if (!isPageNumber) {
|
|
29745
|
+
next(new import_nodejs_utils84.BadRequestError("Invalid page number."));
|
|
29746
|
+
return;
|
|
29747
|
+
}
|
|
29748
|
+
const isLimitNumber = isFinite(limit);
|
|
29749
|
+
if (!isLimitNumber) {
|
|
29750
|
+
next(new import_nodejs_utils84.BadRequestError("Invalid limit number."));
|
|
29751
|
+
return;
|
|
29752
|
+
}
|
|
29753
|
+
const validation = import_joi42.default.object({
|
|
29754
|
+
page: import_joi42.default.number().min(1).optional().allow("", null),
|
|
29755
|
+
limit: import_joi42.default.number().min(1).optional().allow("", null),
|
|
29756
|
+
search: import_joi42.default.string().optional().allow("", null),
|
|
29757
|
+
org: import_joi42.default.string().optional().allow("", null)
|
|
29758
|
+
});
|
|
29759
|
+
const { error } = validation.validate({ page, limit, search, org });
|
|
29760
|
+
if (error) {
|
|
29761
|
+
next(new import_nodejs_utils84.BadRequestError(error.message));
|
|
29762
|
+
return;
|
|
29763
|
+
}
|
|
29764
|
+
try {
|
|
29765
|
+
const plantillas = await _getAllPlantillas({
|
|
29766
|
+
search,
|
|
29767
|
+
page,
|
|
29768
|
+
limit,
|
|
29769
|
+
org
|
|
29770
|
+
});
|
|
29771
|
+
res.json(plantillas);
|
|
29772
|
+
return;
|
|
29773
|
+
} catch (error2) {
|
|
29774
|
+
next(error2);
|
|
29775
|
+
}
|
|
29776
|
+
}
|
|
29777
|
+
async function getPlantillaById(req, res, next) {
|
|
29778
|
+
const id = req.params.id;
|
|
29779
|
+
const validation = import_joi42.default.object({
|
|
29780
|
+
id: import_joi42.default.string().hex().required()
|
|
29781
|
+
});
|
|
29782
|
+
const { error } = validation.validate({ id });
|
|
29783
|
+
if (error) {
|
|
29784
|
+
next(new import_nodejs_utils84.BadRequestError(error.message));
|
|
29785
|
+
return;
|
|
29786
|
+
}
|
|
29787
|
+
try {
|
|
29788
|
+
const plantilla = await _getPlantillaById(id);
|
|
29789
|
+
if (!plantilla) {
|
|
29790
|
+
next(new import_nodejs_utils84.BadRequestError("Plantilla not found."));
|
|
29791
|
+
return;
|
|
29792
|
+
}
|
|
29793
|
+
res.json(plantilla);
|
|
29794
|
+
return;
|
|
29795
|
+
} catch (error2) {
|
|
29796
|
+
next(error2);
|
|
29797
|
+
}
|
|
29798
|
+
}
|
|
29799
|
+
async function updatePlantilla(req, res, next) {
|
|
29800
|
+
const id = req.params.id;
|
|
29801
|
+
const value = req.body;
|
|
29802
|
+
const validation = import_joi42.default.object({
|
|
29803
|
+
id: import_joi42.default.string().hex().required(),
|
|
29804
|
+
employeeId: import_joi42.default.string().hex().optional().allow(null, ""),
|
|
29805
|
+
status: import_joi42.default.string().optional(),
|
|
29806
|
+
positionTitle: import_joi42.default.string().optional()
|
|
29807
|
+
});
|
|
29808
|
+
const { error } = validation.validate({ id, ...value });
|
|
29809
|
+
if (error) {
|
|
29810
|
+
next(new import_nodejs_utils84.BadRequestError(error.message));
|
|
29811
|
+
return;
|
|
29812
|
+
}
|
|
29813
|
+
try {
|
|
29814
|
+
const result = await _updatePlantillaById(id, value);
|
|
29815
|
+
if (result.matchedCount === 0) {
|
|
29816
|
+
next(new import_nodejs_utils84.BadRequestError("Plantilla not found."));
|
|
29817
|
+
return;
|
|
29818
|
+
}
|
|
29819
|
+
res.json({ message: "Plantilla updated successfully" });
|
|
29820
|
+
return;
|
|
29821
|
+
} catch (error2) {
|
|
29822
|
+
next(error2);
|
|
29823
|
+
}
|
|
29824
|
+
}
|
|
29825
|
+
async function deletePlantilla(req, res, next) {
|
|
29826
|
+
const id = req.params.id;
|
|
29827
|
+
const validation = import_joi42.default.object({
|
|
29828
|
+
id: import_joi42.default.string().hex().required()
|
|
29829
|
+
});
|
|
29830
|
+
const { error } = validation.validate({ id });
|
|
29831
|
+
if (error) {
|
|
29832
|
+
next(new import_nodejs_utils84.BadRequestError(error.message));
|
|
29833
|
+
return;
|
|
29834
|
+
}
|
|
29835
|
+
try {
|
|
29836
|
+
const result = await _deletePlantillaById(id);
|
|
29837
|
+
if (result.matchedCount === 0) {
|
|
29838
|
+
next(new import_nodejs_utils84.BadRequestError("Plantilla not found."));
|
|
29839
|
+
return;
|
|
29840
|
+
}
|
|
29841
|
+
res.json({ message: "Plantilla deleted successfully" });
|
|
29842
|
+
return;
|
|
29843
|
+
} catch (error2) {
|
|
29844
|
+
next(error2);
|
|
29845
|
+
}
|
|
29846
|
+
}
|
|
29847
|
+
return {
|
|
29848
|
+
createPlantilla,
|
|
29849
|
+
getAllPlantillas,
|
|
29850
|
+
getPlantillaById,
|
|
29851
|
+
updatePlantilla,
|
|
29852
|
+
deletePlantilla
|
|
29853
|
+
};
|
|
29854
|
+
}
|
|
29169
29855
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29170
29856
|
0 && (module.exports = {
|
|
29171
29857
|
ACCESS_TOKEN_EXPIRY,
|
|
@@ -29197,6 +29883,7 @@ function useStockCardController() {
|
|
|
29197
29883
|
MOrder,
|
|
29198
29884
|
MOrg,
|
|
29199
29885
|
MPaymentMethod,
|
|
29886
|
+
MPlantilla,
|
|
29200
29887
|
MPromoCode,
|
|
29201
29888
|
MRegion,
|
|
29202
29889
|
MRole,
|
|
@@ -29234,6 +29921,7 @@ function useStockCardController() {
|
|
|
29234
29921
|
schemaBuilding,
|
|
29235
29922
|
schemaBuildingUnit,
|
|
29236
29923
|
schemaDivision,
|
|
29924
|
+
schemaPlantilla,
|
|
29237
29925
|
schemaRegion,
|
|
29238
29926
|
schemaSchool,
|
|
29239
29927
|
schemaStockCard,
|
|
@@ -29258,6 +29946,7 @@ function useStockCardController() {
|
|
|
29258
29946
|
useFileController,
|
|
29259
29947
|
useFileRepo,
|
|
29260
29948
|
useFileService,
|
|
29949
|
+
useGitHubService,
|
|
29261
29950
|
useInvoiceController,
|
|
29262
29951
|
useInvoiceModel,
|
|
29263
29952
|
useInvoiceRepo,
|
|
@@ -29276,6 +29965,8 @@ function useStockCardController() {
|
|
|
29276
29965
|
usePaymentModel,
|
|
29277
29966
|
usePaymentRepo,
|
|
29278
29967
|
usePaypalService,
|
|
29968
|
+
usePlantillaController,
|
|
29969
|
+
usePlantillaRepo,
|
|
29279
29970
|
usePriceController,
|
|
29280
29971
|
usePriceModel,
|
|
29281
29972
|
usePriceRepo,
|
|
@@ -29298,6 +29989,7 @@ function useStockCardController() {
|
|
|
29298
29989
|
useUserController,
|
|
29299
29990
|
useUserRepo,
|
|
29300
29991
|
useUserService,
|
|
29992
|
+
useUtilController,
|
|
29301
29993
|
useVerificationController,
|
|
29302
29994
|
useVerificationRepo,
|
|
29303
29995
|
useVerificationService,
|