fix: enhance datetime validation in order and slot lifecycles to ensure accurate comparisons
This commit is contained in:
parent
f0e4a99032
commit
ec06282d56
@ -15,8 +15,11 @@ const ERR_MISSING_SERVICE = 'Не указан сервис';
|
||||
const dayjs = require('dayjs');
|
||||
const utc = require('dayjs/plugin/utc');
|
||||
const timezone = require('dayjs/plugin/timezone');
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
if (!dayjs.prototype.tz) {
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
}
|
||||
|
||||
export default {
|
||||
async beforeCreate(event) {
|
||||
@ -157,7 +160,7 @@ export default {
|
||||
const now = dayjs().tz('Europe/Moscow');
|
||||
const orderStart = dayjs(existingOrder.datetime_start).tz('Europe/Moscow');
|
||||
|
||||
if (state === 'completed' && now.isBefore(orderStart)) {
|
||||
if (state === 'completed' && now.isBefore(orderStart, 'minute')) {
|
||||
throw new Error('Нельзя завершить запись до её наступления');
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,12 @@
|
||||
import { extractId } from '../../../../utils';
|
||||
const dayjs = require('dayjs');
|
||||
const utc = require('dayjs/plugin/utc');
|
||||
const timezone = require('dayjs/plugin/timezone');
|
||||
|
||||
if (!dayjs.prototype.tz) {
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
}
|
||||
|
||||
const ERR_INVALID_TIME = 'Некорректное время';
|
||||
const ERR_OVERLAPPING_TIME = 'Время пересекается с другими слотами';
|
||||
@ -35,8 +43,12 @@ export default {
|
||||
}
|
||||
|
||||
// Проверка, что слот не создаётся в прошлом
|
||||
if (datetime_start && new Date(datetime_start) < new Date()) {
|
||||
throw new Error(ERR_PAST_SLOT);
|
||||
if (datetime_start) {
|
||||
const now = dayjs().tz('Europe/Moscow');
|
||||
const slotStart = dayjs(datetime_start).tz('Europe/Moscow');
|
||||
if (slotStart.isBefore(now, 'minute')) {
|
||||
throw new Error(ERR_PAST_SLOT);
|
||||
}
|
||||
}
|
||||
|
||||
// Проверка валидности времени
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user