diff --git a/demo/collections/LocalOperations.js b/demo/collections/LocalOperations.js index eaebc97851..7db1a52e92 100644 --- a/demo/collections/LocalOperations.js +++ b/demo/collections/LocalOperations.js @@ -12,7 +12,12 @@ const LocalOperations = { collection: 'localized-posts', }); + const blocksGlobal = await req.payload.findGlobal({ + global: 'blocks-global', + }); + formattedData.localizedPosts = localizedPosts; + formattedData.blocksGlobal = blocksGlobal; return formattedData; }, diff --git a/src/globals/operations/local/findOne.js b/src/globals/operations/local/findOne.js new file mode 100644 index 0000000000..c437752ae8 --- /dev/null +++ b/src/globals/operations/local/findOne.js @@ -0,0 +1,25 @@ +async function findOne(options) { + const { + global: globalSlug, + depth, + locale, + fallbackLocale, + } = options; + + const globalConfig = this.globals.config.find((config) => config.slug === globalSlug); + + return this.operations.globals.findOne({ + slug: globalSlug, + depth, + globalConfig, + overrideAccess: true, + req: { + payloadAPI: 'local', + locale, + fallbackLocale, + payload: this, + }, + }); +} + +module.exports = findOne; diff --git a/src/globals/operations/local/index.js b/src/globals/operations/local/index.js new file mode 100644 index 0000000000..511bbcb223 --- /dev/null +++ b/src/globals/operations/local/index.js @@ -0,0 +1,7 @@ +const findOne = require('./findOne'); +const update = require('./update'); + +module.exports = { + findOne, + update, +}; diff --git a/src/globals/operations/local/update.js b/src/globals/operations/local/update.js new file mode 100644 index 0000000000..a287eef9d7 --- /dev/null +++ b/src/globals/operations/local/update.js @@ -0,0 +1,27 @@ +async function update(options) { + const { + global: globalSlug, + depth, + locale, + fallbackLocale, + data, + } = options; + + const globalConfig = this.globals.config.find((config) => config.slug === globalSlug); + + return this.operations.globals.update({ + slug: globalSlug, + data, + depth, + globalConfig, + overrideAccess: true, + req: { + payloadAPI: 'local', + locale, + fallbackLocale, + payload: this, + }, + }); +} + +module.exports = update; diff --git a/src/index.js b/src/index.js index 191e52473d..e0b7a8e8fb 100644 --- a/src/index.js +++ b/src/index.js @@ -24,6 +24,7 @@ const errorHandler = require('./express/middleware/errorHandler'); const performFieldOperations = require('./fields/performFieldOperations'); const localOperations = require('./collections/operations/local'); +const localGlobalOperations = require('./globals/operations/local'); class Payload { init(options) { @@ -95,6 +96,8 @@ class Payload { this.create = this.create.bind(this); this.find = this.find.bind(this); + this.findGlobal = this.findGlobal.bind(this); + this.updateGlobal = this.updateGlobal.bind(this); this.findByID = this.findByID.bind(this); this.update = this.update.bind(this); this.login = this.login.bind(this); @@ -127,6 +130,18 @@ class Payload { return find(options); } + async findGlobal(options) { + let { findOne } = localGlobalOperations; + findOne = findOne.bind(this); + return findOne(options); + } + + async updateGlobal(options) { + let { update } = localGlobalOperations; + update = update.bind(this); + return update(options); + } + async findByID(options) { let { findByID } = localOperations; findByID = findByID.bind(this);