diff --git a/src/api/order/content-types/order/lifecycles.ts b/src/api/order/content-types/order/lifecycles.ts index 0b2c3e3..8c7a42c 100644 --- a/src/api/order/content-types/order/lifecycles.ts +++ b/src/api/order/content-types/order/lifecycles.ts @@ -17,6 +17,7 @@ const ERR_EXISTING_ORDER_OR_SLOT_NOT_FOUND = 'Существующий заказ или слот не найден'; const ERR_CANNOT_COMPLETE_BEFORE_START = 'Нельзя завершить запись до её наступления'; +const ERR_ORDER_IN_PAST = 'Нельзя создать запись на время в прошлом'; const STATE_MAP: Record = { approved: 'Подтверждено', @@ -189,6 +190,14 @@ export default { throw new Error(ERR_INVALID_TIME); } + // Проверка, что заказ не создается на время в прошлом + const now = dayjs().tz(DEFAULT_TZ); + const orderStart = dayjs(datetime_start).tz(DEFAULT_TZ); + + if (orderStart.isBefore(now, 'minute')) { + throw new Error(ERR_ORDER_IN_PAST); + } + // Получаем слот const slot = await strapi.db.query('api::slot.slot').findOne({ where: { id: slotId },