fix(zone): back remoteMethod
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2021-11-04 07:56:12 +01:00
parent b2dd9e6076
commit 3324f4acd2
2 changed files with 55 additions and 16 deletions

View File

@ -1,7 +1,24 @@
module.exports = Self => {
Self.remoteMethodCtx('getEventsFiltered', {
Self.remoteMethod('getEventsFiltered', {
description: 'Get events filtered for zone and date',
accessType: 'READ',
accepts: [
{
arg: 'zoneFk',
type: 'number',
description: 'The zone id',
required: true
},
{
arg: 'started',
type: 'date',
description: 'The date calendar start',
},
{
arg: 'ended',
type: 'date',
description: 'The date calendar end',
}
],
returns: {
type: 'object',
root: true
@ -13,9 +30,29 @@ module.exports = Self => {
});
Self.getEventsFiltered = async(zoneFk, started, ended) => {
query = `CALL vn.zone_getEventsFiltered(?,?,?)`;
const [events, exclusions] = await Self.rawSql(query, [zoneFk, started, ended]);
console.log(events);
query = `
SELECT *
FROM vn.zoneEvent
WHERE zoneFk = ?
AND ((type = 'indefinitely')
OR (type = 'day' AND dated BETWEEN ? AND ?)
OR (type = 'range'
AND (
(started BETWEEN ? AND ?)
OR (ended BETWEEN ? AND ?)
)
)
)
ORDER BY type='indefinitely',type='range',type='day';`;
const events = await Self.rawSql(query, [zoneFk, started, ended, started, ended, started, ended]);
query = `
SELECT *
FROM vn.zoneExclusion
WHERE zoneFk = ?
AND dated BETWEEN ? AND ?;`;
const exclusions = await Self.rawSql(query, [zoneFk, started, ended]);
return {events, exclusions};
};
};

View File

@ -12,21 +12,23 @@ class Controller extends Section {
this.refresh();
}
get path() {
return `Zones/${this.$params.id}/events`;
}
get exclusionsPath() {
return `Zones/${this.$params.id}/exclusions`;
}
refresh() {
this.$.data = null;
let params = {
ended: '2022-01-31',
started: '2021-10-01',
zoneFk: 10
zoneFk: 10,
started: new Date('2021-10-01'),
ended: new Date('2022-02-31')
};
let ended = '2022-01-31';
let started = '2021-10-01';
let zoneFk = 10;
// let filter = encodeURIComponent(JSON.stringify(params));
let path = `Zones/getEventsFiltered?zoneFk=${zoneFk}&started=${started}&ended=${ended}`;
console.log(path);
this.$http.get(path).then(res => {
console.log(res.data);
this.$http.get(`Zones/getEventsFiltered`, {params}).then(res => {
let data = res.data;
this.$.data = data;
});