feat: add update check to order and slot lifecycles

- Implemented a check in both order and slot lifecycles to skip validation if the record is being updated, identified by the presence of the 'publishedAt' field. This change prevents unnecessary validation for existing records.
This commit is contained in:
vchikalkin 2025-08-03 13:56:43 +03:00
parent 63a68c6089
commit b0aa644435
2 changed files with 8 additions and 1 deletions

View File

@ -174,6 +174,10 @@ export default {
async beforeCreate(event) {
const { data } = event.params;
const { datetime_start, datetime_end, client, services } = data;
const isUpdate = !!data?.publishedAt;
if (isUpdate) return;
const clientId = extractId(client);
const slotId = extractId(data.slot);
@ -193,7 +197,7 @@ export default {
// Проверка, что заказ не создается на время в прошлом
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);
}

View File

@ -24,6 +24,9 @@ export default {
const { data } = event.params;
const { master, datetime_start, datetime_end } = data;
const isUpdate = !!data?.publishedAt;
if (isUpdate) return;
// Проверка, что мастер существует и активен
const masterId = extractId(master);
const masterEntity = await strapi.db