2019-02-12 16:24:37 +00:00
|
|
|
module.exports = function(Self) {
|
|
|
|
Self.remoteMethodCtx('save', {
|
|
|
|
description: 'returns the information from UserConfig model for the active user',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'config',
|
|
|
|
type: 'Object',
|
|
|
|
required: true,
|
|
|
|
description: `Code of the table you ask its configuration`,
|
|
|
|
http: {source: 'body'}
|
2021-10-27 15:11:33 +00:00
|
|
|
}],
|
2019-02-12 16:24:37 +00:00
|
|
|
returns: {
|
|
|
|
type: 'object',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/save`,
|
|
|
|
verb: 'post'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.save = async(ctx, config) => {
|
|
|
|
let userView = await Self.app.models.UserConfigView.findOne({
|
|
|
|
where: {tableCode: config.tableCode, userFk: ctx.req.accessToken.userId}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (userView)
|
|
|
|
return userView.updateAttributes(config);
|
|
|
|
|
|
|
|
config.userFk = ctx.req.accessToken.userId;
|
|
|
|
|
2021-10-27 15:11:33 +00:00
|
|
|
return Self.app.models.UserConfigView.create(config);
|
2019-02-12 16:24:37 +00:00
|
|
|
};
|
|
|
|
};
|