ref #6276 operator_add
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2023-11-02 16:25:25 +01:00
parent 83b9ef72fc
commit d0975f0acd
3 changed files with 24 additions and 1 deletions

View File

View File

@ -0,0 +1,21 @@
module.exports = Self => {
Self.remoteMethodCtx('add', {
description: 'Add a new operator',
accessType: 'WRITE',
http: {
path: `/add`,
verb: 'POST'
}
});
Self.add = async ctx => {
const userId = ctx.req.accessToken.userId;
// He visto findOrCreate pero no funciona
const user = await Self.findById(userId);
if (!user) {
await Self.create({
workerFk: userId
});
}
};
};

View File

@ -1,4 +1,6 @@
module.exports = function(Self) {
module.exports = Self => {
require('../methods/operator/add')(Self);
Self.observe('after save', async function(ctx) {
const instance = ctx.data || ctx.instance;
const models = Self.app.models;