Migrate code and remove auto generation of controller and services in memory

This commit is contained in:
Alexandre Bodin 2021-11-18 21:26:26 +01:00
parent d709898a82
commit 7697bb16c3
36 changed files with 150 additions and 489 deletions

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::category.category');

View File

@ -1,46 +1,5 @@
'use strict';
module.exports = {
routes: [
{
method: 'GET',
path: '/categories',
handler: 'category.find',
config: {
policies: [],
},
},
{
method: 'GET',
path: '/categories/:id',
handler: 'category.findOne',
config: {
policies: [],
},
},
{
method: 'POST',
path: '/categories',
handler: 'category.create',
config: {
policies: [],
},
},
{
method: 'PUT',
path: '/categories/:id',
handler: 'category.update',
config: {
policies: [],
},
},
{
method: 'DELETE',
path: '/categories/:id',
handler: 'category.delete',
config: {
policies: [],
},
},
],
};
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::category.category');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::category.category');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::country.country');

View File

@ -1,46 +1,5 @@
'use strict';
module.exports = {
routes: [
{
method: 'GET',
path: '/countries',
handler: 'country.find',
config: {
policies: [],
},
},
{
method: 'GET',
path: '/countries/:id',
handler: 'country.findOne',
config: {
policies: [],
},
},
{
method: 'POST',
path: '/countries',
handler: 'country.create',
config: {
policies: [],
},
},
{
method: 'PUT',
path: '/countries/:id',
handler: 'country.update',
config: {
policies: [],
},
},
{
method: 'DELETE',
path: '/countries/:id',
handler: 'country.delete',
config: {
policies: [],
},
},
],
};
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::country.country');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::country.country');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::homepage.homepage');

View File

@ -1,30 +1,5 @@
'use strict';
module.exports = {
routes: [
{
method: 'GET',
path: '/homepage',
handler: 'homepage.find',
config: {
policies: [],
},
},
{
method: 'PUT',
path: '/homepage',
handler: 'homepage.update',
config: {
policies: [],
},
},
{
method: 'DELETE',
path: '/homepage',
handler: 'homepage.delete',
config: {
policies: [],
},
},
],
};
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::homepage.homepage');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::homepage.homepage');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::kitchensink.kitchensink');

View File

@ -1,46 +1,5 @@
'use strict';
module.exports = {
routes: [
{
method: 'GET',
path: '/kitchensinks',
handler: 'kitchensink.find',
config: {
policies: [],
},
},
{
method: 'GET',
path: '/kitchensinks/:id',
handler: 'kitchensink.findOne',
config: {
policies: [],
},
},
{
method: 'POST',
path: '/kitchensinks',
handler: 'kitchensink.create',
config: {
policies: [],
},
},
{
method: 'PUT',
path: '/kitchensinks/:id',
handler: 'kitchensink.update',
config: {
policies: [],
},
},
{
method: 'DELETE',
path: '/kitchensinks/:id',
handler: 'kitchensink.delete',
config: {
policies: [],
},
},
],
};
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::kitchensink.kitchensink');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::kitchensink.kitchensink');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::like.like');

View File

@ -1,46 +1,5 @@
'use strict';
module.exports = {
routes: [
{
method: 'GET',
path: '/likes',
handler: 'like.find',
config: {
policies: [],
},
},
{
method: 'GET',
path: '/likes/:id',
handler: 'like.findOne',
config: {
policies: [],
},
},
{
method: 'POST',
path: '/likes',
handler: 'like.create',
config: {
policies: [],
},
},
{
method: 'PUT',
path: '/likes/:id',
handler: 'like.update',
config: {
policies: [],
},
},
{
method: 'DELETE',
path: '/likes/:id',
handler: 'like.delete',
config: {
policies: [],
},
},
],
};
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::like.like');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::like.like');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::menu.menu');

View File

@ -1,46 +1,5 @@
'use strict';
module.exports = {
routes: [
{
method: 'GET',
path: '/menus',
handler: 'menu.find',
config: {
policies: [],
},
},
{
method: 'GET',
path: '/menus/:id',
handler: 'menu.findOne',
config: {
policies: [],
},
},
{
method: 'POST',
path: '/menus',
handler: 'menu.create',
config: {
policies: [],
},
},
{
method: 'PUT',
path: '/menus/:id',
handler: 'menu.update',
config: {
policies: [],
},
},
{
method: 'DELETE',
path: '/menus/:id',
handler: 'menu.delete',
config: {
policies: [],
},
},
],
};
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::menu.menu');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::menu.menu');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::menusection.menusection');

View File

@ -1,46 +1,5 @@
'use strict';
module.exports = {
routes: [
{
method: 'GET',
path: '/menusections',
handler: 'menusection.find',
config: {
policies: [],
},
},
{
method: 'GET',
path: '/menusections/:id',
handler: 'menusection.findOne',
config: {
policies: [],
},
},
{
method: 'POST',
path: '/menusections',
handler: 'menusection.create',
config: {
policies: [],
},
},
{
method: 'PUT',
path: '/menusections/:id',
handler: 'menusection.update',
config: {
policies: [],
},
},
{
method: 'DELETE',
path: '/menusections/:id',
handler: 'menusection.delete',
config: {
policies: [],
},
},
],
};
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::menusection.menusection');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::menusection.menusection');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::restaurant.restaurant');

View File

@ -1,47 +1,5 @@
'use strict';
module.exports = {
prefix: '/restaurants',
routes: [
{
method: 'GET',
path: '/',
handler: 'restaurant.find',
config: {
policies: [],
},
},
{
method: 'GET',
path: '/:id',
handler: 'restaurant.findOne',
config: {
policies: [],
},
},
{
method: 'POST',
path: '/',
handler: 'restaurant.create',
config: {
policies: [],
},
},
{
method: 'PUT',
path: '/:id',
handler: 'restaurant.update',
config: {
policies: [],
},
},
{
method: 'DELETE',
path: '/:id',
handler: 'restaurant.delete',
config: {
policies: [],
},
},
],
};
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::restaurant.restaurant');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::restaurant.restaurant');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::review.review');

View File

@ -1,46 +1,5 @@
'use strict';
module.exports = {
routes: [
{
method: 'GET',
path: '/reviews',
handler: 'review.find',
config: {
policies: [],
},
},
{
method: 'GET',
path: '/reviews/:id',
handler: 'review.findOne',
config: {
policies: [],
},
},
{
method: 'POST',
path: '/reviews',
handler: 'review.create',
config: {
policies: [],
},
},
{
method: 'PUT',
path: '/reviews/:id',
handler: 'review.update',
config: {
policies: [],
},
},
{
method: 'DELETE',
path: '/reviews/:id',
handler: 'review.delete',
config: {
policies: [],
},
},
],
};
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::review.review');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::review.review');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::tag.tag');

View File

@ -1,46 +1,5 @@
'use strict';
module.exports = {
routes: [
{
method: 'GET',
path: '/tags',
handler: 'tag.find',
config: {
policies: [],
},
},
{
method: 'GET',
path: '/tags/:id',
handler: 'tag.findOne',
config: {
policies: [],
},
},
{
method: 'POST',
path: '/tags',
handler: 'tag.create',
config: {
policies: [],
},
},
{
method: 'PUT',
path: '/tags/:id',
handler: 'tag.update',
config: {
policies: [],
},
},
{
method: 'DELETE',
path: '/tags/:id',
handler: 'tag.delete',
config: {
policies: [],
},
},
],
};
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::tag.tag');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::tag.tag');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::temp.temp');

View File

@ -1,44 +1,5 @@
module.exports = {
routes: [
{
method: 'GET',
path: '/temps',
handler: 'temp.find',
config: {
policies: [],
},
},
{
method: 'GET',
path: '/temps/:id',
handler: 'temp.findOne',
config: {
policies: [],
},
},
{
method: 'POST',
path: '/temps',
handler: 'temp.create',
config: {
policies: [],
},
},
{
method: 'PUT',
path: '/temps/:id',
handler: 'temp.update',
config: {
policies: [],
},
},
{
method: 'DELETE',
path: '/temps/:id',
handler: 'temp.delete',
config: {
policies: [],
},
},
],
};
'use strict';
const { createCoreRouter } = require('@strapi/strapi').factories;
module.exports = createCoreRouter('api::temp.temp');

View File

@ -0,0 +1,5 @@
'use strict';
const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::temp.temp');

View File

@ -1,8 +1,6 @@
'use strict';
const { has } = require('lodash/fp');
const { createService } = require('../../core-api/service');
const { createController } = require('../../core-api/controller');
const apisRegistry = strapi => {
const apis = {};
@ -21,22 +19,6 @@ const apisRegistry = strapi => {
const api = strapi.container.get('modules').add(`api::${apiName}`, apiConfig);
for (const ctName in api.contentTypes || {}) {
const contentType = api.contentTypes[ctName];
const uid = `api::${apiName}.${ctName}`;
if (!has(contentType.modelName, api.services)) {
const service = createService({ contentType });
strapi.container.get('services').set(uid, service);
}
if (!has(contentType.modelName, api.controllers)) {
const controller = createController({ contentType });
strapi.container.get('controllers').set(uid, controller);
}
}
apis[apiName] = api;
return apis[apiName];

View File

@ -1,5 +1,7 @@
import { Service } from './core-api/service';
import { Controller } from './core-api/controller';
import { Middleware } from './middlewares';
import { Policy } from './core/registries/policies';
type ControllerConfig = Controller;
@ -7,8 +9,8 @@ type ServiceConfig = Service;
type HandlerConfig = {
auth: false | { scope: string[] };
policies: string[];
middlewares: string[];
policies: Array<string | Policy>;
middlewares: Array<string | Middleware>;
};
type SingleTypeRouterConfig = {

View File

@ -2,3 +2,4 @@ import { Strapi } from '../';
import { Middleware } from 'koa';
export type MiddlewareFactory = (config: any, ctx: { strapi: Strapi }) => Middleware | null;
export type Middleware = Middleware;