slot: disable beforeUpdate if no time_start & time_end
This commit is contained in:
parent
f434f0e208
commit
5e54c3f7e3
@ -38,39 +38,42 @@ export default {
|
||||
const { id: entityId } = where;
|
||||
const { time_start, time_end } = data;
|
||||
|
||||
if (!time_start || !time_end) {
|
||||
throw new Error(ERR_INVALID_TIME);
|
||||
}
|
||||
if (time_start && time_end) {
|
||||
if (!time_start || !time_end) {
|
||||
throw new Error(ERR_INVALID_TIME);
|
||||
}
|
||||
|
||||
if (timeToDate(time_start) >= timeToDate(time_end)) {
|
||||
throw new Error(ERR_INVALID_TIME);
|
||||
}
|
||||
if (timeToDate(time_start) >= timeToDate(time_end)) {
|
||||
throw new Error(ERR_INVALID_TIME);
|
||||
}
|
||||
|
||||
const existingEntity = await strapi.db.query('api::slot.slot').findOne({
|
||||
where: { id: entityId },
|
||||
select: ['date', 'documentId'],
|
||||
});
|
||||
|
||||
if (!existingEntity) {
|
||||
throw new Error('Запись не найдена');
|
||||
}
|
||||
|
||||
const { date, documentId } = existingEntity;
|
||||
|
||||
const overlappingEntities = await strapi.db
|
||||
.query('api::slot.slot')
|
||||
.findMany({
|
||||
where: {
|
||||
date,
|
||||
id: { $ne: entityId },
|
||||
documentId: { $ne: documentId },
|
||||
time_start: { $lt: time_end },
|
||||
time_end: { $gt: time_start },
|
||||
},
|
||||
const existingEntity = await strapi.db.query('api::slot.slot').findOne({
|
||||
where: { id: entityId },
|
||||
select: ['date', 'documentId'],
|
||||
});
|
||||
|
||||
if (overlappingEntities.length > 0) {
|
||||
throw new Error(ERR_OVERLAPPING_TIME);
|
||||
if (!existingEntity) {
|
||||
throw new Error('Запись не найдена');
|
||||
}
|
||||
|
||||
const { date, documentId } = existingEntity;
|
||||
|
||||
const overlappingEntities = await strapi.db
|
||||
.query('api::slot.slot')
|
||||
.findMany({
|
||||
where: {
|
||||
date,
|
||||
id: { $ne: entityId },
|
||||
documentId: { $ne: documentId },
|
||||
time_start: { $lt: time_end },
|
||||
time_end: { $gt: time_start },
|
||||
},
|
||||
});
|
||||
|
||||
if (overlappingEntities.length > 0) {
|
||||
throw new Error(ERR_OVERLAPPING_TIME);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user