diff --git a/db/changes/234601/00-newWareHouse.sql b/db/changes/234601/00-newWareHouse.sql new file mode 100644 index 000000000..e69de29bb diff --git a/modules/worker/back/methods/operator/add.js b/modules/worker/back/methods/operator/add.js new file mode 100644 index 000000000..65639ad01 --- /dev/null +++ b/modules/worker/back/methods/operator/add.js @@ -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 + }); + } + }; +}; diff --git a/modules/worker/back/models/operator.js b/modules/worker/back/models/operator.js index db1ac7e49..442ac343f 100644 --- a/modules/worker/back/models/operator.js +++ b/modules/worker/back/models/operator.js @@ -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;