page and offset filter FakeProduction

This commit is contained in:
nelo 2017-06-22 09:09:31 +02:00
parent 26e1e9a71b
commit 4890a69238
4 changed files with 23 additions and 1527 deletions

View File

@ -3,14 +3,35 @@ module.exports = function(FakeProduction) {
FakeProduction.defineScope();
FakeProduction.list = function(ctx, filter, cb){
var page = filter.page - 1;
var limit = filter.limit * page;
var offset = (page + 1) * filter.limit;
delete filter.limit;
delete filter.page;
FakeProduction.connectToService(ctx, "client");
filter.include = require('./filter.json');
this.find(filter, function(err, tickets) {
FakeProduction.disconnectFromService("client");
(err) ? cb(err, null) : cb(null, tickets);
(err) ? cb(err, null) : cb(null, (sum(tickets, limit, offset)));
});
function sum(tickets, limit, offset){
var obj = {lines: 0, m3: 0};
tickets.forEach(function(t) {
obj.lines += t.lines;
obj.m3 += t.m3;
}, this);
obj.m3 = obj.m3.toFixed(2);
obj.total = tickets.length;
obj.tickets = tickets.slice(limit, offset);
return obj;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,3 @@
var json = require("./list-fake.json");
module.exports = function(Ticket) {
Ticket.remoteMethod('list', {
description: 'List tickets for production',
@ -22,13 +20,8 @@ module.exports = function(Ticket) {
Ticket.list = function(cb) {
//list();
return fake(cb);
};
var fake = function(cb){
cb(null, json);
}
var list = function(){
var params = [1, 0];

View File

@ -4,6 +4,4 @@ module.exports = function(Ticket) {
var models = app.models;
// Methods
require('../methods/ticket/list.js')(Ticket);
};