Merge branch 'test' into dev
gitea/salix/dev This commit has test failures
Details
gitea/salix/dev This commit has test failures
Details
This commit is contained in:
commit
fbc84f48a1
|
@ -7,16 +7,44 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.observe('before save', async function(ctx) {
|
Self.observe('before save', async function(ctx) {
|
||||||
let models = Self.app.models;
|
let models = Self.app.models;
|
||||||
let data = ctx.instance;
|
let changes = ctx.data || ctx.instance;
|
||||||
|
|
||||||
let sample = await models.Sample.findById(data.typeFk);
|
let sample = await models.Sample.findById(changes.typeFk);
|
||||||
|
|
||||||
if (sample.hasCompany && !data.companyFk)
|
if (sample.hasCompany && !changes.companyFk)
|
||||||
throw new UserError('Choose a company');
|
throw new UserError('Choose a company');
|
||||||
|
|
||||||
|
// Renew mandate
|
||||||
|
if (sample.code === 'sepa-core') {
|
||||||
|
let mandateType = await models.MandateType.findOne({
|
||||||
|
where: {name: 'CORE'}
|
||||||
|
});
|
||||||
|
|
||||||
|
let oldMandate = await models.Mandate.findOne({
|
||||||
|
where: {
|
||||||
|
clientFk: changes.clientFk,
|
||||||
|
companyFk: changes.companyFk,
|
||||||
|
mandateTypeFk: mandateType.id,
|
||||||
|
finished: null
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Disable old mandate
|
||||||
|
if (oldMandate)
|
||||||
|
oldMandate.updateAttribute('finished', new Date());
|
||||||
|
|
||||||
|
// Create a new mandate
|
||||||
|
await models.Mandate.create({
|
||||||
|
clientFk: changes.clientFk,
|
||||||
|
companyFk: changes.companyFk,
|
||||||
|
mandateTypeFk: mandateType.id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply workerFk
|
||||||
let filter = {where: {userFk: ctx.options.accessToken.userId}};
|
let filter = {where: {userFk: ctx.options.accessToken.userId}};
|
||||||
let worker = await Self.app.models.Worker.findOne(filter);
|
let worker = await Self.app.models.Worker.findOne(filter);
|
||||||
|
|
||||||
data.workerFk = worker.id;
|
changes.workerFk = worker.id;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -99,11 +99,13 @@ module.exports = Self => {
|
||||||
|
|
||||||
let teamIds = [];
|
let teamIds = [];
|
||||||
|
|
||||||
if (worker.collegues().length) {
|
if (worker.collegues().length && ctx.args.myTeam) {
|
||||||
worker.collegues().forEach(collegue => {
|
worker.collegues().forEach(collegue => {
|
||||||
teamIds.push(collegue.collegueFk);
|
teamIds.push(collegue.collegueFk);
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (ctx.args.mine || (worker.collegues().length === 0 && ctx.args.myTeam)) {
|
||||||
worker = await Self.app.models.Worker.findOne({
|
worker = await Self.app.models.Worker.findOne({
|
||||||
fields: ['id'],
|
fields: ['id'],
|
||||||
where: {userFk: ctx.req.accessToken.userId}
|
where: {userFk: ctx.req.accessToken.userId}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
url="/ticket/api/Tickets/filter"
|
url="/ticket/api/Tickets/filter"
|
||||||
limit="20"
|
limit="20"
|
||||||
data="tickets"
|
data="tickets"
|
||||||
order="shipped DESC, clientFk"
|
order="shipped ASC, clientFk"
|
||||||
auto-load="false">
|
auto-load="false">
|
||||||
</vn-crud-model>
|
</vn-crud-model>
|
||||||
<div class="content-block">
|
<div class="content-block">
|
||||||
|
|
|
@ -12,28 +12,25 @@ export default class Controller {
|
||||||
this.goToTurns('ticket.weekly');
|
this.goToTurns('ticket.weekly');
|
||||||
}, name: 'Turns', always: true},
|
}, name: 'Turns', always: true},
|
||||||
];
|
];
|
||||||
|
this.filter = {};
|
||||||
|
|
||||||
if (!$stateParams.q) {
|
if (!$stateParams.q) {
|
||||||
let today = new Date();
|
let today = new Date();
|
||||||
let offset = today.getTimezoneOffset() * 60000;
|
|
||||||
today.setHours(0, 0, 0, 0);
|
today.setHours(0, 0, 0, 0);
|
||||||
today.setTime(today.getTime() - offset);
|
|
||||||
|
|
||||||
let tomorrow = new Date(today);
|
let tomorrow = new Date(today);
|
||||||
tomorrow.setHours(23, 59, 59, 999);
|
tomorrow.setHours(23, 59, 59, 999);
|
||||||
tomorrow.setTime(tomorrow.getTime() - offset);
|
|
||||||
|
|
||||||
let sixDays = new Date(today);
|
let sixDays = new Date(today);
|
||||||
sixDays.setDate(today.getDate() + 6);
|
sixDays.setDate(today.getDate() + 6);
|
||||||
sixDays.setHours(23, 59, 59, 999);
|
sixDays.setHours(23, 59, 59, 999);
|
||||||
sixDays.setTime(sixDays.getTime() - offset);
|
|
||||||
|
|
||||||
this.filter = {mine: true, from: today, to: sixDays};
|
this.filter = Object.assign(this.filter, {myTeam: true, from: today, to: sixDays});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$postLink() {
|
$postLink() {
|
||||||
if (this.filter)
|
if (this.filter && this.filter != {})
|
||||||
this.onSearch(this.filter);
|
this.onSearch(this.filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue