From f0e4a9903228ac9928b0244ab98b6d25ce50579a Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Fri, 18 Jul 2025 15:15:01 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20integrate=20dayjs=20for=20improved=20da?= =?UTF-8?q?tetime=20handling=20in=20order=20lifecycles=20=D0=9D=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D0=B7=D1=8F=20=D0=B7=D0=B0=D0=B2=D0=B5=D1=80=D1=88?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D1=8C=20?= =?UTF-8?q?=D0=B4=D0=BE=20=D0=B5=D1=91=20=D0=BD=D0=B0=D1=81=D1=82=D1=83?= =?UTF-8?q?=D0=BF=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + pnpm-lock.yaml | 52 +++++-------------- .../order/content-types/order/lifecycles.ts | 13 +++++ 3 files changed, 26 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index 7e80e8c..0c384c2 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@strapi/plugin-graphql": "^5.15.0", "@strapi/plugin-users-permissions": "5.15.0", "@strapi/strapi": "5.15.0", + "dayjs": "^1.11.13", "pg": "8.8.0", "react": "^18.0.0", "react-dom": "^18.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f4eeb2f..32829f1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ importers: '@strapi/strapi': specifier: 5.15.0 version: 5.15.0(@babel/runtime@7.26.0)(@codemirror/autocomplete@6.18.3(@codemirror/language@6.10.5)(@codemirror/state@6.4.1)(@codemirror/view@6.35.0)(@lezer/common@1.2.3))(@codemirror/language@6.10.5)(@codemirror/lint@6.8.4)(@codemirror/search@6.5.8)(@codemirror/state@6.4.1)(@codemirror/theme-one-dark@6.1.2)(@codemirror/view@6.35.0)(@swc/helpers@0.5.15)(@types/hoist-non-react-statics@3.3.5)(@types/node@20.17.9)(@types/react-dom@18.3.1)(@types/react@18.3.12)(codemirror@5.65.18)(esbuild@0.25.5)(koa@2.16.1)(pg@8.8.0)(react-dom@18.3.1(react@18.3.1))(react-router-dom@6.28.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react@18.3.1)(redux@4.2.1)(styled-components@6.1.13(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(terser@5.36.0)(type-fest@4.29.0) + dayjs: + specifier: ^1.11.13 + version: 1.11.13 pg: specifier: 8.8.0 version: 8.8.0 @@ -2808,6 +2811,9 @@ packages: resolution: {integrity: sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==} engines: {node: '>=0.11'} + dayjs@1.11.13: + resolution: {integrity: sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==} + debounce@1.2.1: resolution: {integrity: sha512-XRRe6Glud4rd/ZGQfiV1ruXSfbvfJedlV9Y6zOlP+2K04vBYiJEte6stfFkCP03aMnY5tsipamumUjL14fofug==} @@ -7789,7 +7795,7 @@ snapshots: '@strapi/design-system': 2.0.0-rc.24(@babel/runtime@7.26.0)(@codemirror/autocomplete@6.18.3(@codemirror/language@6.10.5)(@codemirror/state@6.4.1)(@codemirror/view@6.35.0)(@lezer/common@1.2.3))(@codemirror/language@6.10.5)(@codemirror/lint@6.8.4)(@codemirror/search@6.5.8)(@codemirror/state@6.4.1)(@codemirror/theme-one-dark@6.1.2)(@codemirror/view@6.35.0)(@strapi/icons@2.0.0-rc.24(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(styled-components@6.1.13(react-dom@18.3.1(react@18.3.1))(react@18.3.1)))(@types/react-dom@18.3.1)(@types/react@18.3.12)(codemirror@5.65.18)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(styled-components@6.1.13(react-dom@18.3.1(react@18.3.1))(react@18.3.1)) '@strapi/icons': 2.0.0-rc.24(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(styled-components@6.1.13(react-dom@18.3.1(react@18.3.1))(react@18.3.1)) '@strapi/permissions': 5.15.0 - '@strapi/types': 5.15.0(@types/node@20.17.9)(pg@8.8.0)(typescript@5.4.4) + '@strapi/types': 5.15.0(@types/node@20.17.9)(pg@8.8.0)(typescript@5.7.2) '@strapi/typescript-utils': 5.15.0 '@strapi/utils': 5.15.0 '@testing-library/dom': 10.1.0 @@ -7982,7 +7988,7 @@ snapshots: '@strapi/database': 5.15.0(@types/node@20.17.9)(pg@8.8.0) '@strapi/design-system': 2.0.0-rc.24(@babel/runtime@7.26.0)(@codemirror/autocomplete@6.18.3(@codemirror/language@6.10.5)(@codemirror/state@6.4.1)(@codemirror/view@6.35.0)(@lezer/common@1.2.3))(@codemirror/language@6.10.5)(@codemirror/lint@6.8.4)(@codemirror/search@6.5.8)(@codemirror/state@6.4.1)(@codemirror/theme-one-dark@6.1.2)(@codemirror/view@6.35.0)(@strapi/icons@2.0.0-rc.24(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(styled-components@6.1.13(react-dom@18.3.1(react@18.3.1))(react@18.3.1)))(@types/react-dom@18.3.1)(@types/react@18.3.12)(codemirror@5.65.18)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(styled-components@6.1.13(react-dom@18.3.1(react@18.3.1))(react@18.3.1)) '@strapi/icons': 2.0.0-rc.24(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(styled-components@6.1.13(react-dom@18.3.1(react@18.3.1))(react@18.3.1)) - '@strapi/types': 5.15.0(@types/node@20.17.9)(pg@8.8.0)(typescript@5.4.4) + '@strapi/types': 5.15.0(@types/node@20.17.9)(pg@8.8.0)(typescript@5.7.2) '@strapi/utils': 5.15.0 date-fns: 2.30.0 date-fns-tz: 2.0.1(date-fns@2.30.0) @@ -8075,7 +8081,7 @@ snapshots: '@strapi/generators': 5.15.0 '@strapi/logger': 5.15.0 '@strapi/permissions': 5.15.0 - '@strapi/types': 5.15.0(@types/node@20.17.9)(pg@8.8.0)(typescript@5.4.4) + '@strapi/types': 5.15.0(@types/node@20.17.9)(pg@8.8.0)(typescript@5.7.2) '@strapi/typescript-utils': 5.15.0 '@strapi/utils': 5.15.0 bcryptjs: 2.4.3 @@ -8525,7 +8531,7 @@ snapshots: '@strapi/logger': 5.15.0 '@strapi/permissions': 5.15.0 '@strapi/review-workflows': 5.15.0(2imnoqd43gbalynv3yjuponlpy) - '@strapi/types': 5.15.0(@types/node@20.17.9)(pg@8.8.0)(typescript@5.4.4) + '@strapi/types': 5.15.0(@types/node@20.17.9)(pg@8.8.0)(typescript@5.7.2) '@strapi/typescript-utils': 5.15.0 '@strapi/upload': 5.15.0(6nrgkysfwt52tfycqocmy4s2kq) '@strapi/utils': 5.15.0 @@ -8627,34 +8633,6 @@ snapshots: - webpack-dev-server - webpack-plugin-serve - '@strapi/types@5.15.0(@types/node@20.17.9)(pg@8.8.0)(typescript@5.4.4)': - dependencies: - '@casl/ability': 6.5.0 - '@koa/cors': 5.0.0 - '@koa/router': 12.0.2 - '@strapi/database': 5.15.0(@types/node@20.17.9)(pg@8.8.0) - '@strapi/logger': 5.15.0 - '@strapi/permissions': 5.15.0 - '@strapi/utils': 5.15.0 - commander: 8.3.0 - koa: 2.16.1 - koa-body: 6.0.1 - node-schedule: 2.1.1 - typedoc: 0.25.10(typescript@5.4.4) - typedoc-github-wiki-theme: 1.1.0(typedoc-plugin-markdown@3.17.1(typedoc@0.25.10(typescript@5.7.2)))(typedoc@0.25.10(typescript@5.7.2)) - typedoc-plugin-markdown: 3.17.1(typedoc@0.25.10(typescript@5.7.2)) - transitivePeerDependencies: - - '@types/node' - - better-sqlite3 - - mysql - - mysql2 - - pg - - pg-native - - sqlite3 - - supports-color - - tedious - - typescript - '@strapi/types@5.15.0(@types/node@20.17.9)(pg@8.8.0)(typescript@5.7.2)': dependencies: '@casl/ability': 6.5.0 @@ -9908,6 +9886,8 @@ snapshots: dependencies: '@babel/runtime': 7.26.0 + dayjs@1.11.13: {} + debounce@1.2.1: {} debug@2.6.9: @@ -13142,14 +13122,6 @@ snapshots: handlebars: 4.7.8 typedoc: 0.25.10(typescript@5.7.2) - typedoc@0.25.10(typescript@5.4.4): - dependencies: - lunr: 2.3.9 - marked: 4.3.0 - minimatch: 9.0.5 - shiki: 0.14.7 - typescript: 5.4.4 - typedoc@0.25.10(typescript@5.7.2): dependencies: lunr: 2.3.9 diff --git a/src/api/order/content-types/order/lifecycles.ts b/src/api/order/content-types/order/lifecycles.ts index 3a8a23d..7541e00 100644 --- a/src/api/order/content-types/order/lifecycles.ts +++ b/src/api/order/content-types/order/lifecycles.ts @@ -12,6 +12,12 @@ const ERR_MISSING_CLIENT = 'Не указан клиент'; const ERR_MISSING_SLOT = 'Не указан слот'; const ERR_MISSING_SERVICE = 'Не указан сервис'; +const dayjs = require('dayjs'); +const utc = require('dayjs/plugin/utc'); +const timezone = require('dayjs/plugin/timezone'); +dayjs.extend(utc); +dayjs.extend(timezone); + export default { async beforeCreate(event) { const { data } = event.params; @@ -148,6 +154,13 @@ export default { data.order_number = lastOrderNumber + 1; } + const now = dayjs().tz('Europe/Moscow'); + const orderStart = dayjs(existingOrder.datetime_start).tz('Europe/Moscow'); + + if (state === 'completed' && now.isBefore(orderStart)) { + throw new Error('Нельзя завершить запись до её наступления'); + } + return; }