refactor(worker): absences return one or all abscences
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
17b178b6bf
commit
c33b8fbb83
|
@ -12,6 +12,11 @@ module.exports = Self => {
|
||||||
arg: 'year',
|
arg: 'year',
|
||||||
type: 'date',
|
type: 'date',
|
||||||
required: true,
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'all',
|
||||||
|
type: 'boolean',
|
||||||
|
required: false,
|
||||||
}],
|
}],
|
||||||
returns: [{
|
returns: [{
|
||||||
arg: 'absences',
|
arg: 'absences',
|
||||||
|
@ -27,7 +32,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.absences = async(ctx, businessFk, year, options) => {
|
Self.absences = async(ctx, businessFk, year, all, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
|
||||||
const started = new Date();
|
const started = new Date();
|
||||||
|
@ -45,6 +50,12 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
let where = {businessFk};
|
||||||
|
if (all) {
|
||||||
|
let worker = await models.WorkerLabour.findOne({where: where});
|
||||||
|
where = {workerFk: worker.workerFk};
|
||||||
|
}
|
||||||
|
|
||||||
const contract = await models.WorkerLabour.findOne({
|
const contract = await models.WorkerLabour.findOne({
|
||||||
include: [{
|
include: [{
|
||||||
relation: 'holidays',
|
relation: 'holidays',
|
||||||
|
@ -82,7 +93,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
where: {businessFk}
|
where: where
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
if (!contract) return;
|
if (!contract) return;
|
||||||
|
|
|
@ -128,7 +128,8 @@ class Controller extends Section {
|
||||||
const fullYear = this.started.getFullYear();
|
const fullYear = this.started.getFullYear();
|
||||||
let params = {
|
let params = {
|
||||||
businessFk: this.businessId,
|
businessFk: this.businessId,
|
||||||
year: fullYear
|
year: fullYear,
|
||||||
|
all: true
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.$http.get(`Calendars/absences`, {params})
|
return this.$http.get(`Calendars/absences`, {params})
|
||||||
|
|
Loading…
Reference in New Issue