Merge pull request #382 from trouble/local-crud-globals
This commit is contained in:
25
src/globals/operations/local/findOne.js
Normal file
25
src/globals/operations/local/findOne.js
Normal 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;
|
||||
7
src/globals/operations/local/index.js
Normal file
7
src/globals/operations/local/index.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const findOne = require('./findOne');
|
||||
const update = require('./update');
|
||||
|
||||
module.exports = {
|
||||
findOne,
|
||||
update,
|
||||
};
|
||||
27
src/globals/operations/local/update.js
Normal file
27
src/globals/operations/local/update.js
Normal 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;
|
||||
15
src/index.js
15
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);
|
||||
|
||||
Reference in New Issue
Block a user