2019-07-19 18:14:13 +02:00
|
|
|
'use strict';
|
|
|
|
|
2019-07-22 09:56:25 +02:00
|
|
|
const storeUtils = require('./utils/store');
|
2019-07-19 18:14:13 +02:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
async getConfiguration(uid) {
|
2019-07-22 09:56:25 +02:00
|
|
|
const storeKey = groupUIDToStoreKey(uid);
|
|
|
|
return storeUtils.getModelConfiguration(storeKey);
|
2019-07-19 18:14:13 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
async setConfiguration(uid, input) {
|
|
|
|
const { settings, metadatas, layouts } = input;
|
|
|
|
|
2019-07-22 09:56:25 +02:00
|
|
|
const storeKey = groupUIDToStoreKey(uid);
|
|
|
|
return storeUtils.setModelConfiguration(storeKey, {
|
|
|
|
uid,
|
|
|
|
isGroup: true,
|
|
|
|
settings,
|
|
|
|
metadatas,
|
|
|
|
layouts,
|
|
|
|
});
|
2019-07-19 18:14:13 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
formatGroupSchema(group) {
|
|
|
|
const { associations, schema, allAttributes } = group;
|
|
|
|
return {
|
|
|
|
...schema,
|
|
|
|
attributes: Object.keys(allAttributes).reduce((acc, key) => {
|
|
|
|
const attr = allAttributes[key];
|
|
|
|
const assoc = associations.find(assoc => assoc.alias === key);
|
|
|
|
if (assoc) {
|
|
|
|
acc[key] = {
|
|
|
|
...attr,
|
|
|
|
type: 'relation',
|
|
|
|
targetModel: attr.model || attr.collection,
|
|
|
|
relationType: assoc.nature,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
acc[key] = attr;
|
|
|
|
}
|
|
|
|
return acc;
|
|
|
|
}, {}),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-07-22 09:56:25 +02:00
|
|
|
const groupUIDToStoreKey = uid => `groups::${uid}`;
|