4221-intrastat #1022
|
@ -2230,6 +2230,10 @@ INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `weekDays`)
|
|||
(8, '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`)
|
||||
VALUES
|
||||
(9, 'range', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR));
|
||||
|
||||
INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`)
|
||||
VALUES
|
||||
(1106, CONCAT(util.VN_CURDATE(), ' 07:00'), TRUE, 'in'),
|
||||
|
|
|
@ -44,12 +44,16 @@ module.exports = Self => {
|
|||
OR (type = 'range'
|
||||
AND (
|
||||
(started BETWEEN ? AND ?)
|
||||
OR (ended BETWEEN ? AND ?)
|
||||
OR
|
||||
(ended BETWEEN ? AND ?)
|
||||
OR
|
||||
(started <= ? AND ended >= ?)
|
||||
)
|
||||
)
|
||||
)
|
||||
ORDER BY type='indefinitely' DESC, type='range' DESC, type='day' DESC;`;
|
||||
const events = await Self.rawSql(query, [zoneFk, started, ended, started, ended, started, ended], myOptions);
|
||||
const events = await Self.rawSql(query,
|
||||
[zoneFk, started, ended, started, ended, started, ended, started, ended], myOptions);
|
||||
|
||||
query = `
|
||||
SELECT *
|
||||
|
|
|
@ -6,8 +6,9 @@ describe('zone getEventsFiltered()', () => {
|
|||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const today = new Date();
|
||||
|
||||
let result = await models.Zone.getEventsFiltered(10, '2021-10-01', '2021-10-02', options);
|
||||
const result = await models.Zone.getEventsFiltered(10, today, today, options);
|
||||
|
||||
expect(result.events.length).toEqual(1);
|
||||
expect(result.exclusions.length).toEqual(0);
|
||||
|
@ -18,4 +19,46 @@ describe('zone getEventsFiltered()', () => {
|
|||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
describe('event range type', () => {
|
||||
it('should return events and exclusions for the zone 9 in a range of dates', async() => {
|
||||
const tx = await models.Zone.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const today = new Date();
|
||||
|
||||
const result = await models.Zone.getEventsFiltered(9, today, today, options);
|
||||
|
||||
expect(result.events.length).toEqual(1);
|
||||
expect(result.exclusions.length).toEqual(0);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should not return events and exclusions for the zone 9 in a range of dates', async() => {
|
||||
const tx = await models.Zone.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const date = new Date();
|
||||
date.setFullYear(date.getFullYear() - 2);
|
||||
const dateTomorrow = new Date(date.setDate(date.getDate() + 1));
|
||||
|
||||
const result = await models.Zone.getEventsFiltered(9, date, dateTomorrow, options);
|
||||
|
||||
expect(result.events.length).toEqual(0);
|
||||
expect(result.exclusions.length).toEqual(0);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue