feat: add validation to prevent order creation in the past

- Introduced a new error message for attempts to create orders with a start time in the past.
- Implemented a check in the order lifecycle to validate that the order start time is not before the current time.
This commit is contained in:
vchikalkin 2025-08-02 11:19:21 +03:00
parent 50f23f67b3
commit cfa5a02ca9

View File

@ -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<State, string> = {
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 },