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:
parent
50f23f67b3
commit
cfa5a02ca9
@ -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 },
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user