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);
|
2024-02-01 11:56:11 +00:00
|
|
|
if (!isOperator) await Self.create({workerFk: userId}, myOptions);
|
2023-11-02 15:25:25 +00:00
|
|
|
};
|
|
|
|
};
|