Merge pull request 'fix(getFiltered): refs #3271 fix to event filter' (!1872) from 3271-zoneGetFilterdFix into test
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #1872 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
6699f5d5a6
|
@ -2347,9 +2347,11 @@ INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `weekDays`)
|
||||||
(8, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'),
|
(8, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'),
|
||||||
(10, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun');
|
(10, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun');
|
||||||
|
|
||||||
INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `started`, `ended`)
|
INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `started`, `ended`, `weekDays`)
|
||||||
VALUES
|
VALUES
|
||||||
(9, 'range', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR));
|
(9, 'range', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR), 'mon'),
|
||||||
|
(9, 'range', util.VN_CURDATE(), NULL, 'tue'),
|
||||||
|
(9, 'range', NULL, util.VN_CURDATE(), 'wed');
|
||||||
|
|
||||||
INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`, `isSendMail`)
|
INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`, `isSendMail`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -80,13 +80,15 @@ module.exports = Self => {
|
||||||
};
|
};
|
||||||
const conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
|
|
||||||
let where = buildFilter(params, (param, value) => {return {[param]: value}});
|
let where = buildFilter(params, (param, value) => {
|
||||||
|
return {[param]: value};
|
||||||
|
});
|
||||||
filter = mergeFilters(filter, {where});
|
filter = mergeFilters(filter, {where});
|
||||||
|
|
||||||
if (!filter.where) {
|
if (!filter.where) {
|
||||||
const yesterday = new Date();
|
const yesterday = new Date();
|
||||||
yesterday.setDate(yesterday.getDate() - 1);
|
yesterday.setDate(yesterday.getDate() - 1);
|
||||||
filter.where = {'shipped': yesterday.toISOString().split('T')[0]}
|
filter.where = {'shipped': yesterday.toISOString().split('T')[0]};
|
||||||
}
|
}
|
||||||
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
|
@ -35,25 +35,17 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
ended = simpleDate(ended);
|
||||||
|
started = simpleDate(started);
|
||||||
|
|
||||||
query = `
|
query = `
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM vn.zoneEvent
|
FROM vn.zoneEvent
|
||||||
WHERE zoneFk = ?
|
WHERE zoneFk = ?
|
||||||
AND ((type = 'indefinitely')
|
AND (IFNULL(started, ?) <= ? AND IFNULL(ended,?) >= ?)
|
||||||
OR (type = 'day' AND dated BETWEEN ? AND ?)
|
|
||||||
OR (type = 'range'
|
|
||||||
AND (
|
|
||||||
(started BETWEEN ? AND ?)
|
|
||||||
OR
|
|
||||||
(ended BETWEEN ? AND ?)
|
|
||||||
OR
|
|
||||||
(started <= ? AND ended >= ?)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
ORDER BY type='indefinitely' DESC, type='range' DESC, type='day' DESC;`;
|
ORDER BY type='indefinitely' DESC, type='range' DESC, type='day' DESC;`;
|
||||||
const events = await Self.rawSql(query,
|
const events = await Self.rawSql(query,
|
||||||
[zoneFk, started, ended, started, ended, started, ended, started, ended], myOptions);
|
[zoneFk, started, ended, ended, started], myOptions);
|
||||||
|
|
||||||
query = `
|
query = `
|
||||||
SELECT e.*
|
SELECT e.*
|
||||||
|
@ -75,4 +67,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
return {events, exclusions, geoExclusions};
|
return {events, exclusions, geoExclusions};
|
||||||
};
|
};
|
||||||
|
function simpleDate(date) {
|
||||||
|
return date.toISOString().split('T')[0];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,7 +30,7 @@ describe('zone getEventsFiltered()', () => {
|
||||||
|
|
||||||
const result = await models.Zone.getEventsFiltered(9, today, today, options);
|
const result = await models.Zone.getEventsFiltered(9, today, today, options);
|
||||||
|
|
||||||
expect(result.events.length).toEqual(1);
|
expect(result.events.length).toEqual(3);
|
||||||
expect(result.exclusions.length).toEqual(0);
|
expect(result.exclusions.length).toEqual(0);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
@ -47,11 +47,12 @@ describe('zone getEventsFiltered()', () => {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const date = Date.vnNew();
|
const date = Date.vnNew();
|
||||||
date.setFullYear(date.getFullYear() - 2);
|
date.setFullYear(date.getFullYear() - 2);
|
||||||
const dateTomorrow = new Date(date.setDate(date.getDate() + 1));
|
const dateTomorrow = new Date(date);
|
||||||
|
dateTomorrow.setDate(dateTomorrow.getDate() + 1);
|
||||||
|
|
||||||
const result = await models.Zone.getEventsFiltered(9, date, dateTomorrow, options);
|
const result = await models.Zone.getEventsFiltered(9, date, dateTomorrow, options);
|
||||||
|
|
||||||
expect(result.events.length).toEqual(0);
|
expect(result.events.length).toEqual(1);
|
||||||
expect(result.exclusions.length).toEqual(0);
|
expect(result.exclusions.length).toEqual(0);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
|
Loading…
Reference in New Issue