From b0aa644435d1af998db429290d858d4b9360c475 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Sun, 3 Aug 2025 13:56:43 +0300 Subject: [PATCH] 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. --- src/api/order/content-types/order/lifecycles.ts | 6 +++++- src/api/slot/content-types/slot/lifecycles.ts | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/api/order/content-types/order/lifecycles.ts b/src/api/order/content-types/order/lifecycles.ts index 8c7a42c..370062c 100644 --- a/src/api/order/content-types/order/lifecycles.ts +++ b/src/api/order/content-types/order/lifecycles.ts @@ -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); } diff --git a/src/api/slot/content-types/slot/lifecycles.ts b/src/api/slot/content-types/slot/lifecycles.ts index aae12dd..3a5c18a 100644 --- a/src/api/slot/content-types/slot/lifecycles.ts +++ b/src/api/slot/content-types/slot/lifecycles.ts @@ -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