Merge pull request #382 from trouble/local-crud-globals

This commit is contained in:
Elliot DeNolf
2020-09-14 17:03:21 -04:00
committed by GitHub
5 changed files with 79 additions and 0 deletions

View File

@@ -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;

View File

@@ -0,0 +1,7 @@
const findOne = require('./findOne');
const update = require('./update');
module.exports = {
findOne,
update,
};

View File

@@ -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;

View File

@@ -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);