new fake production table

list filter with fields
This commit is contained in:
nelo 2017-06-22 14:51:37 +02:00
parent 2bdbda6192
commit d996a56a1e
8 changed files with 180 additions and 114 deletions

View File

@ -45,18 +45,35 @@ module.exports = function(self) {
});
this.list = function(ctx, clientFilter, cb) {
var where = {and: []};
(clientFilter) ? where.and.push(clientFilter.where) : undefined;
(serverFilter) ? where.and.push(serverFilter.where) : undefined;
var clientFields = (clientFilter && clientFilter.fields) ? clientFilter.fields : [];
var serverFields = (serverFilter && serverFilter.fields) ? serverFilter.fields : [];
var fields = clientFields.filter(itemC => {
return serverFields.some(itemS => itemS === itemC);
});
var order = (clientFilter && clientFilter.order) ? clientFilter.order : (serverFilter && serverFilter.order) ? serverFilter.order : undefined;
var limit = (serverFilter && serverFilter.limit) ? serverFilter.limit : (clientFilter && clientFilter.limit) ? clientFilter.limit : undefined;
var and = [];
(clientFilter && clientFilter.where) && and.push(clientFilter.where);
(serverFilter && serverFilter.where) && and.push(serverFilter.where);
var order;
var limit;
if (clientFilter && clientFilter.order)
order = clientFilter.order;
else if (serverFilter && serverFilter.order)
order = serverFilter.order;
var filter = {where: where, order: order, limit: limit};
filter = removeEmpty(filter);
if (serverFilter && serverFilter.limit)
limit = serverFilter.limit;
else if (clientFilter && clientFilter.limit)
limit = clientFilter.limit;
var filter = {order: order, limit: limit};
filter.where = (and.length > 0) && {and: and};
filter.fields = fields;
this.find(filter, function(err, states) {
(!err) ? cb(null, states) : cb(err, null);
(err) ? cb(err, null) : cb(null, states);
});
};
};

View File

@ -1,44 +0,0 @@
[
{
"relation": "ticket",
"scope": {
"fields": ["id"]
}
},
{
"relation": "state",
"scope": {
"fields": ["id", "name"]
}
},
{
"relation": "agency",
"scope": {
"fields": ["id", "name"]
}
},
{
"relation": "province",
"scope": {
"fields": ["id", "name"]
}
},
{
"relation": "client",
"scope": {
"fields": ["id", "name"]
}
},
{
"relation": "worker",
"scope": {
"fields": ["id", "name", "surname"]
}
},
{
"relation": "salesPerson",
"scope": {
"fields": ["id", "name", "surname"]
}
}
]

View File

@ -13,8 +13,6 @@ module.exports = function(FakeProduction) {
FakeProduction.connectToService(ctx, "client");
filter.include = require('./filter.json');
this.find(filter, function(err, tickets) {
FakeProduction.disconnectFromService("client");
(err) ? cb(err, null) : cb(null, (sum(tickets, limit, offset)));

View File

@ -15,5 +15,20 @@
"type": "String"
}
},
"acls": []
"relations": {
"user": {
"type": "belongsTo",
"model": "Account",
"foreignKey": "userFk"
}
},
"acls": [],
"include":[
{
"relation": "user",
"scope": {
"fields": ["name"]
}
}
]
}

View File

@ -4,65 +4,71 @@
"validateUpsert": true,
"properties": {
"id": {
"id": true,
"type": "Number",
"forceId": false
"id": true,
"description": "Identifier"
},
"ticketFk": {
"type": "Number"
},
"clientFk": {
"type": "Number"
},
"client":{
"type": "String"
},
"hour":{
"type": "String"
},
"city":{
"type": "String"
},
"province":{
"type": "String"
},
"provinceFk":{
"type": "Number"
},
"agency":{
"type": "String"
},
"agencyFk":{
"type": "Number"
},
"lines":{
"type": "Number"
},
"m3":{
"type": "Number"
},
"boxes":{
"problems":{
"type": "Number"
},
"city":{
"type": "String"
},
"problem":{
"type": "String"
},
"state":{
"type": "String"
},
"stateFk":{
"type": "Number"
},
"worker":{
"type": "String"
},
"workerFk":{
"type": "Number"
},
"salesPerson":{
"type": "String"
},
"salesPersonFk":{
"type": "Number"
},
"boxes":{
"type": "Number"
}
},
"relations": {
"ticket": {
"type": "belongsTo",
"model": "Ticket",
"foreignKey": "ticketFk"
},
"state": {
"type": "belongsTo",
"model": "State",
"foreignKey": "stateFk"
},
"agency": {
"type": "belongsTo",
"model": "Agency",
"foreignKey": "agencyFk"
},
"province": {
"type": "belongsTo",
"model": "Province",
"foreignKey": "provinceFk"
},
"client": {
"type": "belongsTo",
"model": "Client",
"foreignKey": "clientFk"
},
"worker": {
"type": "belongsTo",
"model": "Employee",
"foreignKey": "workerFk"
},
"salesPerson": {
"type": "belongsTo",
"model": "Employee",
"foreignKey": "salesPersonFk"
}
},
"acls": [
{

View File

@ -45,18 +45,35 @@ module.exports = function(self) {
});
this.list = function(ctx, clientFilter, cb) {
var where = {and: []};
(clientFilter) ? where.and.push(clientFilter.where) : undefined;
(serverFilter) ? where.and.push(serverFilter.where) : undefined;
var clientFields = (clientFilter && clientFilter.fields) ? clientFilter.fields : [];
var serverFields = (serverFilter && serverFilter.fields) ? serverFilter.fields : [];
var fields = clientFields.filter(itemC => {
return serverFields.some(itemS => itemS === itemC);
});
var order = (clientFilter && clientFilter.order) ? clientFilter.order : (serverFilter && serverFilter.order) ? serverFilter.order : undefined;
var limit = (serverFilter && serverFilter.limit) ? serverFilter.limit : (clientFilter && clientFilter.limit) ? clientFilter.limit : undefined;
var and = [];
(clientFilter && clientFilter.where) && and.push(clientFilter.where);
(serverFilter && serverFilter.where) && and.push(serverFilter.where);
var order;
var limit;
if (clientFilter && clientFilter.order)
order = clientFilter.order;
else if (serverFilter && serverFilter.order)
order = serverFilter.order;
var filter = {where: where, order: order, limit: limit};
filter = removeEmpty(filter);
if (serverFilter && serverFilter.limit)
limit = serverFilter.limit;
else if (clientFilter && clientFilter.limit)
limit = clientFilter.limit;
var filter = {order: order, limit: limit};
filter.where = (and.length > 0) && {and: and};
filter.fields = fields;
this.find(filter, function(err, states) {
(!err) ? cb(null, states) : cb(err, null);
(err) ? cb(err, null) : cb(null, states);
});
};
};

View File

@ -0,0 +1,40 @@
select tmp.Id_Ticket as ticketFk,
tmp.Id_Cliente as clientFk,
tmp.Alias as client,
tmp.Hora as hour,
tmp.POBLACION as city,
tmp.PROVINCIA as province,
tmp.province_id as provinceFk,
tmp.Agencia as agency,
tmp.agency_id as agencyFk,
tmp.lines,
tmp.m3,
tmp.problems,
tmp.problem,
tmp.state as stateFk,
t.Id_Trabajador as workerfk,
concat(t.Nombre, ' ', t.Apellidos) as worker,
tt.Id_Trabajador as salesPersonFk,
concat(tt.Nombre, ' ', tt.Apellidos) as salesPerson,
s.name as state,
tmp.Cajas as boxes
from tmp.production_buffer tmp
inner join state s
on tmp.state = s.id
inner join Trabajadores t
on tmp.CodigoTrabajador = t.CodigoTrabajador collate utf8_unicode_ci
inner join Trabajadores tt
on tmp.Comercial = tt.CodigoTrabajador collate utf8_unicode_ci;
ALTER TABLE `salix`.`FakeProduction`
CHANGE COLUMN `client` `client` VARCHAR(50) NULL DEFAULT NULL ,
CHANGE COLUMN `hour` `hour` TIME NULL DEFAULT NULL ,
CHANGE COLUMN `city` `city` VARCHAR(50) NULL DEFAULT NULL ,
CHANGE COLUMN `province` `province` VARCHAR(50) NULL DEFAULT NULL ,
CHANGE COLUMN `agency` `agency` VARCHAR(50) NULL DEFAULT NULL ,
CHANGE COLUMN `problem` `problem` VARCHAR(50) NULL DEFAULT NULL ,
CHANGE COLUMN `worker` `worker` VARCHAR(50) NULL DEFAULT NULL ,
CHANGE COLUMN `salesPerson` `salesPerson` VARCHAR(50) NULL DEFAULT NULL ,
CHANGE COLUMN `state` `state` VARCHAR(50) NULL DEFAULT NULL ;
update salix.FakeProduction set problem = null where problem like '% %';

View File

@ -45,18 +45,35 @@ module.exports = function(self) {
});
this.list = function(ctx, clientFilter, cb) {
var where = {and: []};
(clientFilter) ? where.and.push(clientFilter.where) : undefined;
(serverFilter) ? where.and.push(serverFilter.where) : undefined;
var clientFields = (clientFilter && clientFilter.fields) ? clientFilter.fields : [];
var serverFields = (serverFilter && serverFilter.fields) ? serverFilter.fields : [];
var fields = clientFields.filter(itemC => {
return serverFields.some(itemS => itemS === itemC);
});
var order = (clientFilter && clientFilter.order) ? clientFilter.order : (serverFilter && serverFilter.order) ? serverFilter.order : undefined;
var limit = (serverFilter && serverFilter.limit) ? serverFilter.limit : (clientFilter && clientFilter.limit) ? clientFilter.limit : undefined;
var and = [];
(clientFilter && clientFilter.where) && and.push(clientFilter.where);
(serverFilter && serverFilter.where) && and.push(serverFilter.where);
var order;
var limit;
if (clientFilter && clientFilter.order)
order = clientFilter.order;
else if (serverFilter && serverFilter.order)
order = serverFilter.order;
var filter = {where: where, order: order, limit: limit};
filter = removeEmpty(filter);
if (serverFilter && serverFilter.limit)
limit = serverFilter.limit;
else if (clientFilter && clientFilter.limit)
limit = clientFilter.limit;
var filter = {order: order, limit: limit};
filter.where = (and.length > 0) && {and: and};
filter.fields = fields;
this.find(filter, function(err, states) {
(!err) ? cb(null, states) : cb(err, null);
(err) ? cb(err, null) : cb(null, states);
});
};
};