salix/modules/worker/back/methods/operator/add.js

22 lines
581 B
JavaScript
Raw Normal View History

2023-11-02 15:25:25 +00:00
module.exports = Self => {
Self.remoteMethodCtx('add', {
description: 'Add a new operator',
accessType: 'WRITE',
http: {
path: `/add`,
verb: 'POST'
}
});
2024-01-19 13:35:10 +00:00
Self.add = async(ctx, options) => {
2023-11-02 15:25:25 +00:00
const userId = ctx.req.accessToken.userId;
2024-01-19 13:35:10 +00:00
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
2024-02-02 08:23:29 +00:00
const isOperator = await Self.findById(userId, myOptions);
if (!isOperator) await Self.create({workerFk: userId}, myOptions);
2023-11-02 15:25:25 +00:00
};
};