diff --git a/src/api/order/content-types/order/lifecycles.ts b/src/api/order/content-types/order/lifecycles.ts index 4fb52a4..b571024 100644 --- a/src/api/order/content-types/order/lifecycles.ts +++ b/src/api/order/content-types/order/lifecycles.ts @@ -11,6 +11,9 @@ const ERR_INVALID_MASTER = 'Некорректный мастер'; const ERR_MISSING_CLIENT = 'Не указан клиент'; const ERR_MISSING_SLOT = 'Не указан слот'; const ERR_MISSING_SERVICE = 'Не указан сервис'; +const ERR_ORDER_OUT_OF_SLOT = 'Время заказа выходит за пределы слота'; +const ERR_EXISTING_ORDER_OR_SLOT_NOT_FOUND = 'Существующий заказ или слот не найден'; +const ERR_CANNOT_COMPLETE_BEFORE_START = 'Нельзя завершить запись до её наступления'; const dayjs = require('dayjs'); const utc = require('dayjs/plugin/utc'); @@ -53,7 +56,7 @@ export default { new Date(datetime_start) < new Date(slot.datetime_start) || new Date(datetime_end) > new Date(slot.datetime_end) ) { - throw new Error('Время заказа выходит за пределы слота'); + throw new Error(ERR_ORDER_OUT_OF_SLOT); } // 1. Слот не должен быть закрыт @@ -161,7 +164,7 @@ export default { const orderStart = dayjs(existingOrder.datetime_start).tz('Europe/Moscow'); if (state === 'completed' && now.isBefore(orderStart, 'minute')) { - throw new Error('Нельзя завершить запись до её наступления'); + throw new Error(ERR_CANNOT_COMPLETE_BEFORE_START); } return; @@ -183,7 +186,7 @@ export default { } if (!existingOrder || !existingOrder.slot) { - throw new Error('Существующий заказ или слот не найден'); + throw new Error(ERR_EXISTING_ORDER_OR_SLOT_NOT_FOUND); } const slotId = existingOrder.slot.documentId; diff --git a/src/api/slot/content-types/slot/lifecycles.ts b/src/api/slot/content-types/slot/lifecycles.ts index 1604b65..4d445cc 100644 --- a/src/api/slot/content-types/slot/lifecycles.ts +++ b/src/api/slot/content-types/slot/lifecycles.ts @@ -24,6 +24,7 @@ const ERR_INACTIVE_MASTER = 'Мастер не активен'; const ERR_INVALID_MASTER = 'Некорректный мастер'; const ERR_PAST_SLOT = 'Нельзя создать слот в прошлом'; const ERR_SLOT_HAS_ORDERS = 'Нельзя удалить слот с активными заказами'; +const ERR_RECORD_NOT_FOUND = 'Запись не найдена'; export default { async beforeCreate(event) { @@ -117,7 +118,7 @@ export default { } if (!existingEntity) { - throw new Error('Запись не найдена'); + throw new Error(ERR_RECORD_NOT_FOUND); } const { documentId } = existingEntity;