48 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-07-19 18:14:13 +02:00
'use strict';
const storeUtils = require('./utils/store');
2019-07-19 18:14:13 +02:00
module.exports = {
async getConfiguration(uid) {
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;
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;
}, {}),
};
},
};
const groupUIDToStoreKey = uid => `groups::${uid}`;