From 0ecd9ff0cb3f9bb584141ada2d14e64da00ccb80 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 7 Feb 2022 16:11:19 -0500 Subject: [PATCH] chore: optimizes demo and version operations --- demo/globals/BlocksGlobal.ts | 8 +++++--- demo/globals/GlobalWithStrictAccess.ts | 6 ++++-- demo/globals/NavigationArray.ts | 6 ++++-- src/collections/operations/find.ts | 17 ----------------- src/collections/operations/findByID.ts | 17 ----------------- src/globals/operations/update.ts | 2 +- 6 files changed, 14 insertions(+), 42 deletions(-) diff --git a/demo/globals/BlocksGlobal.ts b/demo/globals/BlocksGlobal.ts index db5f849427..60a094fe82 100644 --- a/demo/globals/BlocksGlobal.ts +++ b/demo/globals/BlocksGlobal.ts @@ -3,10 +3,10 @@ import Quote from '../blocks/Quote'; import CallToAction from '../blocks/CallToAction'; import { GlobalConfig } from '../../src/globals/config/types'; -export default { +const BlocksGlobal: GlobalConfig = { slug: 'blocks-global', label: 'Blocks Global', - revisions: { + versions: { max: 20, }, access: { @@ -22,4 +22,6 @@ export default { localized: true, }, ], -} as GlobalConfig; +}; + +export default BlocksGlobal; diff --git a/demo/globals/GlobalWithStrictAccess.ts b/demo/globals/GlobalWithStrictAccess.ts index aacbab889d..786ed908ca 100644 --- a/demo/globals/GlobalWithStrictAccess.ts +++ b/demo/globals/GlobalWithStrictAccess.ts @@ -1,7 +1,7 @@ import { GlobalConfig } from '../../src/globals/config/types'; import checkRole from '../access/checkRole'; -export default { +const GlobalWithAccess: GlobalConfig = { slug: 'global-with-access', label: 'Global with Strict Access', access: { @@ -32,4 +32,6 @@ export default { required: true, }, ], -} as GlobalConfig; +}; + +export default GlobalWithAccess; diff --git a/demo/globals/NavigationArray.ts b/demo/globals/NavigationArray.ts index e9da709b88..115e83515e 100644 --- a/demo/globals/NavigationArray.ts +++ b/demo/globals/NavigationArray.ts @@ -1,7 +1,7 @@ import { GlobalConfig } from '../../src/globals/config/types'; import checkRole from '../access/checkRole'; -export default { +const NavigationArray: GlobalConfig = { slug: 'navigation-array', access: { update: ({ req: { user } }) => checkRole(['admin', 'user'], user), @@ -27,4 +27,6 @@ export default { }], }, ], -} as GlobalConfig; +}; + +export default NavigationArray; diff --git a/src/collections/operations/find.ts b/src/collections/operations/find.ts index 9a9fa1dd5f..90f9128355 100644 --- a/src/collections/operations/find.ts +++ b/src/collections/operations/find.ts @@ -97,23 +97,6 @@ async function find(incomingArgs: Arguments): Promis } } - if (collectionConfig.versions?.drafts && !draftsEnabled) { - queryToBuild.where.and.push({ - or: [ - { - _status: { - equals: 'published', - }, - }, - { - _status: { - exists: false, - }, - }, - ], - }); - } - const query = await Model.buildQuery(queryToBuild, locale); // ///////////////////////////////////// diff --git a/src/collections/operations/findByID.ts b/src/collections/operations/findByID.ts index c72c690b97..33e4060f69 100644 --- a/src/collections/operations/findByID.ts +++ b/src/collections/operations/findByID.ts @@ -81,23 +81,6 @@ async function findByID(this: Payload, incomingArgs: queryToBuild.where.and.push(accessResult); } - if (collectionConfig.versions?.drafts && !draftEnabled) { - queryToBuild.where.and.push({ - or: [ - { - _status: { - equals: 'published', - }, - }, - { - _status: { - exists: false, - }, - }, - ], - }); - } - const query = await Model.buildQuery(queryToBuild, locale); // ///////////////////////////////////// diff --git a/src/globals/operations/update.ts b/src/globals/operations/update.ts index 8cdfeb2772..442ce5bdc2 100644 --- a/src/globals/operations/update.ts +++ b/src/globals/operations/update.ts @@ -201,7 +201,7 @@ async function update(this: Payload, args): Promise< }); // ///////////////////////////////////// - // afterChange - Collection + // afterChange - Global // ///////////////////////////////////// await globalConfig.hooks.afterChange.reduce(async (priorHook, hook) => {