mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 14:44:31 +00:00
Use prototype chaining to allow super keyword
This commit is contained in:
parent
f4507e1cb0
commit
cd807f5f2d
@ -4,7 +4,7 @@ module.exports = createCoreController('api::address.address', ({ strapi }) => ({
|
||||
async find(ctx) {
|
||||
const { query } = ctx;
|
||||
|
||||
const { results, pagination } = await strapi.service(uid).find(query);
|
||||
const { results, pagination } = await strapi.service('api::address.address').find(query);
|
||||
const sanitizedResults = await this.sanitizeOutput(results, ctx);
|
||||
|
||||
return this.transformResponse(sanitizedResults, { pagination });
|
||||
@ -12,6 +12,6 @@ module.exports = createCoreController('api::address.address', ({ strapi }) => ({
|
||||
|
||||
async findOne(ctx) {
|
||||
// use the parent controller
|
||||
return Object.getPrototypeOf(this).findOne(ctx);
|
||||
return super.findOne(ctx);
|
||||
},
|
||||
}));
|
||||
|
||||
@ -3,10 +3,12 @@ const { createCoreService } = require('@strapi/strapi').factories;
|
||||
module.exports = createCoreService('api::address.address', {
|
||||
find() {
|
||||
return {
|
||||
results: [],
|
||||
pagination: {
|
||||
foo: 'bar',
|
||||
},
|
||||
results: [
|
||||
{
|
||||
id: 'fakeData',
|
||||
},
|
||||
],
|
||||
pagination: {},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
const createController = require('./core-api/controller');
|
||||
const { createService } = require('./core-api/service');
|
||||
|
||||
const createCoreController = (uid, cfg) => {
|
||||
const createCoreController = (uid, cfg = {}) => {
|
||||
return ({ strapi }) => {
|
||||
const deps = {
|
||||
service: strapi.service(uid),
|
||||
@ -14,17 +14,14 @@ const createCoreController = (uid, cfg) => {
|
||||
|
||||
let userCtrl = typeof cfg === 'function' ? cfg({ strapi }) : cfg;
|
||||
|
||||
// TODO: can only extend the defined action so we can add some without creating breaking
|
||||
for (const methodName of Object.keys(baseController)) {
|
||||
if (userCtrl[methodName] === undefined) {
|
||||
userCtrl[methodName] = baseController[methodName];
|
||||
}
|
||||
}
|
||||
|
||||
return Object.assign(
|
||||
Object.create(baseController),
|
||||
{
|
||||
get coreController() {
|
||||
return baseController;
|
||||
},
|
||||
},
|
||||
userCtrl
|
||||
);
|
||||
Object.setPrototypeOf(userCtrl, baseController);
|
||||
return userCtrl;
|
||||
};
|
||||
};
|
||||
|
||||
@ -36,9 +33,16 @@ const createCoreService = (uid, cfg) => {
|
||||
|
||||
const baseService = createService(deps);
|
||||
|
||||
let userCtrl = typeof cfg === 'function' ? cfg({ strapi }) : cfg;
|
||||
let userService = typeof cfg === 'function' ? cfg({ strapi }) : cfg;
|
||||
|
||||
return Object.assign(baseService, userCtrl);
|
||||
for (const methodName of Object.keys(baseService)) {
|
||||
if (userService[methodName] === undefined) {
|
||||
userService[methodName] = baseService[methodName];
|
||||
}
|
||||
}
|
||||
|
||||
Object.setPrototypeOf(userService, baseService);
|
||||
return userService;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ module.exports = (/* _, { strapi } */) => {
|
||||
|
||||
strapi.log.error(error);
|
||||
|
||||
const { status, body } = formatInternalError(error);
|
||||
const { status, body } = formatInternalError();
|
||||
ctx.status = status;
|
||||
ctx.body = body;
|
||||
}
|
||||
|
||||
@ -12,8 +12,6 @@ const defaults = {
|
||||
useDefaults: true,
|
||||
directives: {
|
||||
'connect-src': ["'self'", 'https:'],
|
||||
'img-src': ["'self'", 'data:', 'blob:'],
|
||||
'media-src': ["'self'", 'data:', 'blob:'],
|
||||
},
|
||||
},
|
||||
xssFilter: false,
|
||||
|
||||
@ -60,14 +60,9 @@ const formatHttpError = error => {
|
||||
};
|
||||
};
|
||||
|
||||
const formatInternalError = error => {
|
||||
const httpError = createError(error);
|
||||
|
||||
if (httpError.expose) {
|
||||
return formatHttpError(httpError);
|
||||
}
|
||||
|
||||
return formatHttpError(createError(httpError.status || 500));
|
||||
const formatInternalError = () => {
|
||||
const error = createError(500);
|
||||
return formatHttpError(error);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user