mirror of
https://github.com/strapi/strapi.git
synced 2025-11-25 14:41:15 +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 buildQuery = require('./buildQuery');
|
||||||
const mountModels = require('./mount-models');
|
const mountModels = require('./mount-models');
|
||||||
const getQueryParams = require('./get-query-params');
|
const getQueryParams = require('./get-query-params');
|
||||||
const createDefaults = require('./create-defaults');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bookshelf hook
|
* Bookshelf hook
|
||||||
|
|||||||
@ -55,6 +55,14 @@
|
|||||||
"config": {
|
"config": {
|
||||||
"policies": []
|
"policies": []
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "GET",
|
||||||
|
"path": "/groups/:uid",
|
||||||
|
"handler": "Groups.getGroup",
|
||||||
|
"config": {
|
||||||
|
"policies": []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,12 +7,36 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
/**
|
/**
|
||||||
* GET /groups handler
|
* GET /groups handler
|
||||||
|
* Returns a list of available groups
|
||||||
*/
|
*/
|
||||||
async getGroups(ctx) {
|
async getGroups(ctx) {
|
||||||
const data = await strapi
|
const data = await strapi.groupManager.all();
|
||||||
.service('content-type-builder.groups')
|
|
||||||
.listGroups();
|
|
||||||
|
|
||||||
ctx.body = { data };
|
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';
|
'use strict';
|
||||||
|
|
||||||
module.exports = {
|
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,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|||||||
@ -26,6 +26,7 @@ const initializeHooks = require('./hooks');
|
|||||||
const createStrapiFs = require('./core/fs');
|
const createStrapiFs = require('./core/fs');
|
||||||
const getPrefixedDeps = require('./utils/get-prefixed-dependencies');
|
const getPrefixedDeps = require('./utils/get-prefixed-dependencies');
|
||||||
const defaultQueries = require('./core-api/queries');
|
const defaultQueries = require('./core-api/queries');
|
||||||
|
const createGroupManager = require('./services/groups');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an Strapi instance.
|
* Construct an Strapi instance.
|
||||||
@ -101,6 +102,7 @@ class Strapi extends EventEmitter {
|
|||||||
installedHooks: getPrefixedDeps('strapi-hook', pkgJSON),
|
installedHooks: getPrefixedDeps('strapi-hook', pkgJSON),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.groupManager;
|
||||||
this.fs = createStrapiFs(this);
|
this.fs = createStrapiFs(this);
|
||||||
this.requireProjectBootstrap();
|
this.requireProjectBootstrap();
|
||||||
}
|
}
|
||||||
@ -286,6 +288,10 @@ class Strapi extends EventEmitter {
|
|||||||
|
|
||||||
await bootstrap(this);
|
await bootstrap(this);
|
||||||
|
|
||||||
|
this.groupManager = createGroupManager({
|
||||||
|
groups,
|
||||||
|
});
|
||||||
|
|
||||||
// Usage.
|
// Usage.
|
||||||
await utils.usage(this.config);
|
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": {
|
"dependencies": {
|
||||||
"async": "^2.1.2",
|
"async": "^2.1.2",
|
||||||
"boom": "^5.2.0",
|
"boom": "^7.3.0",
|
||||||
"chalk": "^2.4.1",
|
"chalk": "^2.4.1",
|
||||||
"chokidar": "^2.1.2",
|
"chokidar": "^2.1.2",
|
||||||
"cross-spawn": "^6.0.5",
|
"cross-spawn": "^6.0.5",
|
||||||
|
|||||||
15
yarn.lock
15
yarn.lock
@ -3688,12 +3688,12 @@ boom@2.x.x:
|
|||||||
dependencies:
|
dependencies:
|
||||||
hoek "2.x.x"
|
hoek "2.x.x"
|
||||||
|
|
||||||
boom@^5.2.0:
|
boom@^7.3.0:
|
||||||
version "5.2.0"
|
version "7.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/boom/-/boom-5.2.0.tgz#5dd9da6ee3a5f302077436290cb717d3f4a54e02"
|
resolved "https://registry.yarnpkg.com/boom/-/boom-7.3.0.tgz#733a6d956d33b0b1999da3fe6c12996950d017b9"
|
||||||
integrity sha512-Z5BTk6ZRe4tXXQlkqftmsAUANpXmuwlsF5Oov8ThoMbQRzdGTA1ngYRW160GexgOgjsFOKJz0LYhoNi+2AMBUw==
|
integrity sha512-Swpoyi2t5+GhOEGw8rEsKvTxFLIDiiKoUc2gsoV6Lyr43LHBIzch3k2MvYUs8RTROrIkVJ3Al0TkaOGjnb+B6A==
|
||||||
dependencies:
|
dependencies:
|
||||||
hoek "4.x.x"
|
hoek "6.x.x"
|
||||||
|
|
||||||
bootstrap@^4.0.0-alpha.6:
|
bootstrap@^4.0.0-alpha.6:
|
||||||
version "4.3.1"
|
version "4.3.1"
|
||||||
@ -8272,11 +8272,6 @@ hoek@2.x.x:
|
|||||||
resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed"
|
resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed"
|
||||||
integrity sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0=
|
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:
|
hoek@5.x.x:
|
||||||
version "5.0.4"
|
version "5.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/hoek/-/hoek-5.0.4.tgz#0f7fa270a1cafeb364a4b2ddfaa33f864e4157da"
|
resolved "https://registry.yarnpkg.com/hoek/-/hoek-5.0.4.tgz#0f7fa270a1cafeb364a4b2ddfaa33f864e4157da"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user