fix: refs #8370 deleted use of Time model
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
c1dd0eeb32
commit
dad67cc266
|
@ -1,4 +1,5 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('getMailStates', {
|
Self.remoteMethodCtx('getMailStates', {
|
||||||
|
@ -34,32 +35,36 @@ module.exports = Self => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
const month = args.month;
|
||||||
|
const year = args.year;
|
||||||
|
const weeksOfMonth = getWeeksOfMonth(year, month);
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
if (!await models.Worker.isSubordinate(ctx, workerId)) throw new UserError(`You don't have enough privileges`);
|
if (!await models.Worker.isSubordinate(ctx, workerId)) throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
const times = await models.Time.find({
|
|
||||||
fields: ['week'],
|
|
||||||
where: {
|
|
||||||
month: args.month,
|
|
||||||
year: args.year
|
|
||||||
}
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const weeks = times.map(time => time.week);
|
|
||||||
const weekNumbersSet = new Set(weeks);
|
|
||||||
const weekNumbers = Array.from(weekNumbersSet);
|
|
||||||
|
|
||||||
const workerTimeControlMails = await models.WorkerTimeControlMail.find({
|
const workerTimeControlMails = await models.WorkerTimeControlMail.find({
|
||||||
where: {
|
where: {
|
||||||
workerFk: workerId,
|
workerFk: workerId,
|
||||||
year: args.year,
|
year: args.year,
|
||||||
week: {inq: weekNumbers}
|
week: {inq: weeksOfMonth}
|
||||||
}
|
}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
return workerTimeControlMails;
|
return workerTimeControlMails;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getWeeksOfMonth = (year, month) => {
|
||||||
|
const firstDayOfMonth = moment(`${year}-${month}-01`, 'YYYY-MM-DD');
|
||||||
|
const lastDayOfMonth = moment(firstDayOfMonth).endOf('month');
|
||||||
|
const firstWeek = firstDayOfMonth.isoWeek();
|
||||||
|
const lastWeek = lastDayOfMonth.isoWeek();
|
||||||
|
const weeks = [];
|
||||||
|
|
||||||
|
for (let week = firstWeek; week <= lastWeek; week++)
|
||||||
|
weeks.push(week);
|
||||||
|
|
||||||
|
return weeks;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue