page and offset filter FakeProduction
This commit is contained in:
parent
26e1e9a71b
commit
4890a69238
|
@ -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
|
@ -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];
|
||||
|
||||
|
|
|
@ -4,6 +4,4 @@ module.exports = function(Ticket) {
|
|||
var models = app.models;
|
||||
|
||||
// Methods
|
||||
|
||||
require('../methods/ticket/list.js')(Ticket);
|
||||
};
|
Loading…
Reference in New Issue