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:
parent
63a68c6089
commit
b0aa644435
@ -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);
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user