fix: standardize error messages in order and slot lifecycles for better clarity

This commit is contained in:
vchikalkin 2025-07-18 16:44:04 +03:00
parent ec06282d56
commit c22e179b73
2 changed files with 8 additions and 4 deletions

View File

@ -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;

View File

@ -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;