diff --git a/services/client/common/models/my-model.js b/services/client/common/models/my-model.js index 1372fc644f..bfc5cf015d 100644 --- a/services/client/common/models/my-model.js +++ b/services/client/common/models/my-model.js @@ -28,7 +28,7 @@ module.exports = function(self) { }; self.defineScope = function(serverFilter) { - this.remoteMethod('list', { + this.remoteMethodCtx('list', { accepts: [ { arg: 'filter', @@ -46,7 +46,7 @@ module.exports = function(self) { } }); - this.list = function(clientFilter, cb) { + this.list = function(ctx, clientFilter, cb) { var where = {"and": []}; (clientFilter) ? where.and.push(clientFilter.where) : undefined; (serverFilter) ? where.and.push(serverFilter.where) : undefined; diff --git a/services/production/common/methods/fake-production/list.js b/services/production/common/methods/fake-production/list.js new file mode 100644 index 0000000000..6894500e06 --- /dev/null +++ b/services/production/common/methods/fake-production/list.js @@ -0,0 +1,15 @@ +module.exports = function(FakeProduction) { + + FakeProduction.defineScope(); + + FakeProduction.list = function(ctx, filter, cb){ + FakeProduction.connectToService(ctx, "client"); + + this.find(filter, function(err, tickets) { + (!err) ? cb(null, tickets) : cb(err, null); + }); + + FakeProduction.disconnectFromService("client"); + } + +} \ No newline at end of file diff --git a/services/production/common/models/client.json b/services/production/common/models/client.json new file mode 100644 index 0000000000..cdbfa7e3d7 --- /dev/null +++ b/services/production/common/models/client.json @@ -0,0 +1,32 @@ +{ + "name": "Client", + "base": "MyModel", + "validateUpsert": true, + "properties": { + "id": { + "type": "Number", + "id": true, + "description": "Identifier" + }, + "name": { + "type": "string", + "required": true + } + }, + "acls": [ + { + "accessType": "*", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "DENY" + }, + { + "accessType": "*", + "principalType": "ROLE", + "principalId": "root", + "permission": "ALLOW" + } + ], + "validations": [], + "methods": {} +} \ No newline at end of file diff --git a/services/production/common/models/employee.json b/services/production/common/models/employee.json index bb676a071c..c3590d7484 100644 --- a/services/production/common/models/employee.json +++ b/services/production/common/models/employee.json @@ -7,6 +7,9 @@ "type": "Number", "id": true, "description": "Identifier" + }, + "name":{ + "type": "String" } }, "acls": [] diff --git a/services/production/common/models/fake-production.js b/services/production/common/models/fake-production.js new file mode 100644 index 0000000000..f7f277b99b --- /dev/null +++ b/services/production/common/models/fake-production.js @@ -0,0 +1,8 @@ +var app = require('../../server/server'); + +module.exports = function(FakeProduction) { + var models = app.models; + + // Methods + require('../methods/fake-production/list.js')(FakeProduction); +}; \ No newline at end of file diff --git a/services/production/common/models/fake-production.json b/services/production/common/models/fake-production.json new file mode 100644 index 0000000000..469d5bfd58 --- /dev/null +++ b/services/production/common/models/fake-production.json @@ -0,0 +1,81 @@ +{ + "name": "FakeProduction", + "base": "MyModel", + "validateUpsert": true, + "properties": { + "id": { + "id": true, + "type": "Number", + "forceId": false + }, + "hour":{ + "type": "String" + }, + "lines":{ + "type": "Number" + }, + "m3":{ + "type": "Number" + }, + "boxes":{ + "type": "Number" + }, + "city":{ + "type": "String" + }, + "problem":{ + "type": "String" + } + }, + "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" + }, + "salePerson": { + "type": "belongsTo", + "model": "Employee", + "foreignKey": "salePersonFk" + } + }, + "acls": [ + { + "accessType": "*", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "DENY" + }, + { + "accessType": "*", + "principalType": "ROLE", + "principalId": "root", + "permission": "ALLOW" + } + ] +} diff --git a/services/production/common/models/my-model.js b/services/production/common/models/my-model.js index 1372fc644f..bfc5cf015d 100644 --- a/services/production/common/models/my-model.js +++ b/services/production/common/models/my-model.js @@ -28,7 +28,7 @@ module.exports = function(self) { }; self.defineScope = function(serverFilter) { - this.remoteMethod('list', { + this.remoteMethodCtx('list', { accepts: [ { arg: 'filter', @@ -46,7 +46,7 @@ module.exports = function(self) { } }); - this.list = function(clientFilter, cb) { + this.list = function(ctx, clientFilter, cb) { var where = {"and": []}; (clientFilter) ? where.and.push(clientFilter.where) : undefined; (serverFilter) ? where.and.push(serverFilter.where) : undefined; diff --git a/services/production/common/models/province.json b/services/production/common/models/province.json new file mode 100644 index 0000000000..b63edbb787 --- /dev/null +++ b/services/production/common/models/province.json @@ -0,0 +1,30 @@ +{ + "name": "Province", + "base": "MyModel", + "validateUpsert": true, + "properties": { + "id": { + "type": "Number", + "id": true, + "description": "Identifier" + }, + "name": { + "type": "string", + "required": true + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + }, + { + "accessType": "WRITE", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "DENY" + } + ] +} \ No newline at end of file diff --git a/services/production/server/model-config.json b/services/production/server/model-config.json index fcb1cb8f74..64efcbc90e 100644 --- a/services/production/server/model-config.json +++ b/services/production/server/model-config.json @@ -61,8 +61,20 @@ "dataSource": "client", "public": true }, + "Client":{ + "dataSource": "client", + "public": true + }, + "Province":{ + "dataSource": "client", + "public": true + }, "Agency": { "dataSource": "vn", "public": true + }, + "FakeProduction": { + "dataSource": "vn", + "public": true } } diff --git a/services/service/models/my-model.js b/services/service/models/my-model.js index 1372fc644f..bfc5cf015d 100644 --- a/services/service/models/my-model.js +++ b/services/service/models/my-model.js @@ -28,7 +28,7 @@ module.exports = function(self) { }; self.defineScope = function(serverFilter) { - this.remoteMethod('list', { + this.remoteMethodCtx('list', { accepts: [ { arg: 'filter', @@ -46,7 +46,7 @@ module.exports = function(self) { } }); - this.list = function(clientFilter, cb) { + this.list = function(ctx, clientFilter, cb) { var where = {"and": []}; (clientFilter) ? where.and.push(clientFilter.where) : undefined; (serverFilter) ? where.and.push(serverFilter.where) : undefined;