@kipicore/dbcore 1.1.273 → 1.1.274
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.
|
@@ -148,6 +148,7 @@ const examGroupModelSchema = new mongoose_1.Schema({
|
|
|
148
148
|
});
|
|
149
149
|
const createOrUpdateHook = async (examGroup) => {
|
|
150
150
|
try {
|
|
151
|
+
await validateStandardDateConflict(examGroup);
|
|
151
152
|
if (examGroup.instituteId) {
|
|
152
153
|
const institute = await instituteModel_1.default.findOne({
|
|
153
154
|
where: {
|
|
@@ -267,10 +268,22 @@ const createOrUpdateHook = async (examGroup) => {
|
|
|
267
268
|
throw err;
|
|
268
269
|
}
|
|
269
270
|
};
|
|
271
|
+
const validateStandardDateConflict = async (examGroup) => {
|
|
272
|
+
const conflict = await ExamGroupModel.findOne({
|
|
273
|
+
instituteId: examGroup.instituteId,
|
|
274
|
+
...(examGroup.id && { id: { $ne: examGroup.id } }),
|
|
275
|
+
standards: { $in: examGroup.standards },
|
|
276
|
+
startDate: { $lte: examGroup.endDate },
|
|
277
|
+
endDate: { $gte: examGroup.startDate },
|
|
278
|
+
}).lean();
|
|
279
|
+
if (conflict) {
|
|
280
|
+
throw new Error(`Another exam group "${conflict.title}" already exists for selected standard(s) in this date range`);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
270
283
|
examGroupModelSchema.pre('save', async function (next) {
|
|
271
|
-
const
|
|
284
|
+
const examGroup = this;
|
|
272
285
|
try {
|
|
273
|
-
await createOrUpdateHook(
|
|
286
|
+
await createOrUpdateHook(examGroup);
|
|
274
287
|
next();
|
|
275
288
|
}
|
|
276
289
|
catch (error) {
|
|
@@ -278,9 +291,9 @@ examGroupModelSchema.pre('save', async function (next) {
|
|
|
278
291
|
}
|
|
279
292
|
});
|
|
280
293
|
examGroupModelSchema.pre('updateMany', async function (next) {
|
|
281
|
-
const
|
|
294
|
+
const examGroup = this.getUpdate();
|
|
282
295
|
try {
|
|
283
|
-
await createOrUpdateHook(
|
|
296
|
+
await createOrUpdateHook(examGroup);
|
|
284
297
|
next();
|
|
285
298
|
}
|
|
286
299
|
catch (error) {
|
package/package.json
CHANGED