@eeplatform/basic-edu 1.3.1 → 1.3.3
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 +12 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +453 -387
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +412 -346
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1872,8 +1872,9 @@ var learnerInfoSchema = import_joi3.default.object({
|
|
|
1872
1872
|
hasDisability: import_joi3.default.boolean().required(),
|
|
1873
1873
|
disabilityTypes: import_joi3.default.array().items(
|
|
1874
1874
|
import_joi3.default.string().valid(
|
|
1875
|
-
"Visual Impairment
|
|
1876
|
-
"Visual Impairment
|
|
1875
|
+
"Visual Impairment",
|
|
1876
|
+
"Visual Impairment(Blind)",
|
|
1877
|
+
"Visual Impairment(Low Vision)",
|
|
1877
1878
|
"Hearing Impairment",
|
|
1878
1879
|
"Learning Disability",
|
|
1879
1880
|
"Intellectual Disability",
|
|
@@ -1884,8 +1885,7 @@ var learnerInfoSchema = import_joi3.default.object({
|
|
|
1884
1885
|
"Cerebral Palsy",
|
|
1885
1886
|
"Special Health Problem/Chronic Disease",
|
|
1886
1887
|
"Multiple Disorder",
|
|
1887
|
-
"Cancer"
|
|
1888
|
-
"Other"
|
|
1888
|
+
"Cancer"
|
|
1889
1889
|
)
|
|
1890
1890
|
).optional(),
|
|
1891
1891
|
otherDisabilityDetails: import_joi3.default.string().optional().allow("", null),
|
|
@@ -4335,6 +4335,13 @@ function useDivisionRepo() {
|
|
|
4335
4335
|
} catch (error2) {
|
|
4336
4336
|
throw new import_nodejs_utils15.BadRequestError("Invalid ID.");
|
|
4337
4337
|
}
|
|
4338
|
+
if (options.region) {
|
|
4339
|
+
try {
|
|
4340
|
+
options.region = new import_mongodb10.ObjectId(options.region);
|
|
4341
|
+
} catch (error2) {
|
|
4342
|
+
throw new import_nodejs_utils15.BadRequestError("Invalid region ID.");
|
|
4343
|
+
}
|
|
4344
|
+
}
|
|
4338
4345
|
try {
|
|
4339
4346
|
await collection.updateOne({ _id }, { $set: options }, { session });
|
|
4340
4347
|
delCachedData();
|
|
@@ -4373,272 +4380,61 @@ function useDivisionRepo() {
|
|
|
4373
4380
|
}
|
|
4374
4381
|
|
|
4375
4382
|
// src/resources/division/division.service.ts
|
|
4376
|
-
var
|
|
4377
|
-
var
|
|
4378
|
-
function useDivisionService() {
|
|
4379
|
-
const { add: _add } = useDivisionRepo();
|
|
4380
|
-
const { addRole } = (0, import_core.useRoleRepo)();
|
|
4381
|
-
async function add(value) {
|
|
4382
|
-
const session = import_nodejs_utils16.useAtlas.getClient()?.startSession();
|
|
4383
|
-
if (!session) {
|
|
4384
|
-
throw new Error("Unable to start session for division service.");
|
|
4385
|
-
}
|
|
4386
|
-
try {
|
|
4387
|
-
session.startTransaction();
|
|
4388
|
-
const division = await _add(value, session);
|
|
4389
|
-
await addRole(
|
|
4390
|
-
{
|
|
4391
|
-
id: division.toString(),
|
|
4392
|
-
name: "Admin",
|
|
4393
|
-
type: "basic-edu-sdo",
|
|
4394
|
-
permissions: ["*"],
|
|
4395
|
-
status: "active",
|
|
4396
|
-
default: true
|
|
4397
|
-
},
|
|
4398
|
-
session
|
|
4399
|
-
);
|
|
4400
|
-
await session.commitTransaction();
|
|
4401
|
-
return "Division and admin role created successfully.";
|
|
4402
|
-
} catch (error) {
|
|
4403
|
-
session.abortTransaction();
|
|
4404
|
-
throw error;
|
|
4405
|
-
} finally {
|
|
4406
|
-
session.endSession();
|
|
4407
|
-
}
|
|
4408
|
-
}
|
|
4409
|
-
return {
|
|
4410
|
-
add
|
|
4411
|
-
};
|
|
4412
|
-
}
|
|
4413
|
-
|
|
4414
|
-
// src/resources/division/division.controller.ts
|
|
4415
|
-
var import_nodejs_utils17 = require("@eeplatform/nodejs-utils");
|
|
4416
|
-
var import_joi10 = __toESM(require("joi"));
|
|
4417
|
-
function useDivisionController() {
|
|
4418
|
-
const { add: _add } = useDivisionService();
|
|
4419
|
-
const {
|
|
4420
|
-
getAll: _getAll,
|
|
4421
|
-
getById: _getById,
|
|
4422
|
-
getByName: _getByName,
|
|
4423
|
-
updateFieldById: _updateFieldById,
|
|
4424
|
-
updateById: _updateById,
|
|
4425
|
-
deleteById: _deleteById
|
|
4426
|
-
} = useDivisionRepo();
|
|
4427
|
-
async function add(req, res, next) {
|
|
4428
|
-
const value = req.body;
|
|
4429
|
-
const { error } = schemaDivision.validate(value);
|
|
4430
|
-
if (error) {
|
|
4431
|
-
next(new import_nodejs_utils17.BadRequestError(error.message));
|
|
4432
|
-
return;
|
|
4433
|
-
}
|
|
4434
|
-
try {
|
|
4435
|
-
const data = await _add(value);
|
|
4436
|
-
res.json({
|
|
4437
|
-
message: "Successfully created division.",
|
|
4438
|
-
data
|
|
4439
|
-
});
|
|
4440
|
-
return;
|
|
4441
|
-
} catch (error2) {
|
|
4442
|
-
next(error2);
|
|
4443
|
-
}
|
|
4444
|
-
}
|
|
4445
|
-
async function getAll(req, res, next) {
|
|
4446
|
-
const query = req.query;
|
|
4447
|
-
const validation = import_joi10.default.object({
|
|
4448
|
-
page: import_joi10.default.number().min(1).optional().allow("", null),
|
|
4449
|
-
limit: import_joi10.default.number().min(1).optional().allow("", null),
|
|
4450
|
-
search: import_joi10.default.string().optional().allow("", null),
|
|
4451
|
-
status: import_joi10.default.string().optional().allow("", null),
|
|
4452
|
-
region: import_joi10.default.string().hex().optional().allow("", null)
|
|
4453
|
-
});
|
|
4454
|
-
const { error } = validation.validate(query);
|
|
4455
|
-
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
4456
|
-
const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
|
|
4457
|
-
const search = req.query.search ?? "";
|
|
4458
|
-
const status = req.query.status ?? "active";
|
|
4459
|
-
const region = req.query.region ?? "";
|
|
4460
|
-
const isPageNumber = isFinite(page);
|
|
4461
|
-
if (!isPageNumber) {
|
|
4462
|
-
next(new import_nodejs_utils17.BadRequestError("Invalid page number."));
|
|
4463
|
-
return;
|
|
4464
|
-
}
|
|
4465
|
-
const isLimitNumber = isFinite(limit);
|
|
4466
|
-
if (!isLimitNumber) {
|
|
4467
|
-
next(new import_nodejs_utils17.BadRequestError("Invalid limit number."));
|
|
4468
|
-
return;
|
|
4469
|
-
}
|
|
4470
|
-
if (error) {
|
|
4471
|
-
next(new import_nodejs_utils17.BadRequestError(error.message));
|
|
4472
|
-
return;
|
|
4473
|
-
}
|
|
4474
|
-
try {
|
|
4475
|
-
const data = await _getAll({ page, limit, search, status, region });
|
|
4476
|
-
res.json(data);
|
|
4477
|
-
return;
|
|
4478
|
-
} catch (error2) {
|
|
4479
|
-
next(error2);
|
|
4480
|
-
}
|
|
4481
|
-
}
|
|
4482
|
-
async function getById(req, res, next) {
|
|
4483
|
-
const id = req.params.id;
|
|
4484
|
-
const validation = import_joi10.default.object({
|
|
4485
|
-
id: import_joi10.default.string().hex().required()
|
|
4486
|
-
});
|
|
4487
|
-
const { error } = validation.validate({ id });
|
|
4488
|
-
if (error) {
|
|
4489
|
-
next(new import_nodejs_utils17.BadRequestError(error.message));
|
|
4490
|
-
return;
|
|
4491
|
-
}
|
|
4492
|
-
try {
|
|
4493
|
-
const data = await _getById(id);
|
|
4494
|
-
res.json({
|
|
4495
|
-
message: "Successfully retrieved division.",
|
|
4496
|
-
data
|
|
4497
|
-
});
|
|
4498
|
-
return;
|
|
4499
|
-
} catch (error2) {
|
|
4500
|
-
next(error2);
|
|
4501
|
-
}
|
|
4502
|
-
}
|
|
4503
|
-
async function getByName(req, res, next) {
|
|
4504
|
-
const name = req.params.name;
|
|
4505
|
-
const validation = import_joi10.default.object({
|
|
4506
|
-
name: import_joi10.default.string().required()
|
|
4507
|
-
});
|
|
4508
|
-
const { error } = validation.validate({ name });
|
|
4509
|
-
if (error) {
|
|
4510
|
-
next(new import_nodejs_utils17.BadRequestError(error.message));
|
|
4511
|
-
return;
|
|
4512
|
-
}
|
|
4513
|
-
try {
|
|
4514
|
-
const data = await _getByName(name);
|
|
4515
|
-
res.json({
|
|
4516
|
-
message: "Successfully retrieved division.",
|
|
4517
|
-
data
|
|
4518
|
-
});
|
|
4519
|
-
return;
|
|
4520
|
-
} catch (error2) {
|
|
4521
|
-
next(error2);
|
|
4522
|
-
}
|
|
4523
|
-
}
|
|
4524
|
-
async function updateField(req, res, next) {
|
|
4525
|
-
const _id = req.params.id;
|
|
4526
|
-
const { field, value } = req.body;
|
|
4527
|
-
const validation = import_joi10.default.object({
|
|
4528
|
-
_id: import_joi10.default.string().hex().required(),
|
|
4529
|
-
field: import_joi10.default.string().valid("name", "director", "directorName").required(),
|
|
4530
|
-
value: import_joi10.default.string().required()
|
|
4531
|
-
});
|
|
4532
|
-
const { error } = validation.validate({ _id, field, value });
|
|
4533
|
-
if (error) {
|
|
4534
|
-
next(new import_nodejs_utils17.BadRequestError(error.message));
|
|
4535
|
-
return;
|
|
4536
|
-
}
|
|
4537
|
-
try {
|
|
4538
|
-
const message = await _updateFieldById({ _id, field, value });
|
|
4539
|
-
res.json({ message });
|
|
4540
|
-
return;
|
|
4541
|
-
} catch (error2) {
|
|
4542
|
-
next(error2);
|
|
4543
|
-
}
|
|
4544
|
-
}
|
|
4545
|
-
async function updateById(req, res, next) {
|
|
4546
|
-
const _id = req.params.id;
|
|
4547
|
-
const payload = req.body;
|
|
4548
|
-
const { error } = schemaDivisionUpdate.validate({ _id, ...payload });
|
|
4549
|
-
if (error) {
|
|
4550
|
-
next(new import_nodejs_utils17.BadRequestError(error.message));
|
|
4551
|
-
return;
|
|
4552
|
-
}
|
|
4553
|
-
try {
|
|
4554
|
-
const message = await _updateById(_id, payload);
|
|
4555
|
-
res.json({ message });
|
|
4556
|
-
return;
|
|
4557
|
-
} catch (error2) {
|
|
4558
|
-
next(error2);
|
|
4559
|
-
}
|
|
4560
|
-
}
|
|
4561
|
-
async function deleteById(req, res, next) {
|
|
4562
|
-
const _id = req.params.id;
|
|
4563
|
-
const validation = import_joi10.default.object({
|
|
4564
|
-
_id: import_joi10.default.string().hex().required()
|
|
4565
|
-
});
|
|
4566
|
-
const { error } = validation.validate({ _id });
|
|
4567
|
-
if (error) {
|
|
4568
|
-
next(new import_nodejs_utils17.BadRequestError(error.message));
|
|
4569
|
-
return;
|
|
4570
|
-
}
|
|
4571
|
-
try {
|
|
4572
|
-
const message = await _deleteById(_id);
|
|
4573
|
-
res.json({ message });
|
|
4574
|
-
return;
|
|
4575
|
-
} catch (error2) {
|
|
4576
|
-
next(error2);
|
|
4577
|
-
}
|
|
4578
|
-
}
|
|
4579
|
-
return {
|
|
4580
|
-
add,
|
|
4581
|
-
getAll,
|
|
4582
|
-
getById,
|
|
4583
|
-
getByName,
|
|
4584
|
-
updateField,
|
|
4585
|
-
updateById,
|
|
4586
|
-
deleteById
|
|
4587
|
-
};
|
|
4588
|
-
}
|
|
4383
|
+
var import_nodejs_utils20 = require("@eeplatform/nodejs-utils");
|
|
4384
|
+
var import_core2 = require("@eeplatform/core");
|
|
4589
4385
|
|
|
4590
4386
|
// src/resources/school/school.model.ts
|
|
4591
|
-
var
|
|
4592
|
-
var
|
|
4387
|
+
var import_nodejs_utils16 = require("@eeplatform/nodejs-utils");
|
|
4388
|
+
var import_joi10 = __toESM(require("joi"));
|
|
4593
4389
|
var import_mongodb11 = require("mongodb");
|
|
4594
|
-
var schemaSchool =
|
|
4595
|
-
_id:
|
|
4596
|
-
id:
|
|
4597
|
-
name:
|
|
4598
|
-
region:
|
|
4599
|
-
regionName:
|
|
4600
|
-
division:
|
|
4601
|
-
divisionName:
|
|
4602
|
-
principal:
|
|
4603
|
-
principalName:
|
|
4604
|
-
street:
|
|
4605
|
-
barangay:
|
|
4606
|
-
cityMunicipality:
|
|
4607
|
-
province:
|
|
4608
|
-
provincePSGC:
|
|
4609
|
-
cityMunicipalityPSGC:
|
|
4610
|
-
postalCode:
|
|
4611
|
-
contactNumber:
|
|
4612
|
-
email:
|
|
4613
|
-
status:
|
|
4614
|
-
createdBy:
|
|
4615
|
-
createdAt:
|
|
4616
|
-
updatedAt:
|
|
4617
|
-
deletedAt:
|
|
4390
|
+
var schemaSchool = import_joi10.default.object({
|
|
4391
|
+
_id: import_joi10.default.string().hex().optional().allow(null, ""),
|
|
4392
|
+
id: import_joi10.default.string().min(1).max(50).required(),
|
|
4393
|
+
name: import_joi10.default.string().min(1).max(100).required(),
|
|
4394
|
+
region: import_joi10.default.string().hex().required(),
|
|
4395
|
+
regionName: import_joi10.default.string().min(1).max(100).optional().allow(null, ""),
|
|
4396
|
+
division: import_joi10.default.string().hex().required(),
|
|
4397
|
+
divisionName: import_joi10.default.string().min(1).max(100).optional().allow(null, ""),
|
|
4398
|
+
principal: import_joi10.default.string().hex().optional().allow(null, ""),
|
|
4399
|
+
principalName: import_joi10.default.string().min(1).max(100).optional().allow(null, ""),
|
|
4400
|
+
street: import_joi10.default.string().max(200).optional().allow(null, ""),
|
|
4401
|
+
barangay: import_joi10.default.string().max(200).optional().allow(null, ""),
|
|
4402
|
+
cityMunicipality: import_joi10.default.string().max(100).optional().allow(null, ""),
|
|
4403
|
+
province: import_joi10.default.string().max(100).optional().allow(null, ""),
|
|
4404
|
+
provincePSGC: import_joi10.default.string().length(10).optional().allow(null, ""),
|
|
4405
|
+
cityMunicipalityPSGC: import_joi10.default.string().length(10).optional().allow(null, ""),
|
|
4406
|
+
postalCode: import_joi10.default.string().max(20).optional().allow(null, ""),
|
|
4407
|
+
contactNumber: import_joi10.default.string().max(20).optional().allow(null, ""),
|
|
4408
|
+
email: import_joi10.default.string().email().max(100).optional().allow(null, ""),
|
|
4409
|
+
status: import_joi10.default.string().optional().allow(null, ""),
|
|
4410
|
+
createdBy: import_joi10.default.string().optional().allow(null, ""),
|
|
4411
|
+
createdAt: import_joi10.default.string().isoDate().optional().allow(null, ""),
|
|
4412
|
+
updatedAt: import_joi10.default.string().isoDate().optional().allow(null, ""),
|
|
4413
|
+
deletedAt: import_joi10.default.string().isoDate().optional().allow(null, "")
|
|
4618
4414
|
});
|
|
4619
|
-
var schemaSchoolUpdate =
|
|
4620
|
-
id:
|
|
4621
|
-
name:
|
|
4622
|
-
region:
|
|
4623
|
-
regionName:
|
|
4624
|
-
division:
|
|
4625
|
-
divisionName:
|
|
4626
|
-
principal:
|
|
4627
|
-
principalName:
|
|
4628
|
-
street:
|
|
4629
|
-
barangay:
|
|
4630
|
-
cityMunicipality:
|
|
4631
|
-
province:
|
|
4632
|
-
provincePSGC:
|
|
4633
|
-
cityMunicipalityPSGC:
|
|
4634
|
-
postalCode:
|
|
4635
|
-
contactNumber:
|
|
4636
|
-
email:
|
|
4415
|
+
var schemaSchoolUpdate = import_joi10.default.object({
|
|
4416
|
+
id: import_joi10.default.string().min(1).max(50).required(),
|
|
4417
|
+
name: import_joi10.default.string().min(1).max(100).required(),
|
|
4418
|
+
region: import_joi10.default.string().hex().required(),
|
|
4419
|
+
regionName: import_joi10.default.string().min(1).max(100).optional().allow(null, ""),
|
|
4420
|
+
division: import_joi10.default.string().hex().required(),
|
|
4421
|
+
divisionName: import_joi10.default.string().min(1).max(100).optional().allow(null, ""),
|
|
4422
|
+
principal: import_joi10.default.string().hex().optional().allow(null, ""),
|
|
4423
|
+
principalName: import_joi10.default.string().min(1).max(100).optional().allow(null, ""),
|
|
4424
|
+
street: import_joi10.default.string().max(200).optional().allow(null, ""),
|
|
4425
|
+
barangay: import_joi10.default.string().max(200).optional().allow(null, ""),
|
|
4426
|
+
cityMunicipality: import_joi10.default.string().max(100).optional().allow(null, ""),
|
|
4427
|
+
province: import_joi10.default.string().max(100).optional().allow(null, ""),
|
|
4428
|
+
provincePSGC: import_joi10.default.string().length(10).optional().allow(null, ""),
|
|
4429
|
+
cityMunicipalityPSGC: import_joi10.default.string().length(10).optional().allow(null, ""),
|
|
4430
|
+
postalCode: import_joi10.default.string().max(20).optional().allow(null, ""),
|
|
4431
|
+
contactNumber: import_joi10.default.string().max(20).optional().allow(null, ""),
|
|
4432
|
+
email: import_joi10.default.string().email().max(100).optional().allow(null, "")
|
|
4637
4433
|
});
|
|
4638
4434
|
function modelSchool(value) {
|
|
4639
4435
|
const { error } = schemaSchool.validate(value);
|
|
4640
4436
|
if (error) {
|
|
4641
|
-
throw new
|
|
4437
|
+
throw new import_nodejs_utils16.BadRequestError(`Invalid sdo data: ${error.message}`);
|
|
4642
4438
|
}
|
|
4643
4439
|
if (value._id && typeof value._id === "string") {
|
|
4644
4440
|
try {
|
|
@@ -4686,8 +4482,8 @@ function modelSchool(value) {
|
|
|
4686
4482
|
contactNumber: value.contactNumber ?? "",
|
|
4687
4483
|
email: value.email ?? "",
|
|
4688
4484
|
status: value.status ?? "active",
|
|
4689
|
-
provincePSGC: value.provincePSGC ??
|
|
4690
|
-
cityMunicipalityPSGC: value.cityMunicipalityPSGC ??
|
|
4485
|
+
provincePSGC: value.provincePSGC ?? "",
|
|
4486
|
+
cityMunicipalityPSGC: value.cityMunicipalityPSGC ?? "",
|
|
4691
4487
|
createdBy: value.createdBy ?? "",
|
|
4692
4488
|
createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
4693
4489
|
updatedAt: value.updatedAt ?? "",
|
|
@@ -4696,16 +4492,16 @@ function modelSchool(value) {
|
|
|
4696
4492
|
}
|
|
4697
4493
|
|
|
4698
4494
|
// src/resources/school/school.repository.ts
|
|
4699
|
-
var
|
|
4495
|
+
var import_nodejs_utils17 = require("@eeplatform/nodejs-utils");
|
|
4700
4496
|
var import_mongodb12 = require("mongodb");
|
|
4701
4497
|
function useSchoolRepo() {
|
|
4702
|
-
const db =
|
|
4498
|
+
const db = import_nodejs_utils17.useAtlas.getDb();
|
|
4703
4499
|
if (!db) {
|
|
4704
4500
|
throw new Error("Unable to connect to server.");
|
|
4705
4501
|
}
|
|
4706
4502
|
const namespace_collection = "deped.schools";
|
|
4707
4503
|
const collection = db.collection(namespace_collection);
|
|
4708
|
-
const { getCache, setCache, delNamespace } = (0,
|
|
4504
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils17.useCache)(namespace_collection);
|
|
4709
4505
|
async function createIndexes() {
|
|
4710
4506
|
try {
|
|
4711
4507
|
await collection.createIndexes([
|
|
@@ -4720,12 +4516,12 @@ function useSchoolRepo() {
|
|
|
4720
4516
|
}
|
|
4721
4517
|
function delCachedData() {
|
|
4722
4518
|
delNamespace().then(() => {
|
|
4723
|
-
|
|
4519
|
+
import_nodejs_utils17.logger.log({
|
|
4724
4520
|
level: "info",
|
|
4725
4521
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
4726
4522
|
});
|
|
4727
4523
|
}).catch((err) => {
|
|
4728
|
-
|
|
4524
|
+
import_nodejs_utils17.logger.log({
|
|
4729
4525
|
level: "error",
|
|
4730
4526
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
4731
4527
|
});
|
|
@@ -4740,7 +4536,7 @@ function useSchoolRepo() {
|
|
|
4740
4536
|
}
|
|
4741
4537
|
return res.insertedId;
|
|
4742
4538
|
} catch (error) {
|
|
4743
|
-
|
|
4539
|
+
import_nodejs_utils17.logger.log({
|
|
4744
4540
|
level: "error",
|
|
4745
4541
|
message: `Failed to add school: ${error.message}`,
|
|
4746
4542
|
metadata: {
|
|
@@ -4752,14 +4548,14 @@ function useSchoolRepo() {
|
|
|
4752
4548
|
transactionNumber: error.errorResponse?.txnNumber || "unknown"
|
|
4753
4549
|
}
|
|
4754
4550
|
});
|
|
4755
|
-
if (error instanceof
|
|
4551
|
+
if (error instanceof import_nodejs_utils17.AppError) {
|
|
4756
4552
|
throw error;
|
|
4757
4553
|
} else {
|
|
4758
4554
|
const isDuplicated = error.message.includes("duplicate");
|
|
4759
4555
|
if (isDuplicated) {
|
|
4760
|
-
throw new
|
|
4556
|
+
throw new import_nodejs_utils17.BadRequestError("Duplicate, school already exists.");
|
|
4761
4557
|
}
|
|
4762
|
-
throw new
|
|
4558
|
+
throw new import_nodejs_utils17.InternalServerError("Failed to add school.");
|
|
4763
4559
|
}
|
|
4764
4560
|
}
|
|
4765
4561
|
}
|
|
@@ -4786,15 +4582,15 @@ function useSchoolRepo() {
|
|
|
4786
4582
|
query.$text = { $search: search };
|
|
4787
4583
|
cacheKeyOptions.search = search;
|
|
4788
4584
|
}
|
|
4789
|
-
const cacheKey = (0,
|
|
4790
|
-
|
|
4585
|
+
const cacheKey = (0, import_nodejs_utils17.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
4586
|
+
import_nodejs_utils17.logger.log({
|
|
4791
4587
|
level: "info",
|
|
4792
4588
|
message: `Cache key for getAll schools: ${cacheKey}`
|
|
4793
4589
|
});
|
|
4794
4590
|
try {
|
|
4795
4591
|
const cached = await getCache(cacheKey);
|
|
4796
4592
|
if (cached) {
|
|
4797
|
-
|
|
4593
|
+
import_nodejs_utils17.logger.log({
|
|
4798
4594
|
level: "info",
|
|
4799
4595
|
message: `Cache hit for getAll schools: ${cacheKey}`
|
|
4800
4596
|
});
|
|
@@ -4807,21 +4603,21 @@ function useSchoolRepo() {
|
|
|
4807
4603
|
{ $limit: limit }
|
|
4808
4604
|
]).toArray();
|
|
4809
4605
|
const length = await collection.countDocuments(query);
|
|
4810
|
-
const data = (0,
|
|
4606
|
+
const data = (0, import_nodejs_utils17.paginate)(items, page, limit, length);
|
|
4811
4607
|
setCache(cacheKey, data, 600).then(() => {
|
|
4812
|
-
|
|
4608
|
+
import_nodejs_utils17.logger.log({
|
|
4813
4609
|
level: "info",
|
|
4814
4610
|
message: `Cache set for getAll schools: ${cacheKey}`
|
|
4815
4611
|
});
|
|
4816
4612
|
}).catch((err) => {
|
|
4817
|
-
|
|
4613
|
+
import_nodejs_utils17.logger.log({
|
|
4818
4614
|
level: "error",
|
|
4819
4615
|
message: `Failed to set cache for getAll schools: ${err.message}`
|
|
4820
4616
|
});
|
|
4821
4617
|
});
|
|
4822
4618
|
return data;
|
|
4823
4619
|
} catch (error) {
|
|
4824
|
-
|
|
4620
|
+
import_nodejs_utils17.logger.log({ level: "error", message: `${error}` });
|
|
4825
4621
|
throw error;
|
|
4826
4622
|
}
|
|
4827
4623
|
}
|
|
@@ -4829,7 +4625,7 @@ function useSchoolRepo() {
|
|
|
4829
4625
|
try {
|
|
4830
4626
|
_id = new import_mongodb12.ObjectId(_id);
|
|
4831
4627
|
} catch (error) {
|
|
4832
|
-
throw new
|
|
4628
|
+
throw new import_nodejs_utils17.BadRequestError("Invalid ID.");
|
|
4833
4629
|
}
|
|
4834
4630
|
const query = { _id };
|
|
4835
4631
|
const cacheKeyOptions = {
|
|
@@ -4840,11 +4636,11 @@ function useSchoolRepo() {
|
|
|
4840
4636
|
query.status = status;
|
|
4841
4637
|
cacheKeyOptions.status = status;
|
|
4842
4638
|
}
|
|
4843
|
-
const cacheKey = (0,
|
|
4639
|
+
const cacheKey = (0, import_nodejs_utils17.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
4844
4640
|
try {
|
|
4845
4641
|
const cached = await getCache(cacheKey);
|
|
4846
4642
|
if (cached) {
|
|
4847
|
-
|
|
4643
|
+
import_nodejs_utils17.logger.log({
|
|
4848
4644
|
level: "info",
|
|
4849
4645
|
message: `Cache hit for getById school: ${cacheKey}`
|
|
4850
4646
|
});
|
|
@@ -4852,25 +4648,25 @@ function useSchoolRepo() {
|
|
|
4852
4648
|
}
|
|
4853
4649
|
const result = await collection.findOne(query);
|
|
4854
4650
|
if (!result) {
|
|
4855
|
-
throw new
|
|
4651
|
+
throw new import_nodejs_utils17.BadRequestError("School not found.");
|
|
4856
4652
|
}
|
|
4857
4653
|
setCache(cacheKey, result, 300).then(() => {
|
|
4858
|
-
|
|
4654
|
+
import_nodejs_utils17.logger.log({
|
|
4859
4655
|
level: "info",
|
|
4860
4656
|
message: `Cache set for school by id: ${cacheKey}`
|
|
4861
4657
|
});
|
|
4862
4658
|
}).catch((err) => {
|
|
4863
|
-
|
|
4659
|
+
import_nodejs_utils17.logger.log({
|
|
4864
4660
|
level: "error",
|
|
4865
4661
|
message: `Failed to set cache for school by id: ${err.message}`
|
|
4866
4662
|
});
|
|
4867
4663
|
});
|
|
4868
4664
|
return result;
|
|
4869
4665
|
} catch (error) {
|
|
4870
|
-
if (error instanceof
|
|
4666
|
+
if (error instanceof import_nodejs_utils17.AppError) {
|
|
4871
4667
|
throw error;
|
|
4872
4668
|
} else {
|
|
4873
|
-
throw new
|
|
4669
|
+
throw new import_nodejs_utils17.InternalServerError("Failed to get school.");
|
|
4874
4670
|
}
|
|
4875
4671
|
}
|
|
4876
4672
|
}
|
|
@@ -4878,13 +4674,13 @@ function useSchoolRepo() {
|
|
|
4878
4674
|
try {
|
|
4879
4675
|
createdBy = new import_mongodb12.ObjectId(createdBy);
|
|
4880
4676
|
} catch (error) {
|
|
4881
|
-
throw new
|
|
4677
|
+
throw new import_nodejs_utils17.BadRequestError("Invalid ID.");
|
|
4882
4678
|
}
|
|
4883
|
-
const cacheKey = (0,
|
|
4679
|
+
const cacheKey = (0, import_nodejs_utils17.makeCacheKey)(namespace_collection, { createdBy });
|
|
4884
4680
|
try {
|
|
4885
4681
|
const cached = await getCache(cacheKey);
|
|
4886
4682
|
if (cached) {
|
|
4887
|
-
|
|
4683
|
+
import_nodejs_utils17.logger.log({
|
|
4888
4684
|
level: "info",
|
|
4889
4685
|
message: `Cache hit for getById school: ${cacheKey}`
|
|
4890
4686
|
});
|
|
@@ -4895,34 +4691,34 @@ function useSchoolRepo() {
|
|
|
4895
4691
|
status: "pending"
|
|
4896
4692
|
});
|
|
4897
4693
|
if (!result) {
|
|
4898
|
-
throw new
|
|
4694
|
+
throw new import_nodejs_utils17.BadRequestError("School not found.");
|
|
4899
4695
|
}
|
|
4900
4696
|
setCache(cacheKey, result, 300).then(() => {
|
|
4901
|
-
|
|
4697
|
+
import_nodejs_utils17.logger.log({
|
|
4902
4698
|
level: "info",
|
|
4903
4699
|
message: `Cache set for school by id: ${cacheKey}`
|
|
4904
4700
|
});
|
|
4905
4701
|
}).catch((err) => {
|
|
4906
|
-
|
|
4702
|
+
import_nodejs_utils17.logger.log({
|
|
4907
4703
|
level: "error",
|
|
4908
4704
|
message: `Failed to set cache for school by id: ${err.message}`
|
|
4909
4705
|
});
|
|
4910
4706
|
});
|
|
4911
4707
|
return result;
|
|
4912
4708
|
} catch (error) {
|
|
4913
|
-
if (error instanceof
|
|
4709
|
+
if (error instanceof import_nodejs_utils17.AppError) {
|
|
4914
4710
|
throw error;
|
|
4915
4711
|
} else {
|
|
4916
|
-
throw new
|
|
4712
|
+
throw new import_nodejs_utils17.InternalServerError("Failed to get school.");
|
|
4917
4713
|
}
|
|
4918
4714
|
}
|
|
4919
4715
|
}
|
|
4920
4716
|
async function getByName(name) {
|
|
4921
|
-
const cacheKey = (0,
|
|
4717
|
+
const cacheKey = (0, import_nodejs_utils17.makeCacheKey)(namespace_collection, { name });
|
|
4922
4718
|
try {
|
|
4923
4719
|
const cached = await getCache(cacheKey);
|
|
4924
4720
|
if (cached) {
|
|
4925
|
-
|
|
4721
|
+
import_nodejs_utils17.logger.log({
|
|
4926
4722
|
level: "info",
|
|
4927
4723
|
message: `Cache hit for getByName school: ${cacheKey}`
|
|
4928
4724
|
});
|
|
@@ -4933,25 +4729,25 @@ function useSchoolRepo() {
|
|
|
4933
4729
|
deletedAt: { $in: ["", null] }
|
|
4934
4730
|
});
|
|
4935
4731
|
if (!result) {
|
|
4936
|
-
throw new
|
|
4732
|
+
throw new import_nodejs_utils17.BadRequestError("School not found.");
|
|
4937
4733
|
}
|
|
4938
4734
|
setCache(cacheKey, result, 300).then(() => {
|
|
4939
|
-
|
|
4735
|
+
import_nodejs_utils17.logger.log({
|
|
4940
4736
|
level: "info",
|
|
4941
4737
|
message: `Cache set for school by name: ${cacheKey}`
|
|
4942
4738
|
});
|
|
4943
4739
|
}).catch((err) => {
|
|
4944
|
-
|
|
4740
|
+
import_nodejs_utils17.logger.log({
|
|
4945
4741
|
level: "error",
|
|
4946
4742
|
message: `Failed to set cache for school by name: ${err.message}`
|
|
4947
4743
|
});
|
|
4948
4744
|
});
|
|
4949
4745
|
return result;
|
|
4950
4746
|
} catch (error) {
|
|
4951
|
-
if (error instanceof
|
|
4747
|
+
if (error instanceof import_nodejs_utils17.AppError) {
|
|
4952
4748
|
throw error;
|
|
4953
4749
|
} else {
|
|
4954
|
-
throw new
|
|
4750
|
+
throw new import_nodejs_utils17.InternalServerError("Failed to get school.");
|
|
4955
4751
|
}
|
|
4956
4752
|
}
|
|
4957
4753
|
}
|
|
@@ -4959,7 +4755,7 @@ function useSchoolRepo() {
|
|
|
4959
4755
|
try {
|
|
4960
4756
|
_id = new import_mongodb12.ObjectId(_id);
|
|
4961
4757
|
} catch (error) {
|
|
4962
|
-
throw new
|
|
4758
|
+
throw new import_nodejs_utils17.BadRequestError("Invalid ID.");
|
|
4963
4759
|
}
|
|
4964
4760
|
try {
|
|
4965
4761
|
await collection.updateOne(
|
|
@@ -4970,24 +4766,30 @@ function useSchoolRepo() {
|
|
|
4970
4766
|
delCachedData();
|
|
4971
4767
|
return `Successfully updated school status to ${status}.`;
|
|
4972
4768
|
} catch (error) {
|
|
4973
|
-
if (error instanceof
|
|
4769
|
+
if (error instanceof import_nodejs_utils17.AppError) {
|
|
4974
4770
|
throw error;
|
|
4975
4771
|
} else {
|
|
4976
|
-
throw new
|
|
4772
|
+
throw new import_nodejs_utils17.InternalServerError("Failed to update school status.");
|
|
4977
4773
|
}
|
|
4978
4774
|
}
|
|
4979
4775
|
}
|
|
4980
4776
|
async function updateFieldById({ _id, field, value } = {}, session) {
|
|
4981
|
-
const allowedFields = [
|
|
4777
|
+
const allowedFields = [
|
|
4778
|
+
"name",
|
|
4779
|
+
"division",
|
|
4780
|
+
"divisionName",
|
|
4781
|
+
"region",
|
|
4782
|
+
"regionName"
|
|
4783
|
+
];
|
|
4982
4784
|
if (!allowedFields.includes(field)) {
|
|
4983
|
-
throw new
|
|
4785
|
+
throw new import_nodejs_utils17.BadRequestError(
|
|
4984
4786
|
`Field "${field}" is not allowed to be updated.`
|
|
4985
4787
|
);
|
|
4986
4788
|
}
|
|
4987
4789
|
try {
|
|
4988
4790
|
_id = new import_mongodb12.ObjectId(_id);
|
|
4989
4791
|
} catch (error) {
|
|
4990
|
-
throw new
|
|
4792
|
+
throw new import_nodejs_utils17.BadRequestError("Invalid ID.");
|
|
4991
4793
|
}
|
|
4992
4794
|
try {
|
|
4993
4795
|
await collection.updateOne(
|
|
@@ -4998,32 +4800,56 @@ function useSchoolRepo() {
|
|
|
4998
4800
|
delCachedData();
|
|
4999
4801
|
return `Successfully updated school ${field}.`;
|
|
5000
4802
|
} catch (error) {
|
|
5001
|
-
throw new
|
|
4803
|
+
throw new import_nodejs_utils17.InternalServerError(`Failed to update school ${field}.`);
|
|
4804
|
+
}
|
|
4805
|
+
}
|
|
4806
|
+
async function updateDivisionNameByDivision(division, name, session) {
|
|
4807
|
+
try {
|
|
4808
|
+
division = new import_mongodb12.ObjectId(division);
|
|
4809
|
+
} catch (error) {
|
|
4810
|
+
throw new import_nodejs_utils17.BadRequestError("Invalid division.");
|
|
4811
|
+
}
|
|
4812
|
+
try {
|
|
4813
|
+
const result = await collection.updateMany(
|
|
4814
|
+
{ division },
|
|
4815
|
+
{ $set: { divisionName: name, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
4816
|
+
{ session }
|
|
4817
|
+
);
|
|
4818
|
+
if (result.modifiedCount === 0) {
|
|
4819
|
+
import_nodejs_utils17.logger.log({
|
|
4820
|
+
level: "info",
|
|
4821
|
+
message: `No schools found for division ${division} to update divisionName.`
|
|
4822
|
+
});
|
|
4823
|
+
}
|
|
4824
|
+
delCachedData();
|
|
4825
|
+
return `Successfully updated school divisionName.`;
|
|
4826
|
+
} catch (error) {
|
|
4827
|
+
throw new import_nodejs_utils17.InternalServerError(`Failed to update school divisionName.`);
|
|
5002
4828
|
}
|
|
5003
4829
|
}
|
|
5004
4830
|
async function updateById(_id, options, session) {
|
|
5005
4831
|
const { error } = schemaSchoolUpdate.validate(options);
|
|
5006
4832
|
if (error) {
|
|
5007
|
-
throw new
|
|
4833
|
+
throw new import_nodejs_utils17.BadRequestError(`Invalid school data: ${error.message}`);
|
|
5008
4834
|
}
|
|
5009
4835
|
try {
|
|
5010
4836
|
_id = new import_mongodb12.ObjectId(_id);
|
|
5011
4837
|
} catch (error2) {
|
|
5012
|
-
throw new
|
|
4838
|
+
throw new import_nodejs_utils17.BadRequestError("Invalid ID.");
|
|
5013
4839
|
}
|
|
5014
4840
|
try {
|
|
5015
4841
|
await collection.updateOne({ _id }, { $set: options }, { session });
|
|
5016
4842
|
delCachedData();
|
|
5017
4843
|
return `Successfully updated school.`;
|
|
5018
4844
|
} catch (error2) {
|
|
5019
|
-
throw new
|
|
4845
|
+
throw new import_nodejs_utils17.InternalServerError(`Failed to update school.`);
|
|
5020
4846
|
}
|
|
5021
4847
|
}
|
|
5022
4848
|
async function deleteById(_id) {
|
|
5023
4849
|
try {
|
|
5024
4850
|
_id = new import_mongodb12.ObjectId(_id);
|
|
5025
4851
|
} catch (error) {
|
|
5026
|
-
throw new
|
|
4852
|
+
throw new import_nodejs_utils17.BadRequestError("Invalid ID.");
|
|
5027
4853
|
}
|
|
5028
4854
|
try {
|
|
5029
4855
|
await collection.updateOne(
|
|
@@ -5033,7 +4859,7 @@ function useSchoolRepo() {
|
|
|
5033
4859
|
delCachedData();
|
|
5034
4860
|
return "Successfully deleted school.";
|
|
5035
4861
|
} catch (error) {
|
|
5036
|
-
throw new
|
|
4862
|
+
throw new import_nodejs_utils17.InternalServerError("Failed to delete school.");
|
|
5037
4863
|
}
|
|
5038
4864
|
}
|
|
5039
4865
|
return {
|
|
@@ -5047,13 +4873,14 @@ function useSchoolRepo() {
|
|
|
5047
4873
|
updateById,
|
|
5048
4874
|
deleteById,
|
|
5049
4875
|
getByName,
|
|
5050
|
-
delCachedData
|
|
4876
|
+
delCachedData,
|
|
4877
|
+
updateDivisionNameByDivision
|
|
5051
4878
|
};
|
|
5052
4879
|
}
|
|
5053
4880
|
|
|
5054
4881
|
// src/resources/school/school.service.ts
|
|
5055
|
-
var
|
|
5056
|
-
var
|
|
4882
|
+
var import_nodejs_utils18 = require("@eeplatform/nodejs-utils");
|
|
4883
|
+
var import_core = require("@eeplatform/core");
|
|
5057
4884
|
|
|
5058
4885
|
// node_modules/xlsx/xlsx.mjs
|
|
5059
4886
|
var XLSX = {};
|
|
@@ -33221,17 +33048,17 @@ function useSchoolService() {
|
|
|
33221
33048
|
getById,
|
|
33222
33049
|
delCachedData: delCachedSchoolData
|
|
33223
33050
|
} = useSchoolRepo();
|
|
33224
|
-
const { addRole, delCachedData: delCachedRoleData } = (0,
|
|
33225
|
-
const { getUserById } = (0,
|
|
33226
|
-
const { add: addMember } = (0,
|
|
33051
|
+
const { addRole, delCachedData: delCachedRoleData } = (0, import_core.useRoleRepo)();
|
|
33052
|
+
const { getUserById } = (0, import_core.useUserRepo)();
|
|
33053
|
+
const { add: addMember } = (0, import_core.useMemberRepo)();
|
|
33227
33054
|
async function register(value) {
|
|
33228
33055
|
const { error } = schemaSchool.validate(value);
|
|
33229
33056
|
if (error) {
|
|
33230
|
-
throw new
|
|
33057
|
+
throw new import_nodejs_utils18.BadRequestError(error.message);
|
|
33231
33058
|
}
|
|
33232
33059
|
const existingSchool = await getPendingByCreatedBy(value.createdBy ?? "");
|
|
33233
33060
|
if (existingSchool) {
|
|
33234
|
-
throw new
|
|
33061
|
+
throw new import_nodejs_utils18.BadRequestError(
|
|
33235
33062
|
"You already have a pending school registration."
|
|
33236
33063
|
);
|
|
33237
33064
|
}
|
|
@@ -33246,9 +33073,9 @@ function useSchoolService() {
|
|
|
33246
33073
|
async function approve(id) {
|
|
33247
33074
|
const school = await getById(id, "pending");
|
|
33248
33075
|
if (!school) {
|
|
33249
|
-
throw new
|
|
33076
|
+
throw new import_nodejs_utils18.BadRequestError("School registration not found.");
|
|
33250
33077
|
}
|
|
33251
|
-
const session =
|
|
33078
|
+
const session = import_nodejs_utils18.useAtlas.getClient()?.startSession();
|
|
33252
33079
|
if (!session) {
|
|
33253
33080
|
throw new Error("Unable to start session for school service.");
|
|
33254
33081
|
}
|
|
@@ -33270,11 +33097,11 @@ function useSchoolService() {
|
|
|
33270
33097
|
session
|
|
33271
33098
|
);
|
|
33272
33099
|
if (!school.createdBy) {
|
|
33273
|
-
throw new
|
|
33100
|
+
throw new import_nodejs_utils18.BadRequestError("School must have a creator.");
|
|
33274
33101
|
}
|
|
33275
33102
|
const user = await getUserById(school.createdBy ?? "");
|
|
33276
33103
|
if (!user) {
|
|
33277
|
-
throw new
|
|
33104
|
+
throw new import_nodejs_utils18.BadRequestError("User not found for the school creator.");
|
|
33278
33105
|
}
|
|
33279
33106
|
await addMember(
|
|
33280
33107
|
{
|
|
@@ -33291,7 +33118,7 @@ function useSchoolService() {
|
|
|
33291
33118
|
await session.commitTransaction();
|
|
33292
33119
|
return "School registration has been approved.";
|
|
33293
33120
|
} catch (error) {
|
|
33294
|
-
|
|
33121
|
+
import_nodejs_utils18.logger.log({
|
|
33295
33122
|
level: "error",
|
|
33296
33123
|
message: `Error approving school registration: ${error.message}`
|
|
33297
33124
|
});
|
|
@@ -33304,9 +33131,9 @@ function useSchoolService() {
|
|
|
33304
33131
|
async function add(value) {
|
|
33305
33132
|
const { error } = schemaSchool.validate(value);
|
|
33306
33133
|
if (error) {
|
|
33307
|
-
throw new
|
|
33134
|
+
throw new import_nodejs_utils18.BadRequestError(error.message);
|
|
33308
33135
|
}
|
|
33309
|
-
const session =
|
|
33136
|
+
const session = import_nodejs_utils18.useAtlas.getClient()?.startSession();
|
|
33310
33137
|
if (!session) {
|
|
33311
33138
|
throw new Error("Unable to start session for school service.");
|
|
33312
33139
|
}
|
|
@@ -33328,11 +33155,11 @@ function useSchoolService() {
|
|
|
33328
33155
|
session
|
|
33329
33156
|
);
|
|
33330
33157
|
if (!value.createdBy) {
|
|
33331
|
-
throw new
|
|
33158
|
+
throw new import_nodejs_utils18.BadRequestError("School must have a creator.");
|
|
33332
33159
|
}
|
|
33333
33160
|
const user = await getUserById(value.createdBy ?? "");
|
|
33334
33161
|
if (!user) {
|
|
33335
|
-
throw new
|
|
33162
|
+
throw new import_nodejs_utils18.BadRequestError("User not found for the school creator.");
|
|
33336
33163
|
}
|
|
33337
33164
|
await addMember(
|
|
33338
33165
|
{
|
|
@@ -33349,7 +33176,7 @@ function useSchoolService() {
|
|
|
33349
33176
|
await session.commitTransaction();
|
|
33350
33177
|
return "School has been added and activated successfully.";
|
|
33351
33178
|
} catch (error2) {
|
|
33352
|
-
|
|
33179
|
+
import_nodejs_utils18.logger.log({
|
|
33353
33180
|
level: "error",
|
|
33354
33181
|
message: `Error adding school: ${error2.message}`
|
|
33355
33182
|
});
|
|
@@ -33363,7 +33190,7 @@ function useSchoolService() {
|
|
|
33363
33190
|
const isCSV = file.mimetype.includes("csv") || file.originalname.endsWith(".csv");
|
|
33364
33191
|
const isExcel = file.mimetype.includes("sheet") || file.originalname.endsWith(".xlsx") || file.originalname.endsWith(".xls");
|
|
33365
33192
|
if (!isCSV && !isExcel) {
|
|
33366
|
-
throw new
|
|
33193
|
+
throw new import_nodejs_utils18.BadRequestError("Only CSV and Excel files are supported");
|
|
33367
33194
|
}
|
|
33368
33195
|
let rawData = [];
|
|
33369
33196
|
try {
|
|
@@ -33380,17 +33207,17 @@ function useSchoolService() {
|
|
|
33380
33207
|
transformHeader: (header) => header.trim()
|
|
33381
33208
|
});
|
|
33382
33209
|
if (parseResult.errors.length > 0) {
|
|
33383
|
-
throw new
|
|
33210
|
+
throw new import_nodejs_utils18.BadRequestError(
|
|
33384
33211
|
`CSV parsing error: ${parseResult.errors[0].message}`
|
|
33385
33212
|
);
|
|
33386
33213
|
}
|
|
33387
33214
|
rawData = parseResult.data;
|
|
33388
33215
|
}
|
|
33389
33216
|
} catch (error) {
|
|
33390
|
-
throw new
|
|
33217
|
+
throw new import_nodejs_utils18.BadRequestError(`File parsing error: ${error.message}`);
|
|
33391
33218
|
}
|
|
33392
33219
|
if (!rawData.length) {
|
|
33393
|
-
throw new
|
|
33220
|
+
throw new import_nodejs_utils18.BadRequestError("No data found in file");
|
|
33394
33221
|
}
|
|
33395
33222
|
const schools = [];
|
|
33396
33223
|
const errors = [];
|
|
@@ -33436,7 +33263,7 @@ function useSchoolService() {
|
|
|
33436
33263
|
schools.push(school);
|
|
33437
33264
|
}
|
|
33438
33265
|
if (errors.length > 0) {
|
|
33439
|
-
throw new
|
|
33266
|
+
throw new import_nodejs_utils18.BadRequestError(
|
|
33440
33267
|
`Validation errors:
|
|
33441
33268
|
${errors.slice(0, 5).join("\n")}${errors.length > 5 ? `
|
|
33442
33269
|
...and ${errors.length - 5} more` : ""}`
|
|
@@ -33448,9 +33275,9 @@ ${errors.slice(0, 5).join("\n")}${errors.length > 5 ? `
|
|
|
33448
33275
|
skipped: 0,
|
|
33449
33276
|
errors: []
|
|
33450
33277
|
};
|
|
33451
|
-
const { getByName: getPSGCByName } = (0,
|
|
33278
|
+
const { getByName: getPSGCByName } = (0, import_core.usePSGCRepo)();
|
|
33452
33279
|
for (let i = 0; i < schools.length; i++) {
|
|
33453
|
-
const session =
|
|
33280
|
+
const session = import_nodejs_utils18.useAtlas.getClient()?.startSession();
|
|
33454
33281
|
if (!session) {
|
|
33455
33282
|
throw new Error("Unable to start MongoDB session");
|
|
33456
33283
|
}
|
|
@@ -33462,22 +33289,22 @@ ${errors.slice(0, 5).join("\n")}${errors.length > 5 ? `
|
|
|
33462
33289
|
type: "Prov"
|
|
33463
33290
|
});
|
|
33464
33291
|
if (!provincePSGC) {
|
|
33465
|
-
throw new
|
|
33292
|
+
throw new import_nodejs_utils18.BadRequestError(
|
|
33466
33293
|
`Province '${school.province}' not found in PSGC data.`
|
|
33467
33294
|
);
|
|
33468
33295
|
}
|
|
33469
33296
|
const cityMunPSGC = await getPSGCByName({
|
|
33470
33297
|
name: school.cityMunicipality ?? "",
|
|
33471
|
-
|
|
33472
|
-
|
|
33298
|
+
type: "City",
|
|
33299
|
+
prefix: provincePSGC.code.toString().slice(0, 5)
|
|
33473
33300
|
});
|
|
33474
33301
|
if (!cityMunPSGC) {
|
|
33475
|
-
throw new
|
|
33302
|
+
throw new import_nodejs_utils18.BadRequestError(
|
|
33476
33303
|
`City/Municipality '${school.cityMunicipality}' not found in PSGC data.`
|
|
33477
33304
|
);
|
|
33478
33305
|
}
|
|
33479
|
-
school.provincePSGC = provincePSGC.code ??
|
|
33480
|
-
school.cityMunicipalityPSGC = cityMunPSGC.code ??
|
|
33306
|
+
school.provincePSGC = provincePSGC.code ?? "";
|
|
33307
|
+
school.cityMunicipalityPSGC = cityMunPSGC.code ?? "";
|
|
33481
33308
|
const schoolId = await addSchool(school, session, false);
|
|
33482
33309
|
await addRole(
|
|
33483
33310
|
{
|
|
@@ -33524,8 +33351,8 @@ ${errors.slice(0, 5).join("\n")}${errors.length > 5 ? `
|
|
|
33524
33351
|
}
|
|
33525
33352
|
|
|
33526
33353
|
// src/resources/school/school.controller.ts
|
|
33527
|
-
var
|
|
33528
|
-
var
|
|
33354
|
+
var import_nodejs_utils19 = require("@eeplatform/nodejs-utils");
|
|
33355
|
+
var import_joi11 = __toESM(require("joi"));
|
|
33529
33356
|
function useSchoolController() {
|
|
33530
33357
|
const {
|
|
33531
33358
|
getAll: _getAll,
|
|
@@ -33545,7 +33372,7 @@ function useSchoolController() {
|
|
|
33545
33372
|
const payload = req.body;
|
|
33546
33373
|
const { error } = schemaSchool.validate(payload);
|
|
33547
33374
|
if (error) {
|
|
33548
|
-
next(new
|
|
33375
|
+
next(new import_nodejs_utils19.BadRequestError(`Validation error: ${error.message}`));
|
|
33549
33376
|
return;
|
|
33550
33377
|
}
|
|
33551
33378
|
try {
|
|
@@ -33558,19 +33385,19 @@ function useSchoolController() {
|
|
|
33558
33385
|
}
|
|
33559
33386
|
}
|
|
33560
33387
|
async function getAll(req, res, next) {
|
|
33561
|
-
const validation =
|
|
33562
|
-
page:
|
|
33563
|
-
limit:
|
|
33564
|
-
sort:
|
|
33565
|
-
sortOrder:
|
|
33566
|
-
status:
|
|
33567
|
-
org:
|
|
33568
|
-
app:
|
|
33569
|
-
search:
|
|
33388
|
+
const validation = import_joi11.default.object({
|
|
33389
|
+
page: import_joi11.default.number().optional().allow(null, ""),
|
|
33390
|
+
limit: import_joi11.default.number().optional().allow(null, ""),
|
|
33391
|
+
sort: import_joi11.default.string().optional().allow(null, ""),
|
|
33392
|
+
sortOrder: import_joi11.default.string().optional().allow(null, ""),
|
|
33393
|
+
status: import_joi11.default.string().optional().allow(null, ""),
|
|
33394
|
+
org: import_joi11.default.string().hex().optional().allow(null, ""),
|
|
33395
|
+
app: import_joi11.default.string().optional().allow(null, ""),
|
|
33396
|
+
search: import_joi11.default.string().optional().allow(null, "")
|
|
33570
33397
|
});
|
|
33571
33398
|
const { error } = validation.validate(req.query);
|
|
33572
33399
|
if (error) {
|
|
33573
|
-
next(new
|
|
33400
|
+
next(new import_nodejs_utils19.BadRequestError(`Validation error: ${error.message}`));
|
|
33574
33401
|
return;
|
|
33575
33402
|
}
|
|
33576
33403
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -33602,10 +33429,10 @@ function useSchoolController() {
|
|
|
33602
33429
|
}
|
|
33603
33430
|
async function getByCreatedBy(req, res, next) {
|
|
33604
33431
|
const createdBy = req.params.createdBy;
|
|
33605
|
-
const validation =
|
|
33432
|
+
const validation = import_joi11.default.string().hex().required();
|
|
33606
33433
|
const { error } = validation.validate(createdBy);
|
|
33607
33434
|
if (error) {
|
|
33608
|
-
next(new
|
|
33435
|
+
next(new import_nodejs_utils19.BadRequestError(`Validation error: ${error.message}`));
|
|
33609
33436
|
return;
|
|
33610
33437
|
}
|
|
33611
33438
|
try {
|
|
@@ -33619,13 +33446,13 @@ function useSchoolController() {
|
|
|
33619
33446
|
async function updateStatusById(req, res, next) {
|
|
33620
33447
|
const schoolId = req.params.id;
|
|
33621
33448
|
const status = req.params.status;
|
|
33622
|
-
const validation =
|
|
33623
|
-
id:
|
|
33624
|
-
status:
|
|
33449
|
+
const validation = import_joi11.default.object({
|
|
33450
|
+
id: import_joi11.default.string().hex().required(),
|
|
33451
|
+
status: import_joi11.default.string().valid("active", "deleted", "suspended").required()
|
|
33625
33452
|
});
|
|
33626
33453
|
const { error } = validation.validate({ id: schoolId, status });
|
|
33627
33454
|
if (error) {
|
|
33628
|
-
next(new
|
|
33455
|
+
next(new import_nodejs_utils19.BadRequestError(`Validation error: ${error.message}`));
|
|
33629
33456
|
return;
|
|
33630
33457
|
}
|
|
33631
33458
|
try {
|
|
@@ -33640,7 +33467,7 @@ function useSchoolController() {
|
|
|
33640
33467
|
const payload = req.body;
|
|
33641
33468
|
const { error } = schemaSchool.validate(payload);
|
|
33642
33469
|
if (error) {
|
|
33643
|
-
next(new
|
|
33470
|
+
next(new import_nodejs_utils19.BadRequestError(`Validation error: ${error.message}`));
|
|
33644
33471
|
return;
|
|
33645
33472
|
}
|
|
33646
33473
|
try {
|
|
@@ -33654,12 +33481,12 @@ function useSchoolController() {
|
|
|
33654
33481
|
}
|
|
33655
33482
|
async function approveSchool(req, res, next) {
|
|
33656
33483
|
const schoolId = req.params.id;
|
|
33657
|
-
const validation =
|
|
33658
|
-
id:
|
|
33484
|
+
const validation = import_joi11.default.object({
|
|
33485
|
+
id: import_joi11.default.string().hex().required()
|
|
33659
33486
|
});
|
|
33660
33487
|
const { error } = validation.validate({ id: schoolId });
|
|
33661
33488
|
if (error) {
|
|
33662
|
-
next(new
|
|
33489
|
+
next(new import_nodejs_utils19.BadRequestError(`Validation error: ${error.message}`));
|
|
33663
33490
|
return;
|
|
33664
33491
|
}
|
|
33665
33492
|
try {
|
|
@@ -33678,11 +33505,11 @@ function useSchoolController() {
|
|
|
33678
33505
|
return;
|
|
33679
33506
|
}
|
|
33680
33507
|
const { region, regionName, division, divisionName } = req.body;
|
|
33681
|
-
const validation =
|
|
33682
|
-
region:
|
|
33683
|
-
regionName:
|
|
33684
|
-
division:
|
|
33685
|
-
divisionName:
|
|
33508
|
+
const validation = import_joi11.default.object({
|
|
33509
|
+
region: import_joi11.default.string().hex().required(),
|
|
33510
|
+
regionName: import_joi11.default.string().min(1).required(),
|
|
33511
|
+
division: import_joi11.default.string().hex().required(),
|
|
33512
|
+
divisionName: import_joi11.default.string().min(1).required()
|
|
33686
33513
|
});
|
|
33687
33514
|
const { error } = validation.validate({
|
|
33688
33515
|
region,
|
|
@@ -33691,7 +33518,7 @@ function useSchoolController() {
|
|
|
33691
33518
|
divisionName
|
|
33692
33519
|
});
|
|
33693
33520
|
if (error) {
|
|
33694
|
-
next(new
|
|
33521
|
+
next(new import_nodejs_utils19.BadRequestError(`Validation error: ${error.message}`));
|
|
33695
33522
|
return;
|
|
33696
33523
|
}
|
|
33697
33524
|
try {
|
|
@@ -33711,14 +33538,14 @@ function useSchoolController() {
|
|
|
33711
33538
|
async function updateFieldById(req, res, next) {
|
|
33712
33539
|
const _id = req.params.id;
|
|
33713
33540
|
const { field, value } = req.body;
|
|
33714
|
-
const validation =
|
|
33715
|
-
_id:
|
|
33716
|
-
field:
|
|
33717
|
-
value:
|
|
33541
|
+
const validation = import_joi11.default.object({
|
|
33542
|
+
_id: import_joi11.default.string().hex().required(),
|
|
33543
|
+
field: import_joi11.default.string().valid("name", "director", "directorName").required(),
|
|
33544
|
+
value: import_joi11.default.string().required()
|
|
33718
33545
|
});
|
|
33719
33546
|
const { error } = validation.validate({ _id, field, value });
|
|
33720
33547
|
if (error) {
|
|
33721
|
-
next(new
|
|
33548
|
+
next(new import_nodejs_utils19.BadRequestError(error.message));
|
|
33722
33549
|
return;
|
|
33723
33550
|
}
|
|
33724
33551
|
try {
|
|
@@ -33732,17 +33559,17 @@ function useSchoolController() {
|
|
|
33732
33559
|
async function updateById(req, res, next) {
|
|
33733
33560
|
const id = req.params.id;
|
|
33734
33561
|
const payload = req.body;
|
|
33735
|
-
const validation =
|
|
33736
|
-
id:
|
|
33562
|
+
const validation = import_joi11.default.object({
|
|
33563
|
+
id: import_joi11.default.string().hex().required()
|
|
33737
33564
|
});
|
|
33738
33565
|
const { error: idError } = validation.validate({ id });
|
|
33739
33566
|
if (idError) {
|
|
33740
|
-
next(new
|
|
33567
|
+
next(new import_nodejs_utils19.BadRequestError(idError.message));
|
|
33741
33568
|
return;
|
|
33742
33569
|
}
|
|
33743
33570
|
const { error } = schemaSchoolUpdate.validate(payload);
|
|
33744
33571
|
if (error) {
|
|
33745
|
-
next(new
|
|
33572
|
+
next(new import_nodejs_utils19.BadRequestError(error.message));
|
|
33746
33573
|
return;
|
|
33747
33574
|
}
|
|
33748
33575
|
try {
|
|
@@ -33755,12 +33582,12 @@ function useSchoolController() {
|
|
|
33755
33582
|
}
|
|
33756
33583
|
async function deleteById(req, res, next) {
|
|
33757
33584
|
const _id = req.params.id;
|
|
33758
|
-
const validation =
|
|
33759
|
-
_id:
|
|
33585
|
+
const validation = import_joi11.default.object({
|
|
33586
|
+
_id: import_joi11.default.string().hex().required()
|
|
33760
33587
|
});
|
|
33761
33588
|
const { error } = validation.validate({ _id });
|
|
33762
33589
|
if (error) {
|
|
33763
|
-
next(new
|
|
33590
|
+
next(new import_nodejs_utils19.BadRequestError(error.message));
|
|
33764
33591
|
return;
|
|
33765
33592
|
}
|
|
33766
33593
|
try {
|
|
@@ -33785,6 +33612,245 @@ function useSchoolController() {
|
|
|
33785
33612
|
};
|
|
33786
33613
|
}
|
|
33787
33614
|
|
|
33615
|
+
// src/resources/division/division.service.ts
|
|
33616
|
+
function useDivisionService() {
|
|
33617
|
+
const {
|
|
33618
|
+
add: _add,
|
|
33619
|
+
updateById: _updateById,
|
|
33620
|
+
getById: _getById
|
|
33621
|
+
} = useDivisionRepo();
|
|
33622
|
+
const { addRole } = (0, import_core2.useRoleRepo)();
|
|
33623
|
+
const { updateDivisionNameByDivision } = useSchoolRepo();
|
|
33624
|
+
async function add(value) {
|
|
33625
|
+
const session = import_nodejs_utils20.useAtlas.getClient()?.startSession();
|
|
33626
|
+
if (!session) {
|
|
33627
|
+
throw new Error("Unable to start session for division service.");
|
|
33628
|
+
}
|
|
33629
|
+
try {
|
|
33630
|
+
session.startTransaction();
|
|
33631
|
+
const division = await _add(value, session);
|
|
33632
|
+
await addRole(
|
|
33633
|
+
{
|
|
33634
|
+
id: division.toString(),
|
|
33635
|
+
name: "Admin",
|
|
33636
|
+
type: "basic-edu-sdo",
|
|
33637
|
+
permissions: ["*"],
|
|
33638
|
+
status: "active",
|
|
33639
|
+
default: true
|
|
33640
|
+
},
|
|
33641
|
+
session
|
|
33642
|
+
);
|
|
33643
|
+
await session.commitTransaction();
|
|
33644
|
+
return "Division and admin role created successfully.";
|
|
33645
|
+
} catch (error) {
|
|
33646
|
+
session.abortTransaction();
|
|
33647
|
+
throw error;
|
|
33648
|
+
} finally {
|
|
33649
|
+
session.endSession();
|
|
33650
|
+
}
|
|
33651
|
+
}
|
|
33652
|
+
async function updateById(id, value) {
|
|
33653
|
+
const session = import_nodejs_utils20.useAtlas.getClient()?.startSession();
|
|
33654
|
+
if (!session) {
|
|
33655
|
+
throw new Error("Unable to start session for division service.");
|
|
33656
|
+
}
|
|
33657
|
+
try {
|
|
33658
|
+
session.startTransaction();
|
|
33659
|
+
const division = await _getById(id);
|
|
33660
|
+
await _updateById(id, value, session);
|
|
33661
|
+
if (division && division._id && division.name !== value.name) {
|
|
33662
|
+
await updateDivisionNameByDivision(division._id, value.name, session);
|
|
33663
|
+
}
|
|
33664
|
+
await session.commitTransaction();
|
|
33665
|
+
return "Division and admin role created successfully.";
|
|
33666
|
+
} catch (error) {
|
|
33667
|
+
session.abortTransaction();
|
|
33668
|
+
throw error;
|
|
33669
|
+
} finally {
|
|
33670
|
+
session.endSession();
|
|
33671
|
+
}
|
|
33672
|
+
}
|
|
33673
|
+
return {
|
|
33674
|
+
add,
|
|
33675
|
+
updateById
|
|
33676
|
+
};
|
|
33677
|
+
}
|
|
33678
|
+
|
|
33679
|
+
// src/resources/division/division.controller.ts
|
|
33680
|
+
var import_nodejs_utils21 = require("@eeplatform/nodejs-utils");
|
|
33681
|
+
var import_joi12 = __toESM(require("joi"));
|
|
33682
|
+
function useDivisionController() {
|
|
33683
|
+
const { add: _add, updateById: _updateById } = useDivisionService();
|
|
33684
|
+
const {
|
|
33685
|
+
getAll: _getAll,
|
|
33686
|
+
getById: _getById,
|
|
33687
|
+
getByName: _getByName,
|
|
33688
|
+
updateFieldById: _updateFieldById,
|
|
33689
|
+
deleteById: _deleteById
|
|
33690
|
+
} = useDivisionRepo();
|
|
33691
|
+
async function add(req, res, next) {
|
|
33692
|
+
const value = req.body;
|
|
33693
|
+
const { error } = schemaDivision.validate(value);
|
|
33694
|
+
if (error) {
|
|
33695
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
33696
|
+
return;
|
|
33697
|
+
}
|
|
33698
|
+
try {
|
|
33699
|
+
const data = await _add(value);
|
|
33700
|
+
res.json({
|
|
33701
|
+
message: "Successfully created division.",
|
|
33702
|
+
data
|
|
33703
|
+
});
|
|
33704
|
+
return;
|
|
33705
|
+
} catch (error2) {
|
|
33706
|
+
next(error2);
|
|
33707
|
+
}
|
|
33708
|
+
}
|
|
33709
|
+
async function getAll(req, res, next) {
|
|
33710
|
+
const query = req.query;
|
|
33711
|
+
const validation = import_joi12.default.object({
|
|
33712
|
+
page: import_joi12.default.number().min(1).optional().allow("", null),
|
|
33713
|
+
limit: import_joi12.default.number().min(1).optional().allow("", null),
|
|
33714
|
+
search: import_joi12.default.string().optional().allow("", null),
|
|
33715
|
+
status: import_joi12.default.string().optional().allow("", null),
|
|
33716
|
+
region: import_joi12.default.string().hex().optional().allow("", null)
|
|
33717
|
+
});
|
|
33718
|
+
const { error } = validation.validate(query);
|
|
33719
|
+
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
33720
|
+
const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
|
|
33721
|
+
const search = req.query.search ?? "";
|
|
33722
|
+
const status = req.query.status ?? "active";
|
|
33723
|
+
const region = req.query.region ?? "";
|
|
33724
|
+
const isPageNumber = isFinite(page);
|
|
33725
|
+
if (!isPageNumber) {
|
|
33726
|
+
next(new import_nodejs_utils21.BadRequestError("Invalid page number."));
|
|
33727
|
+
return;
|
|
33728
|
+
}
|
|
33729
|
+
const isLimitNumber = isFinite(limit);
|
|
33730
|
+
if (!isLimitNumber) {
|
|
33731
|
+
next(new import_nodejs_utils21.BadRequestError("Invalid limit number."));
|
|
33732
|
+
return;
|
|
33733
|
+
}
|
|
33734
|
+
if (error) {
|
|
33735
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
33736
|
+
return;
|
|
33737
|
+
}
|
|
33738
|
+
try {
|
|
33739
|
+
const data = await _getAll({ page, limit, search, status, region });
|
|
33740
|
+
res.json(data);
|
|
33741
|
+
return;
|
|
33742
|
+
} catch (error2) {
|
|
33743
|
+
next(error2);
|
|
33744
|
+
}
|
|
33745
|
+
}
|
|
33746
|
+
async function getById(req, res, next) {
|
|
33747
|
+
const id = req.params.id;
|
|
33748
|
+
const validation = import_joi12.default.object({
|
|
33749
|
+
id: import_joi12.default.string().hex().required()
|
|
33750
|
+
});
|
|
33751
|
+
const { error } = validation.validate({ id });
|
|
33752
|
+
if (error) {
|
|
33753
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
33754
|
+
return;
|
|
33755
|
+
}
|
|
33756
|
+
try {
|
|
33757
|
+
const data = await _getById(id);
|
|
33758
|
+
res.json({
|
|
33759
|
+
message: "Successfully retrieved division.",
|
|
33760
|
+
data
|
|
33761
|
+
});
|
|
33762
|
+
return;
|
|
33763
|
+
} catch (error2) {
|
|
33764
|
+
next(error2);
|
|
33765
|
+
}
|
|
33766
|
+
}
|
|
33767
|
+
async function getByName(req, res, next) {
|
|
33768
|
+
const name = req.params.name;
|
|
33769
|
+
const validation = import_joi12.default.object({
|
|
33770
|
+
name: import_joi12.default.string().required()
|
|
33771
|
+
});
|
|
33772
|
+
const { error } = validation.validate({ name });
|
|
33773
|
+
if (error) {
|
|
33774
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
33775
|
+
return;
|
|
33776
|
+
}
|
|
33777
|
+
try {
|
|
33778
|
+
const data = await _getByName(name);
|
|
33779
|
+
res.json({
|
|
33780
|
+
message: "Successfully retrieved division.",
|
|
33781
|
+
data
|
|
33782
|
+
});
|
|
33783
|
+
return;
|
|
33784
|
+
} catch (error2) {
|
|
33785
|
+
next(error2);
|
|
33786
|
+
}
|
|
33787
|
+
}
|
|
33788
|
+
async function updateField(req, res, next) {
|
|
33789
|
+
const _id = req.params.id;
|
|
33790
|
+
const { field, value } = req.body;
|
|
33791
|
+
const validation = import_joi12.default.object({
|
|
33792
|
+
_id: import_joi12.default.string().hex().required(),
|
|
33793
|
+
field: import_joi12.default.string().valid("name", "director", "directorName").required(),
|
|
33794
|
+
value: import_joi12.default.string().required()
|
|
33795
|
+
});
|
|
33796
|
+
const { error } = validation.validate({ _id, field, value });
|
|
33797
|
+
if (error) {
|
|
33798
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
33799
|
+
return;
|
|
33800
|
+
}
|
|
33801
|
+
try {
|
|
33802
|
+
const message = await _updateFieldById({ _id, field, value });
|
|
33803
|
+
res.json({ message });
|
|
33804
|
+
return;
|
|
33805
|
+
} catch (error2) {
|
|
33806
|
+
next(error2);
|
|
33807
|
+
}
|
|
33808
|
+
}
|
|
33809
|
+
async function updateById(req, res, next) {
|
|
33810
|
+
const _id = req.params.id;
|
|
33811
|
+
const payload = req.body;
|
|
33812
|
+
const { error } = schemaDivisionUpdate.validate({ _id, ...payload });
|
|
33813
|
+
if (error) {
|
|
33814
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
33815
|
+
return;
|
|
33816
|
+
}
|
|
33817
|
+
try {
|
|
33818
|
+
const message = await _updateById(_id, payload);
|
|
33819
|
+
res.json({ message });
|
|
33820
|
+
return;
|
|
33821
|
+
} catch (error2) {
|
|
33822
|
+
next(error2);
|
|
33823
|
+
}
|
|
33824
|
+
}
|
|
33825
|
+
async function deleteById(req, res, next) {
|
|
33826
|
+
const _id = req.params.id;
|
|
33827
|
+
const validation = import_joi12.default.object({
|
|
33828
|
+
_id: import_joi12.default.string().hex().required()
|
|
33829
|
+
});
|
|
33830
|
+
const { error } = validation.validate({ _id });
|
|
33831
|
+
if (error) {
|
|
33832
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
33833
|
+
return;
|
|
33834
|
+
}
|
|
33835
|
+
try {
|
|
33836
|
+
const message = await _deleteById(_id);
|
|
33837
|
+
res.json({ message });
|
|
33838
|
+
return;
|
|
33839
|
+
} catch (error2) {
|
|
33840
|
+
next(error2);
|
|
33841
|
+
}
|
|
33842
|
+
}
|
|
33843
|
+
return {
|
|
33844
|
+
add,
|
|
33845
|
+
getAll,
|
|
33846
|
+
getById,
|
|
33847
|
+
getByName,
|
|
33848
|
+
updateField,
|
|
33849
|
+
updateById,
|
|
33850
|
+
deleteById
|
|
33851
|
+
};
|
|
33852
|
+
}
|
|
33853
|
+
|
|
33788
33854
|
// src/resources/asset/asset.model.ts
|
|
33789
33855
|
var import_nodejs_utils22 = require("@eeplatform/nodejs-utils");
|
|
33790
33856
|
var import_joi13 = __toESM(require("joi"));
|