mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 10:55:37 +00:00
Init groupManager
This commit is contained in:
parent
5777d0de35
commit
e9d2c04824
@ -16,7 +16,6 @@ const relations = require('./relations');
|
||||
const buildQuery = require('./buildQuery');
|
||||
const mountModels = require('./mount-models');
|
||||
const getQueryParams = require('./get-query-params');
|
||||
const createDefaults = require('./create-defaults');
|
||||
|
||||
/**
|
||||
* Bookshelf hook
|
||||
|
||||
@ -55,6 +55,14 @@
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/groups/:uid",
|
||||
"handler": "Groups.getGroup",
|
||||
"config": {
|
||||
"policies": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -7,12 +7,36 @@
|
||||
module.exports = {
|
||||
/**
|
||||
* GET /groups handler
|
||||
* Returns a list of available groups
|
||||
*/
|
||||
async getGroups(ctx) {
|
||||
const data = await strapi
|
||||
.service('content-type-builder.groups')
|
||||
.listGroups();
|
||||
|
||||
const data = await strapi.groupManager.all();
|
||||
ctx.body = { data };
|
||||
},
|
||||
|
||||
/**
|
||||
* GET /groups/:uid
|
||||
* Returns a specific group
|
||||
* @param {*} ctx
|
||||
*/
|
||||
async getGroup(ctx) {
|
||||
const { uid } = ctx.params;
|
||||
|
||||
const group = await strapi.groupManager.get(uid);
|
||||
|
||||
if (!group) {
|
||||
ctx.status = 404;
|
||||
ctx.body = {
|
||||
error: 'group.notFound',
|
||||
};
|
||||
}
|
||||
|
||||
ctx.body = { data: group };
|
||||
},
|
||||
|
||||
async createGroup() {},
|
||||
|
||||
async updateGroup() {},
|
||||
|
||||
async deleteGroup() {},
|
||||
};
|
||||
|
||||
@ -1,16 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Returns the list of existing groups
|
||||
*/
|
||||
listGroups() {
|
||||
return Array.from(strapi.groupManager).map(([groupKey, schema]) => {
|
||||
return {
|
||||
id: groupKey,
|
||||
name: schema.name,
|
||||
schema: schema,
|
||||
};
|
||||
});
|
||||
},
|
||||
};
|
||||
module.exports = {};
|
||||
|
||||
@ -26,6 +26,7 @@ const initializeHooks = require('./hooks');
|
||||
const createStrapiFs = require('./core/fs');
|
||||
const getPrefixedDeps = require('./utils/get-prefixed-dependencies');
|
||||
const defaultQueries = require('./core-api/queries');
|
||||
const createGroupManager = require('./services/groups');
|
||||
|
||||
/**
|
||||
* Construct an Strapi instance.
|
||||
@ -101,6 +102,7 @@ class Strapi extends EventEmitter {
|
||||
installedHooks: getPrefixedDeps('strapi-hook', pkgJSON),
|
||||
};
|
||||
|
||||
this.groupManager;
|
||||
this.fs = createStrapiFs(this);
|
||||
this.requireProjectBootstrap();
|
||||
}
|
||||
@ -286,6 +288,10 @@ class Strapi extends EventEmitter {
|
||||
|
||||
await bootstrap(this);
|
||||
|
||||
this.groupManager = createGroupManager({
|
||||
groups,
|
||||
});
|
||||
|
||||
// Usage.
|
||||
await utils.usage(this.config);
|
||||
|
||||
|
||||
42
packages/strapi/lib/services/groups/index.js
Normal file
42
packages/strapi/lib/services/groups/index.js
Normal file
@ -0,0 +1,42 @@
|
||||
const initMap = groups => {
|
||||
const map = new Map();
|
||||
|
||||
Object.keys(groups).forEach(key => {
|
||||
const {
|
||||
connection,
|
||||
collectionName,
|
||||
description,
|
||||
attributes,
|
||||
} = strapi.groups[key];
|
||||
|
||||
map.set(key, {
|
||||
uid: key,
|
||||
name: key.toUpperCase(), // get the display name som
|
||||
schema: { connection, collectionName, description, attributes },
|
||||
});
|
||||
});
|
||||
|
||||
return map;
|
||||
};
|
||||
|
||||
const createGrougManager = ({ groups }) => {
|
||||
const groupMap = initMap(groups);
|
||||
|
||||
return {
|
||||
/**
|
||||
* Returns all the groups
|
||||
*/
|
||||
all() {
|
||||
return Array.from(groupMap.values());
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a group by UID
|
||||
*/
|
||||
get(uid) {
|
||||
return groupMap.get(uid);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = createGrougManager;
|
||||
@ -13,7 +13,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "^2.1.2",
|
||||
"boom": "^5.2.0",
|
||||
"boom": "^7.3.0",
|
||||
"chalk": "^2.4.1",
|
||||
"chokidar": "^2.1.2",
|
||||
"cross-spawn": "^6.0.5",
|
||||
|
||||
15
yarn.lock
15
yarn.lock
@ -3688,12 +3688,12 @@ boom@2.x.x:
|
||||
dependencies:
|
||||
hoek "2.x.x"
|
||||
|
||||
boom@^5.2.0:
|
||||
version "5.2.0"
|
||||
resolved "https://registry.yarnpkg.com/boom/-/boom-5.2.0.tgz#5dd9da6ee3a5f302077436290cb717d3f4a54e02"
|
||||
integrity sha512-Z5BTk6ZRe4tXXQlkqftmsAUANpXmuwlsF5Oov8ThoMbQRzdGTA1ngYRW160GexgOgjsFOKJz0LYhoNi+2AMBUw==
|
||||
boom@^7.3.0:
|
||||
version "7.3.0"
|
||||
resolved "https://registry.yarnpkg.com/boom/-/boom-7.3.0.tgz#733a6d956d33b0b1999da3fe6c12996950d017b9"
|
||||
integrity sha512-Swpoyi2t5+GhOEGw8rEsKvTxFLIDiiKoUc2gsoV6Lyr43LHBIzch3k2MvYUs8RTROrIkVJ3Al0TkaOGjnb+B6A==
|
||||
dependencies:
|
||||
hoek "4.x.x"
|
||||
hoek "6.x.x"
|
||||
|
||||
bootstrap@^4.0.0-alpha.6:
|
||||
version "4.3.1"
|
||||
@ -8272,11 +8272,6 @@ hoek@2.x.x:
|
||||
resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed"
|
||||
integrity sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0=
|
||||
|
||||
hoek@4.x.x:
|
||||
version "4.2.1"
|
||||
resolved "https://registry.yarnpkg.com/hoek/-/hoek-4.2.1.tgz#9634502aa12c445dd5a7c5734b572bb8738aacbb"
|
||||
integrity sha512-QLg82fGkfnJ/4iy1xZ81/9SIJiq1NGFUMGs6ParyjBZr6jW2Ufj/snDqTHixNlHdPNwN2RLVD0Pi3igeK9+JfA==
|
||||
|
||||
hoek@5.x.x:
|
||||
version "5.0.4"
|
||||
resolved "https://registry.yarnpkg.com/hoek/-/hoek-5.0.4.tgz#0f7fa270a1cafeb364a4b2ddfaa33f864e4157da"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user