feat: integrate dayjs for improved datetime handling in order lifecycles
Нельзя завершить запись до её наступления
This commit is contained in:
parent
d91cabaed0
commit
f0e4a99032
@ -15,6 +15,7 @@
|
|||||||
"@strapi/plugin-graphql": "^5.15.0",
|
"@strapi/plugin-graphql": "^5.15.0",
|
||||||
"@strapi/plugin-users-permissions": "5.15.0",
|
"@strapi/plugin-users-permissions": "5.15.0",
|
||||||
"@strapi/strapi": "5.15.0",
|
"@strapi/strapi": "5.15.0",
|
||||||
|
"dayjs": "^1.11.13",
|
||||||
"pg": "8.8.0",
|
"pg": "8.8.0",
|
||||||
"react": "^18.0.0",
|
"react": "^18.0.0",
|
||||||
"react-dom": "^18.0.0",
|
"react-dom": "^18.0.0",
|
||||||
|
|||||||
52
pnpm-lock.yaml
generated
52
pnpm-lock.yaml
generated
@ -20,6 +20,9 @@ importers:
|
|||||||
'@strapi/strapi':
|
'@strapi/strapi':
|
||||||
specifier: 5.15.0
|
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)
|
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:
|
pg:
|
||||||
specifier: 8.8.0
|
specifier: 8.8.0
|
||||||
version: 8.8.0
|
version: 8.8.0
|
||||||
@ -2808,6 +2811,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==}
|
resolution: {integrity: sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==}
|
||||||
engines: {node: '>=0.11'}
|
engines: {node: '>=0.11'}
|
||||||
|
|
||||||
|
dayjs@1.11.13:
|
||||||
|
resolution: {integrity: sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==}
|
||||||
|
|
||||||
debounce@1.2.1:
|
debounce@1.2.1:
|
||||||
resolution: {integrity: sha512-XRRe6Glud4rd/ZGQfiV1ruXSfbvfJedlV9Y6zOlP+2K04vBYiJEte6stfFkCP03aMnY5tsipamumUjL14fofug==}
|
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/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/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/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/typescript-utils': 5.15.0
|
||||||
'@strapi/utils': 5.15.0
|
'@strapi/utils': 5.15.0
|
||||||
'@testing-library/dom': 10.1.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/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/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/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
|
'@strapi/utils': 5.15.0
|
||||||
date-fns: 2.30.0
|
date-fns: 2.30.0
|
||||||
date-fns-tz: 2.0.1(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/generators': 5.15.0
|
||||||
'@strapi/logger': 5.15.0
|
'@strapi/logger': 5.15.0
|
||||||
'@strapi/permissions': 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/typescript-utils': 5.15.0
|
||||||
'@strapi/utils': 5.15.0
|
'@strapi/utils': 5.15.0
|
||||||
bcryptjs: 2.4.3
|
bcryptjs: 2.4.3
|
||||||
@ -8525,7 +8531,7 @@ snapshots:
|
|||||||
'@strapi/logger': 5.15.0
|
'@strapi/logger': 5.15.0
|
||||||
'@strapi/permissions': 5.15.0
|
'@strapi/permissions': 5.15.0
|
||||||
'@strapi/review-workflows': 5.15.0(2imnoqd43gbalynv3yjuponlpy)
|
'@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/typescript-utils': 5.15.0
|
||||||
'@strapi/upload': 5.15.0(6nrgkysfwt52tfycqocmy4s2kq)
|
'@strapi/upload': 5.15.0(6nrgkysfwt52tfycqocmy4s2kq)
|
||||||
'@strapi/utils': 5.15.0
|
'@strapi/utils': 5.15.0
|
||||||
@ -8627,34 +8633,6 @@ snapshots:
|
|||||||
- webpack-dev-server
|
- webpack-dev-server
|
||||||
- webpack-plugin-serve
|
- 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)':
|
'@strapi/types@5.15.0(@types/node@20.17.9)(pg@8.8.0)(typescript@5.7.2)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@casl/ability': 6.5.0
|
'@casl/ability': 6.5.0
|
||||||
@ -9908,6 +9886,8 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@babel/runtime': 7.26.0
|
'@babel/runtime': 7.26.0
|
||||||
|
|
||||||
|
dayjs@1.11.13: {}
|
||||||
|
|
||||||
debounce@1.2.1: {}
|
debounce@1.2.1: {}
|
||||||
|
|
||||||
debug@2.6.9:
|
debug@2.6.9:
|
||||||
@ -13142,14 +13122,6 @@ snapshots:
|
|||||||
handlebars: 4.7.8
|
handlebars: 4.7.8
|
||||||
typedoc: 0.25.10(typescript@5.7.2)
|
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):
|
typedoc@0.25.10(typescript@5.7.2):
|
||||||
dependencies:
|
dependencies:
|
||||||
lunr: 2.3.9
|
lunr: 2.3.9
|
||||||
|
|||||||
@ -12,6 +12,12 @@ const ERR_MISSING_CLIENT = 'Не указан клиент';
|
|||||||
const ERR_MISSING_SLOT = 'Не указан слот';
|
const ERR_MISSING_SLOT = 'Не указан слот';
|
||||||
const ERR_MISSING_SERVICE = 'Не указан сервис';
|
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 {
|
export default {
|
||||||
async beforeCreate(event) {
|
async beforeCreate(event) {
|
||||||
const { data } = event.params;
|
const { data } = event.params;
|
||||||
@ -148,6 +154,13 @@ export default {
|
|||||||
data.order_number = lastOrderNumber + 1;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user