Added controller with sql
This commit is contained in:
parent
7408d22b66
commit
1adaeca615
|
@ -0,0 +1,44 @@
|
||||||
|
|
||||||
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('getTravelDaysDuration', {
|
||||||
|
description: 'Return the total days of travel',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: {
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The travel id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
returns: {
|
||||||
|
type: 'number',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/:id/getTravelDaysDuration`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.getTravelDaysDuration = async id => {
|
||||||
|
let stmt;
|
||||||
|
|
||||||
|
stmt = new ParameterizedSQL(`
|
||||||
|
SELECT
|
||||||
|
ROUND(
|
||||||
|
AVG(
|
||||||
|
DATEDIFF(landed , shipped)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
FROM travel
|
||||||
|
WHERE agencyFk = ?
|
||||||
|
GROUP BY agencyFK`, [
|
||||||
|
id
|
||||||
|
]);
|
||||||
|
|
||||||
|
let result = await Self.rawStmt(stmt);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue