Eliminando código redundante v1
This commit is contained in:
parent
e52b31ceb3
commit
08da6c9713
|
@ -42,8 +42,8 @@ gulp.task('services', function() {
|
|||
'auth',
|
||||
'salix',
|
||||
'client',
|
||||
'production',
|
||||
'route'
|
||||
'production'
|
||||
// 'route'
|
||||
];
|
||||
|
||||
for (var service of lbServices)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
module.exports = function(Address) {
|
||||
Address.validate('default',isEnabled,{message: 'No se puede poner predeterminado un consignatario desactivado'});
|
||||
module.exports = function(Self) {
|
||||
Self.validate('default',isEnabled,{message: 'No se puede poner predeterminado un consignatario desactivado'});
|
||||
function isEnabled(err) {
|
||||
if (!this.isEnabled && this.isDefaultAddress) err();
|
||||
}
|
||||
|
||||
Address.beforeRemote('create',function(ctx, modelInstance, next){
|
||||
Self.beforeRemote('create',function(ctx, modelInstance, next){
|
||||
var data = ctx.req.body;
|
||||
create(data, next);
|
||||
});
|
||||
|
@ -17,13 +17,13 @@ module.exports = function(Address) {
|
|||
}
|
||||
}
|
||||
|
||||
Address.beforeRemote('prototype.patchAttributes',function(ctx, modelInstance, next){
|
||||
Self.beforeRemote('prototype.patchAttributes',function(ctx, modelInstance, next){
|
||||
let newData = ctx.req.body;
|
||||
newData.id = ctx.req.params.id;
|
||||
getAddress(ctx, newData, next);
|
||||
});
|
||||
|
||||
Address.beforeRemote('findById', function(ctx, modelInstance, next) {
|
||||
Self.beforeRemote('findById', function(ctx, modelInstance, next) {
|
||||
ctx.args.filter = {
|
||||
"include": {
|
||||
"relation": "province",
|
||||
|
@ -36,7 +36,7 @@ module.exports = function(Address) {
|
|||
});
|
||||
|
||||
function getAddress(ctx, newData, next){
|
||||
Address.findOne( {where: { id: newData.id}}, function (err, oldData){
|
||||
Self.findOne( {where: { id: newData.id}}, function (err, oldData){
|
||||
if(oldData)
|
||||
callbackGetAddress(ctx, newData, oldData, next);
|
||||
});
|
||||
|
@ -60,7 +60,7 @@ module.exports = function(Address) {
|
|||
}
|
||||
|
||||
function removeAllDefault(client, next){
|
||||
Address.updateAll({clientFk: client.id, isDefaultAddress: true}, {isDefaultAddress: false}, next);
|
||||
Self.updateAll({clientFk: client.id, isDefaultAddress: true}, {isDefaultAddress: false}, next);
|
||||
}
|
||||
|
||||
function generateErrorDefaultAddress(){
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "Address",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
|
@ -62,19 +61,5 @@
|
|||
"model": "Agency",
|
||||
"foreignKey": "defaultAgencyFk"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "AgencyService",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
|
@ -36,19 +35,5 @@
|
|||
"model": "AgencyType",
|
||||
"foreignKey": "agencyTypeFk"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "ClientCreditLimit",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
|
@ -18,19 +17,5 @@
|
|||
"model": "Role",
|
||||
"foreignKey": "roleFk"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ClientCredit",
|
||||
"base": "MyModel",
|
||||
"base": "VnModel",
|
||||
"validateUpsert": true,
|
||||
"properties": {
|
||||
"id": {
|
||||
|
@ -26,19 +26,5 @@
|
|||
"model": "Employee",
|
||||
"foreignKey": "employeeFk"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,19 +1,19 @@
|
|||
module.exports = function(ClientObservation) {
|
||||
module.exports = function(Self) {
|
||||
|
||||
let loopBackContext = require('loopback-context');
|
||||
|
||||
ClientObservation.validate('text', isEnabled, {message: 'Se debe rellenar el campo de texto'});
|
||||
Self.validate('text', isEnabled, {message: 'Se debe rellenar el campo de texto'});
|
||||
function isEnabled(err) {
|
||||
if (!this.text) err();
|
||||
}
|
||||
|
||||
ClientObservation.observe('before save', function(ctx, next) {
|
||||
Self.observe('before save', function(ctx, next) {
|
||||
ctx.instance.created = Date();
|
||||
let currentUser = loopBackContext.getCurrentContext();
|
||||
let userId = currentUser.get('currentUser');
|
||||
let app = require('../../server/server');
|
||||
let employee = app.models.Employee;
|
||||
employee.findOne({where: {userFk: userId}}, function (err, user){
|
||||
let Employee = app.models.Employee;
|
||||
Employee.findOne({where: {userFk: userId}}, function (err, user){
|
||||
if (user){
|
||||
ctx.instance.employeeFk = user.id;
|
||||
next();
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
{
|
||||
"name": "ClientObservation",
|
||||
"description": "Notas de los clientes.",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
|
@ -33,20 +32,6 @@
|
|||
"foreignKey": "id"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
],
|
||||
"scope": {
|
||||
"include": "employee"
|
||||
}
|
||||
|
|
|
@ -1,66 +1,66 @@
|
|||
var app = require('../../server/server');
|
||||
|
||||
module.exports = function(Client) {
|
||||
module.exports = function(Self) {
|
||||
var models = app.models;
|
||||
var loopBackContext = require('loopback-context');
|
||||
// Methods
|
||||
|
||||
require('../methods/client/activate.js')(Client);
|
||||
require('../methods/client/addresses.js')(Client);
|
||||
require('../methods/client/before-save.js')(Client);
|
||||
require('../methods/client/card.js')(Client);
|
||||
require('../methods/client/create.js')(Client);
|
||||
require('../methods/client/employee.js')(Client);
|
||||
require('../methods/client/filter.js')(Client);
|
||||
require('../methods/client/roles.js')(Client);
|
||||
require('../methods/client/salesperson.js')(Client);
|
||||
require('../methods/client/addressesPropagateRe.js')(Client);
|
||||
require('../methods/client/activate.js')(Self);
|
||||
require('../methods/client/addresses.js')(Self);
|
||||
require('../methods/client/before-save.js')(Self);
|
||||
require('../methods/client/card.js')(Self);
|
||||
require('../methods/client/create.js')(Self);
|
||||
require('../methods/client/employee.js')(Self);
|
||||
require('../methods/client/filter.js')(Self);
|
||||
require('../methods/client/roles.js')(Self);
|
||||
require('../methods/client/salesperson.js')(Self);
|
||||
require('../methods/client/addressesPropagateRe.js')(Self);
|
||||
|
||||
// Validations
|
||||
|
||||
Client.validatesUniquenessOf('name', {
|
||||
Self.validatesUniquenessOf('name', {
|
||||
message: 'El nombre debe ser único'
|
||||
});
|
||||
Client.validatesUniquenessOf('fi', {
|
||||
Self.validatesUniquenessOf('fi', {
|
||||
message: 'El NIF/CIF debe ser único'
|
||||
});
|
||||
Client.validatesPresenceOf('socialName', {
|
||||
Self.validatesPresenceOf('socialName', {
|
||||
message: 'Debe especificarse la razón social'
|
||||
});
|
||||
Client.validatesUniquenessOf('socialName', {
|
||||
Self.validatesUniquenessOf('socialName', {
|
||||
message: 'La razón social debe ser única'
|
||||
});
|
||||
Client.validatesFormatOf('postcode', {
|
||||
Self.validatesFormatOf('postcode', {
|
||||
message: 'El código postal solo debe contener números',
|
||||
allowNull: true,
|
||||
allowBlank: true,
|
||||
with: /^\d+$/
|
||||
});
|
||||
Client.validatesFormatOf('email', {
|
||||
Self.validatesFormatOf('email', {
|
||||
message: 'Correo electrónico inválido',
|
||||
allowNull: true,
|
||||
allowBlank: true,
|
||||
with: /^[\w|\.|\-]+@\w[\w|\.|\-]*\w(,[\w|\.|\-]+@\w[\w|\.|\-]*\w)*$/
|
||||
});
|
||||
Client.validatesLengthOf('postcode', {
|
||||
Self.validatesLengthOf('postcode', {
|
||||
allowNull: true,
|
||||
allowBlank: true,
|
||||
min: 3, max: 10
|
||||
});
|
||||
|
||||
var validateIban = require('../validations/validateIban');
|
||||
Client.validateBinded('iban',validateIban,{
|
||||
Self.validateBinded('iban',validateIban,{
|
||||
message:'El iban no tiene el formato correcto'
|
||||
});
|
||||
|
||||
Client.validate('payMethod', hasSalesMan, {
|
||||
Self.validate('payMethod', hasSalesMan, {
|
||||
message: 'No se puede cambiar la forma de pago si no hay comercial asignado'
|
||||
});
|
||||
function hasSalesMan(err) {
|
||||
if(this.payMethod && !this.salesPerson)
|
||||
err();
|
||||
}
|
||||
Client.validateAsync('payMethodFk', hasIban, {
|
||||
Self.validateAsync('payMethodFk', hasIban, {
|
||||
message: 'El método de pago seleccionado requiere que se especifique el IBAN'
|
||||
});
|
||||
function hasIban(err, done) {
|
||||
|
@ -71,7 +71,7 @@ module.exports = function(Client) {
|
|||
});
|
||||
}
|
||||
|
||||
Client.validateAsync('credit', validateCredit, {
|
||||
Self.validateAsync('credit', validateCredit, {
|
||||
message: 'No tienes privilegios para modificar el crédito'
|
||||
});
|
||||
function validateCredit(err, done) {
|
||||
|
@ -116,7 +116,7 @@ module.exports = function(Client) {
|
|||
// Si se puso a 0 por gerencia, solo gerencia puede aumentarlo
|
||||
function validate() {
|
||||
let query = 'SELECT * FROM ClientCredit WHERE clientFk = ? ORDER BY created DESC LIMIT 1';
|
||||
Client.dataSource.connector.execute (query, [self.id],
|
||||
Self.dataSource.connector.execute (query, [self.id],
|
||||
(_, res) => maxCb(_, res));
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ module.exports = function(Client) {
|
|||
AND cc.employeeFk = ${instances[0].employeeFk}
|
||||
AND r.\`name\` = 'manager'`;
|
||||
|
||||
Client.dataSource.connector.execute(sql, [], (_, res) => clientCreditCb(_, res));
|
||||
Self.dataSource.connector.execute(sql, [], (_, res) => clientCreditCb(_, res));
|
||||
}
|
||||
|
||||
function clientCreditCb(_, instance) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "Client",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
|
@ -142,21 +141,5 @@
|
|||
"model": "Address",
|
||||
"foreignKey": "clientFk"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
],
|
||||
"validations": [],
|
||||
"methods": {}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "ContactChannel",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
|
@ -12,19 +11,5 @@
|
|||
"type": "string",
|
||||
"required": true
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
{
|
||||
"name": "CreditClassification",
|
||||
"description": "Clientes clasificados.",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
|
@ -22,19 +21,5 @@
|
|||
"model": "Client",
|
||||
"foreignKey": "clientFk"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "PayMethod",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
|
@ -21,19 +20,5 @@
|
|||
"ibanRequired": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,5 +11,10 @@
|
|||
"mysql": "^2.13.0",
|
||||
"nodemailer": "^4.0.1",
|
||||
"path": "^0.12.7"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.verdnatura.es/salix"
|
||||
},
|
||||
"license": "GPL-3.0"
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
module.exports = function(Warehouse) {
|
||||
|
||||
var serverFilter = {"where": {"isManaged": {"neq": 0}}};
|
||||
|
||||
Warehouse.defineScope(serverFilter);
|
||||
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
var app = require('../../server/server');
|
||||
|
||||
module.exports = function(Agency) {
|
||||
require('../methods/agency/list.js')(Agency);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "Agency",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
|
@ -16,19 +15,5 @@
|
|||
"type": "Number",
|
||||
"required": false
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "Client",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
|
@ -12,21 +11,5 @@
|
|||
"type": "string",
|
||||
"required": true
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
],
|
||||
"validations": [],
|
||||
"methods": {}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
{
|
||||
"name": "Employee",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
"id": true,
|
||||
"description": "Identifier"
|
||||
},
|
||||
"name":{
|
||||
"type": "String"
|
||||
},
|
||||
"surname":{
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
"user": {
|
||||
"type": "belongsTo",
|
||||
"model": "Account",
|
||||
"foreignKey": "userFk"
|
||||
}
|
||||
},
|
||||
"acls": [],
|
||||
"include":[
|
||||
{
|
||||
"relation": "user",
|
||||
"scope": {
|
||||
"fields": ["name"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
var app = require('../../server/server');
|
||||
|
||||
module.exports = function(FakeProduction) {
|
||||
require('../methods/fake-production/list.js')(FakeProduction);
|
||||
require('../methods/fake-production/message-send.js')(FakeProduction);
|
||||
require('../methods/fake-production/route.js')(FakeProduction);
|
||||
};
|
||||
module.exports = function(Self) {
|
||||
require('../methods/fake-production/list.js')(Self);
|
||||
require('../methods/fake-production/message-send.js')(Self);
|
||||
require('../methods/fake-production/route.js')(Self);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "FakeProduction",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
|
@ -74,19 +73,5 @@
|
|||
"routeFk":{
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "READ",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "MessageInbox",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
|
@ -26,19 +25,5 @@
|
|||
"sendDate":{
|
||||
"type": "date"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "Message",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
|
@ -23,19 +22,5 @@
|
|||
"sendDate":{
|
||||
"type": "date"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "Route",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
|
@ -12,20 +11,6 @@
|
|||
"type": "date"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
],
|
||||
"validations": [],
|
||||
"methods": {}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
var app = require('../../server/server');
|
||||
|
||||
module.exports = function(State) {
|
||||
require('../methods/state/list.js')(State);
|
||||
};
|
||||
module.exports = function(Self) {
|
||||
require('../methods/state/list.js')(Self);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "State",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
|
@ -24,19 +23,5 @@
|
|||
"type": "String",
|
||||
"required": false
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
var app = require('../../server/server');
|
||||
|
||||
module.exports = function(TicketState) {
|
||||
require('../methods/ticket-state/change-state.js')(TicketState);
|
||||
module.exports = function(Self) {
|
||||
require('../methods/ticket-state/change-state.js')(Self);
|
||||
};
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "TicketState",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
|
@ -29,19 +28,5 @@
|
|||
"model": "Employee",
|
||||
"foreignKey": "employeeFk"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
var app = require('../../server/server');
|
||||
|
||||
module.exports = function(Ticket) {
|
||||
require('../methods/ticket/change-time.js')(Ticket);
|
||||
require('../methods/ticket/change-worker.js')(Ticket);
|
||||
module.exports = function(Self) {
|
||||
require('../methods/ticket/change-time.js')(Self);
|
||||
require('../methods/ticket/change-worker.js')(Self);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "Ticket",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
|
@ -11,19 +10,5 @@
|
|||
"date": {
|
||||
"type": "date"
|
||||
}
|
||||
},
|
||||
"acls": [{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
var app = require('../../server/server');
|
||||
|
||||
module.exports = function(Warehouse) {
|
||||
require('../methods/warehouse/list.js')(Warehouse);
|
||||
};
|
|
@ -59,7 +59,7 @@
|
|||
"public": true
|
||||
},
|
||||
"Employee":{
|
||||
"dataSource": "client",
|
||||
"dataSource": "vn",
|
||||
"public": true
|
||||
},
|
||||
"Client":{
|
||||
|
@ -67,7 +67,7 @@
|
|||
"public": true
|
||||
},
|
||||
"Province":{
|
||||
"dataSource": "client",
|
||||
"dataSource": "vn",
|
||||
"public": true
|
||||
},
|
||||
"Agency": {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(Delivery) {
|
||||
require('../methods/filter.js')(Delivery);
|
||||
};
|
||||
|
||||
module.exports = function(Self) {
|
||||
require('../methods/filter.js')(Self);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "Delivery",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
|
@ -17,21 +16,5 @@
|
|||
"warehouseFk":{
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
],
|
||||
"validations" : [],
|
||||
"methods": {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "Zone",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
|
@ -14,20 +13,6 @@
|
|||
"printingOrder":{
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,30 @@
|
|||
|
||||
module.exports = function(app) {
|
||||
let models = app.models();
|
||||
models.forEach(function(model) {
|
||||
let settings = model.settings;
|
||||
let acls = settings.acls;
|
||||
|
||||
if (!acls)
|
||||
model.settings.acls = acls = [];
|
||||
|
||||
acls.push({
|
||||
accessType: '*',
|
||||
principalType: 'ROLE',
|
||||
principalId: '$everyone',
|
||||
permission: 'DENY'
|
||||
});
|
||||
acls.push({
|
||||
accessType: '*',
|
||||
principalType: 'ROLE',
|
||||
principalId: 'root',
|
||||
permission: 'ALLOW'
|
||||
});
|
||||
|
||||
if (settings.validateUpsert === undefined)
|
||||
settings.validateUpsert = true;
|
||||
});
|
||||
|
||||
app.enableAuth();
|
||||
|
||||
var router = app.loopback.Router();
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function(Self) {
|
||||
Self.defineScope({where: {isManaged: {neq: 0}}});
|
||||
};
|
|
@ -28,19 +28,5 @@
|
|||
"updated": {
|
||||
"type": "date"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Country",
|
||||
"base": "MyModel",
|
||||
"base": "VnModel",
|
||||
"validateUpsert": true,
|
||||
"properties": {
|
||||
"id": {
|
||||
|
@ -37,18 +37,6 @@
|
|||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
},
|
||||
{
|
||||
"accessType": "WRITE",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "Employee",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "Number",
|
||||
|
@ -23,19 +22,5 @@
|
|||
"model": "Account",
|
||||
"foreignKey": "userFk"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Province",
|
||||
"base": "MyModel",
|
||||
"base": "VnModel",
|
||||
"validateUpsert": true,
|
||||
"properties": {
|
||||
"id": {
|
||||
|
@ -36,18 +36,6 @@
|
|||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
},
|
||||
{
|
||||
"accessType": "WRITE",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "DENY"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = function(self) {
|
||||
self.setup = function() {
|
||||
self.super_.setup.call(this);
|
||||
module.exports = function(Self) {
|
||||
Self.setup = function() {
|
||||
Self.super_.setup.call(this);
|
||||
|
||||
let disableMethods = {
|
||||
create: true,
|
||||
|
@ -25,7 +25,7 @@ module.exports = function(self) {
|
|||
}
|
||||
};
|
||||
|
||||
self.defineScope = function(serverFilter) {
|
||||
Self.defineScope = function(serverFilter) {
|
||||
this.remoteMethodCtx('list', {
|
||||
accepts: [
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ module.exports = function(self) {
|
|||
};
|
||||
};
|
||||
|
||||
self.rawSql = function(query, params, cb) {
|
||||
Self.rawSql = function(query, params, cb) {
|
||||
var connector = this.dataSource.connector;
|
||||
return new Promise(function(resolve, reject) {
|
||||
connector.execute(query, params, function(error, response) {
|
||||
|
@ -92,7 +92,7 @@ module.exports = function(self) {
|
|||
});
|
||||
};
|
||||
|
||||
self.remoteMethodCtx = function(methodName, args) {
|
||||
Self.remoteMethodCtx = function(methodName, args) {
|
||||
var ctx = {
|
||||
arg: 'context',
|
||||
type: 'object',
|
||||
|
@ -108,21 +108,21 @@ module.exports = function(self) {
|
|||
this.remoteMethod(methodName, args);
|
||||
};
|
||||
|
||||
self.connectToService = function(ctx, dataSource) {
|
||||
Self.connectToService = function(ctx, dataSource) {
|
||||
this.app.dataSources[dataSource].connector.remotes.auth = {
|
||||
bearer: new Buffer(ctx.req.accessToken.id).toString('base64'),
|
||||
sendImmediately: true
|
||||
};
|
||||
};
|
||||
|
||||
self.disconnectFromService = function(dataSource) {
|
||||
Self.disconnectFromService = function(dataSource) {
|
||||
this.app.dataSources[dataSource].connector.remotes.auth = {
|
||||
bearer: new Buffer("").toString('base64'),
|
||||
sendImmediately: true
|
||||
};
|
||||
};
|
||||
|
||||
self.installMethod = function(methodName, filterCb) {
|
||||
Self.installMethod = function(methodName, filterCb) {
|
||||
this.remoteMethod(methodName, {
|
||||
description: 'List items using a filter',
|
||||
accessType: 'READ',
|
||||
|
@ -180,7 +180,7 @@ module.exports = function(self) {
|
|||
};
|
||||
};
|
||||
|
||||
self.validateBinded = function(propertyName, validatorFn, options) {
|
||||
Self.validateBinded = function(propertyName, validatorFn, options) {
|
||||
var customValidator = function(err) {
|
||||
if (!validatorFn(this[propertyName])) err();
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"name": "MyModel",
|
||||
"name": "VnModel",
|
||||
"base": "PersistedModel"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
module.exports = function(Self) {
|
||||
require('../methods/warehouse/list.js')(Self);
|
||||
};
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"name": "Warehouse",
|
||||
"base": "MyModel",
|
||||
"validateUpsert": true,
|
||||
"base": "VnModel",
|
||||
"properties": {
|
||||
"id": {
|
||||
"id": true,
|
||||
|
@ -24,12 +23,6 @@
|
|||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
},
|
||||
{
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "root",
|
||||
"permission": "ALLOW"
|
||||
}
|
||||
],
|
||||
"scopes" : {
|
Loading…
Reference in New Issue