62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
|
module.exports = Self => {
|
||
|
Self.remoteMethodCtx('updateWorkerTimeControlMail', {
|
||
|
description: 'Updates the state of WorkerTimeControlMail',
|
||
|
accessType: 'WRITE',
|
||
|
accepts: [{
|
||
|
arg: 'workerId',
|
||
|
type: 'number',
|
||
|
required: true
|
||
|
},
|
||
|
{
|
||
|
arg: 'year',
|
||
|
type: 'number',
|
||
|
required: true
|
||
|
},
|
||
|
{
|
||
|
arg: 'week',
|
||
|
type: 'number',
|
||
|
required: true
|
||
|
},
|
||
|
{
|
||
|
arg: 'state',
|
||
|
type: 'string',
|
||
|
required: true
|
||
|
},
|
||
|
{
|
||
|
arg: 'emailResponse',
|
||
|
type: 'string'
|
||
|
}],
|
||
|
returns: {
|
||
|
type: 'boolean',
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/updateWorkerTimeControlMail`,
|
||
|
verb: 'POST'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.updateWorkerTimeControlMail = async(ctx, options) => {
|
||
|
const models = Self.app.models;
|
||
|
const args = ctx.args;
|
||
|
|
||
|
const myOptions = {};
|
||
|
|
||
|
if (typeof options == 'object')
|
||
|
Object.assign(myOptions, options);
|
||
|
|
||
|
const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({
|
||
|
where: {
|
||
|
workerFk: args.workerId,
|
||
|
year: args.year,
|
||
|
week: args.week
|
||
|
}
|
||
|
}, myOptions);
|
||
|
|
||
|
return workerTimeControlMail.updateAttributes({
|
||
|
state: args.state,
|
||
|
emailResponse: args.emailResponse || null
|
||
|
}, myOptions);
|
||
|
};
|
||
|
};
|