Fixed locales: client & back-end validations, back-end UserError. #464

This commit is contained in:
Joan Sanchez 2018-08-02 09:49:00 +02:00
parent b6cc14065e
commit ff0f0436af
49 changed files with 7575 additions and 3672 deletions

View File

@ -5,6 +5,11 @@
data="contacts" on-data-change="$ctrl.onDataChange()">
</vn-crud-model>
<vn-watcher
vn-id="watcher"
data="contacts"
form="form">
</vn-watcher>
<form name="form" ng-submit="$ctrl.submit()">
<vn-card pad-large>
<vn-title>Contacts</vn-title>

View File

@ -2,8 +2,8 @@ import ngModule from '../module';
import {validateAll} from '../lib/validator';
import {firstUpper} from '../lib/string';
directive.$inject = ['$interpolate', '$compile', '$window'];
export function directive(interpolate, compile, $window) {
directive.$inject = ['$interpolate', '$compile', '$translate', '$window'];
export function directive(interpolate, compile, $translate, $window) {
return {
restrict: 'A',
require: ['ngModel', '^^?form'],
@ -41,7 +41,7 @@ export function directive(interpolate, compile, $window) {
ngModel.$options.$$options.allowInvalid = true;
ngModel.$validators.entity = value => {
try {
validateAll(value, validations);
validateAll($translate, value, validations);
return true;
} catch (e) {
errorMsg = e.message;

View File

@ -1,8 +1,8 @@
import ngModule from '../module';
import HttpError from './http-error';
interceptor.$inject = ['$q', 'vnApp', '$cookies'];
function interceptor($q, vnApp, $cookies) {
interceptor.$inject = ['$q', 'vnApp', '$cookies', '$translate'];
function interceptor($q, vnApp, $cookies, $translate) {
return {
request: function(config) {
vnApp.pushLoader();
@ -11,6 +11,9 @@ function interceptor($q, vnApp, $cookies) {
if (token)
config.headers.Authorization = token;
if ($translate.use())
config.headers['Accept-Language'] = $translate.use();
return config;
},
requestError: function(rejection) {

View File

@ -1,15 +1,15 @@
import {validator} from 'vendor';
export const validators = {
presence: value => {
presence: ($translate, value) => {
if (validator.isEmpty(value ? String(value) : ''))
throw new Error(`Value can't be empty`);
throw new Error(_($translate, `Value can't be empty`));
},
absence: value => {
absence: ($translate, value) => {
if (!validator.isEmpty(value))
throw new Error(`Value should be empty`);
throw new Error(_($translate, `Value should be empty`));
},
length: (value, conf) => {
length: ($translate, value, conf) => {
let options = {
min: conf.min || conf.is,
max: conf.max || conf.is
@ -17,38 +17,42 @@ export const validators = {
let val = value ? String(value) : '';
if (!validator.isLength(val, options)) {
if (conf.is) {
throw new Error(`Value should be ${conf.is} characters long`);
throw new Error(_($translate,
`Value should be %s characters long`, [conf.is]));
} else if (conf.min && conf.max) {
throw new Error(`Value should have a length between ${conf.min} and ${conf.max}`);
throw new Error(_($translate,
`Value should have a length between %s and %s`, [conf.min, conf.max]));
} else if (conf.min) {
throw new Error(`Value should have at least ${conf.min} characters`);
throw new Error(_($translate,
`Value should have at least %s characters`, [conf.min]));
} else {
throw new Error(`Value should have at most ${conf.max} characters`);
throw new Error(_($translate,
`Value should have at most %s characters`, [conf.max]));
}
}
},
numericality: (value, conf) => {
numericality: ($translate, value, conf) => {
if (conf.int) {
if (!validator.isInt(value))
throw new Error(`Value should be integer`);
throw new Error(_($translate, `Value should be integer`));
} else if (!validator.isNumeric(value))
throw new Error(`Value should be a number`);
throw new Error(_($translate, `Value should be a number`));
},
inclusion: (value, conf) => {
inclusion: ($translate, value, conf) => {
if (!validator.isIn(value, conf.in))
throw new Error(`Invalid value`);
throw new Error(_($translate, `Invalid value`));
},
exclusion: (value, conf) => {
exclusion: ($translate, value, conf) => {
if (validator.isIn(value, conf.in))
throw new Error(`Invalid value`);
throw new Error(_($translate, `Invalid value`));
},
format: (value, conf) => {
format: ($translate, value, conf) => {
if (!validator.matches(value, conf.with))
throw new Error(`Invalid value`);
throw new Error(_($translate, `Invalid value`));
},
custom: (value, conf) => {
custom: ($translate, value, conf) => {
if (!conf.bindedFunction(value))
throw new Error(`Invalid value`);
throw new Error(_($translate, `Invalid value`));
}
};
@ -58,9 +62,9 @@ export const validators = {
* @param {*} value The value
* @param {Array} validations Array with validations
*/
export function validateAll(value, validations) {
export function validateAll($translate, value, validations) {
for (let conf of validations)
validate(value, conf);
validate($translate, value, conf);
}
/**
@ -69,18 +73,18 @@ export function validateAll(value, validations) {
* @param {*} value The value
* @param {Object} conf The validation configuration
*/
export function validate(value, conf) {
export function validate($translate, value, conf) {
let validator = validators[conf.validation];
try {
let isEmpty = value == null || value === '';
if (isEmpty)
checkNull(value, conf);
checkNull($translate, value, conf);
if (validator && (!isEmpty || conf.validation == 'presence'))
validator(value, conf);
validator($translate, value, conf);
} catch (e) {
let message = conf.message ? conf.message : e.message;
throw new Error(message);
throw new Error(_($translate, message));
}
}
@ -90,9 +94,19 @@ export function validate(value, conf) {
* @param {*} value The value
* @param {Object} conf The validation configuration
*/
export function checkNull(value, conf) {
export function checkNull($translate, value, conf) {
if (conf.allowBlank === false && value === '')
throw new Error(`Value can't be blank`);
throw new Error(_($translate, `Value can't be blank`));
else if (conf.allowNull === false && value == null)
throw new Error(`Value can't be null`);
throw new Error(_($translate, `Value can't be null`));
}
export function _($translate, text, params = []) {
text = $translate.instant(text);
for (let i = 0; i < params.length; i++) {
text = text.replace('%s', params[i]);
}
return text;
}

View File

@ -12,4 +12,15 @@ Next: Siguiente
Finalize: Finalizar
Previous: Anterior
Load more: Cargar más
Auto-scroll interrupted, please adjust the search: Auto-scroll interrumpido, por favor ajusta la búsqueda
Auto-scroll interrupted, please adjust the search: Auto-scroll interrumpido, por favor ajusta la búsqueda
Value can't be empty: El valor no puede estar vacío
Value should be empty: El valor debe estar vacío
Value should be integer: El valor debe ser entero
Value should be a number: El valor debe ser numérico
Invalid value: Valor incorrecto
Value can't be blank: El valor no puede estar en blanco
Value can't be null: El valor no puede ser nulo
Value should be %s characters long: El valor debe ser de %s carácteres de longitud
Value should have a length between %s and %s: El valor debe tener una longitud de entre %s y %s
Value should have at least %s characters: El valor debe tener al menos %s carácteres
Value should have at most %s characters: El valor debe tener un máximo de %s carácteres

View File

@ -70,6 +70,7 @@ describe('Client', () => {
it(`should create a new greuge with all its data`, () => {
return nightmare
.type(selectors.clientGreuge.amountInput, 999)
.waitForTextInInput(selectors.clientGreuge.amountInput, '999')
.type(selectors.clientGreuge.descriptionInput, 'new armor for Batman!')
.click(selectors.clientGreuge.saveButton)
.waitForSnackbar()

7184
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,8 @@
"posttest": "npm run lint && nsp check"
},
"dependencies": {
"md5": "^2.2.1"
"md5": "^2.2.1",
"vn-loopback": "file:../loopback"
},
"repository": {
"type": "git",

View File

@ -1,5 +1,5 @@
var vnLoopback = require('../../loopback/server/server.js');
var vnLoopback = require('vn-loopback/server/server.js');
var app = module.exports = vnLoopback.loopback();
app.set('applications', require('./application.json'));

View File

@ -7,6 +7,9 @@
"start": "node .",
"posttest": "npm run lint && nsp check"
},
"dependencies": {
"vn-loopback": "file:../loopback"
},
"repository": {
"type": "git",
"url": "https://git.verdnatura.es/salix"

View File

@ -1,5 +1,5 @@
var vnLoopback = require('../../loopback/server/server.js');
var vnLoopback = require('vn-loopback/server/server.js');
var app = module.exports = vnLoopback.loopback();
vnLoopback.boot(app, __dirname, module);

View File

@ -1,5 +1,5 @@
module.exports = function(Self) {
Self.validate('text', isEnabled, {message: 'Se debe rellenar el campo de texto'});
Self.validate('text', isEnabled, {message: 'Description cannot be blank'});
function isEnabled(err) {
if (!this.text) err();
}

View File

@ -1,3 +1,5 @@
const UserError = require('vn-loopback/common/helpers').UserError;
module.exports = Self => {
Self.validatesPresenceOf('typeFk', {
message: 'Sample type cannot be blank'
@ -10,7 +12,7 @@ module.exports = Self => {
let sample = await models.Sample.findById(data.typeFk);
if (sample.hasCompany && !data.companyFk)
throw new Error('Choose a company');
throw new UserError('Choose a company');
let filter = {where: {userFk: ctx.options.accessToken.userId}};
let worker = await Self.app.models.Worker.findOne(filter);

View File

@ -20,7 +20,7 @@ module.exports = function(Self) {
async function validateNullGrade(err, done) {
let filter = {
fields: ['grade'],
fields: ['grade'],
where: {
creditClassification: this.creditClassification
},

View File

@ -3,6 +3,6 @@ module.exports = function(Self) {
Self.validatesLengthOf('description', {
max: 45,
message: 'La description debe tener maximo 45 caracteres'
message: 'Description should have maximum of 45 characters'
});
};

3792
services/client/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,7 @@
"url": "https://git.verdnatura.es/salix"
},
"dependencies": {
"request": "^2.83.0"
"request": "^2.83.0",
"vn-loopback": "file:../loopback"
}
}

View File

@ -1,5 +1,5 @@
var vnLoopback = require('../../loopback/server/server.js');
var vnLoopback = require('vn-loopback/server/server.js');
var app = module.exports = vnLoopback.loopback();
vnLoopback.boot(app, __dirname, module);

13
services/item/package-lock.json generated Normal file
View File

@ -0,0 +1,13 @@
{
"name": "vn-item",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"uuid": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz",
"integrity": "sha512-jZnMwlb9Iku/O3smGWvZhauCf6cvvpKi4BKRiliS3cxnI+Gz9j5MEpTz2UFuXiKPJocb7gnsLHwiS05ige5BEA=="
}
}
}

View File

@ -14,6 +14,7 @@
"license": "GPL-3.0",
"description": "vn-item",
"dependencies": {
"uuid": "^3.1.0"
"uuid": "^3.1.0",
"vn-loopback": "file:../loopback"
}
}

View File

@ -1,4 +1,4 @@
var vnLoopback = require('../../loopback/server/server.js');
var vnLoopback = require('vn-loopback/server/server.js');
var app = module.exports = vnLoopback.loopback();
vnLoopback.boot(app, __dirname, module);

View File

@ -2,6 +2,7 @@
exports.UserError = class extends Error {
constructor(message) {
super(message);
this.name = 'UserError';
this.statusCode = 400;
}
};

View File

@ -23,5 +23,11 @@
"Phone cannot be blank": "Phone cannot be blank",
"Observation type cannot be blank": "Observation type cannot be blank",
"NO_AGENCY_AVAILABLE": "NO_AGENCY_AVAILABLE",
"can't be blank": "can't be blank"
"can't be blank": "can't be blank",
"Cannot be blank": "Cannot be blank",
"Description should have maximum of 45 characters": "Description should have maximum of 45 characters",
"Period cannot be blank": "Period cannot be blank",
"The credit must be an integer greater than or equal to zero": "The credit must be an integer greater than or equal to zero",
"The grade must be an integer greater than or equal to zero": "The grade must be an integer greater than or equal to zero",
"Sample type cannot be blank": "Sample type cannot be blank"
}

View File

@ -28,5 +28,12 @@
"Name cannot be blank": "El nombre no puede estar en blanco",
"Phone cannot be blank": "El teléfono no puede estar en blanco",
"Period cannot be blank": "El periodo no puede estar en blanco",
"Choose a company": "Selecciona una empresa"
"Choose a company": "Selecciona una empresa",
"Se debe rellenar el campo de texto": "Se debe rellenar el campo de texto",
"Description should have maximum of 45 characters": "La descripción debe tener maximo 45 caracteres",
"Cannot be blank": "Cannot be blank",
"The grade must be an integer greater than or equal to zero": "El grade debe ser un entero mayor o igual a cero",
"Sample type cannot be blank": "El tipo de plantilla no puede quedar en blanco",
"Description cannot be blank": "Se debe rellenar el campo de texto",
"You can't create an order for a frozen client": "You can't create an order for a frozen client"
}

View File

@ -1,3 +1,5 @@
let UserError = require('../../helpers').UserError;
module.exports = Self => {
Self.remoteMethod('updateBasicData', {
description: 'Updates billing data of a client',
@ -30,7 +32,7 @@ module.exports = Self => {
let validUpdateParams = ['id', 'contact', 'name', 'email', 'phone', 'mobile', 'salesPersonFk', 'contactChannelFk'];
for (const key in params) {
if (validUpdateParams.indexOf(key) === -1)
throw new Error(`You don't have enough privileges to do that`);
throw new UserError(`You don't have enough privileges to do that`);
}
return await Self.app.models.Client.update({id: id}, params);

View File

@ -1,3 +1,5 @@
let UserError = require('../../helpers').UserError;
module.exports = Self => {
Self.remoteMethodCtx('updateBillingData', {
description: 'Updates billing data of a client',
@ -32,7 +34,7 @@ module.exports = Self => {
let [taxData] = await Self.app.models.Client.find({where: {id: id}, fields: ['isTaxDataChecked']});
if (!isAdministrative && taxData.isTaxDataChecked)
throw new Error(`You don't have enough privileges to do that`);
throw new UserError(`You don't have enough privileges to do that`);
let validUpdateParams = [
'payMethodFk',
@ -45,7 +47,7 @@ module.exports = Self => {
for (const key in params) {
if (validUpdateParams.indexOf(key) === -1)
throw new Error(`You don't have enough privileges to do that`);
throw new UserError(`You don't have enough privileges to do that`);
}
return await Self.app.models.Client.update({id: id}, params);

View File

@ -1,3 +1,5 @@
let UserError = require('../../helpers').UserError;
module.exports = Self => {
Self.remoteMethodCtx('updateFiscalData', {
description: 'Updates billing data of a client',
@ -32,7 +34,7 @@ module.exports = Self => {
let [taxData] = await Self.app.models.Client.find({where: {id: id}, fields: ['isTaxDataChecked']});
if (!isAdministrative && taxData.isTaxDataChecked)
throw new Error(`You don't have enough privileges to do that`);
throw new UserError(`You don't have enough privileges to do that`);
let validUpdateParams = [
'id',
@ -56,7 +58,7 @@ module.exports = Self => {
for (const key in params) {
if (validUpdateParams.indexOf(key) === -1)
throw new Error(`You don't have enough privileges to do that`);
throw new UserError(`You don't have enough privileges to do that`);
}
params.id = id;

View File

@ -1,3 +1,5 @@
let UserError = require('../../helpers').UserError;
module.exports = Self => {
Self.remoteMethod('updateTaxes', {
description: 'Updates the item taxes',
@ -29,7 +31,7 @@ module.exports = Self => {
let promises = [];
for (let tax of taxes) {
if (!tax.taxClassFk)
throw new Error('Tax class cannot be blank');
throw new UserError('Tax class cannot be blank');
promises.push(Self.app.models.ItemTaxCountry.updateAll(
{id: tax.id},

View File

@ -1,3 +1,5 @@
let UserError = require('../../helpers').UserError;
module.exports = Self => {
Self.remoteMethodCtx('moveToNewTicket', {
description: 'Change the state of a ticket',
@ -30,7 +32,7 @@ module.exports = Self => {
let model = Self.app.models;
let thisTicketIsEditable = await model.Ticket.isEditable(params.ticket.oldTicketFk);
if (!thisTicketIsEditable)
throw new Error(`The sales of this ticket can't be modified`);
throw new UserError(`The sales of this ticket can't be modified`);
let travelDates = await model.Agency.getFirstShipped(params.ticket);
let shipped = new Date(travelDates.vShipped);

View File

@ -1,3 +1,5 @@
let UserError = require('../../helpers').UserError;
module.exports = Self => {
Self.remoteMethod('moveToTicket', {
description: 'Change the state of a ticket',
@ -22,11 +24,11 @@ module.exports = Self => {
Self.moveToTicket = async params => {
let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.actualTicketFk);
if (!thisTicketIsEditable)
throw new Error(`The sales of this ticket can't be modified`);
throw new UserError(`The sales of this ticket can't be modified`);
let newTicketIsEditable = await Self.app.models.Ticket.isEditable(params.newTicketFk);
if (!newTicketIsEditable)
throw new Error(`The sales of that ticket can't be modified`);
throw new UserError(`The sales of that ticket can't be modified`);
for (let i = 0; i < params.sales.length; i++) {
await Self.app.models.Sale.update({id: params.sales[i].id}, {ticketFk: params.newTicketFk});

View File

@ -1,3 +1,5 @@
let UserError = require('../../helpers').UserError;
module.exports = Self => {
Self.remoteMethod('removes', {
description: 'Change the state of a ticket',
@ -22,7 +24,7 @@ module.exports = Self => {
Self.removes = async params => {
let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.actualTicketFk);
if (!thisTicketIsEditable)
throw new Error(`The sales of this ticket can't be modified`);
throw new UserError(`The sales of this ticket can't be modified`);
for (let i = 0; i < params.sales.length; i++) {
await Self.app.models.Sale.destroyById(params.sales[i].id);

View File

@ -1,4 +1,6 @@
let UserError = require('../../helpers').UserError;
module.exports = Self => {
Self.remoteMethod('reserve', {
description: 'Change the state of a ticket',
@ -23,7 +25,7 @@ module.exports = Self => {
Self.reserve = async params => {
let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.actualTicketFk);
if (!thisTicketIsEditable)
throw new Error(`The sales of this ticket can't be modified`);
throw new UserError(`The sales of this ticket can't be modified`);
for (let i = 0; i < params.sales.length; i++) {
await Self.app.models.Sale.update({id: params.sales[i].id}, {reserved: params.reserved});

View File

@ -1,3 +1,5 @@
let UserError = require('../../helpers').UserError;
module.exports = Self => {
Self.remoteMethod('updateDiscount', {
description: 'Changes the discount of a sale',
@ -21,13 +23,13 @@ module.exports = Self => {
Self.updateDiscount = async params => {
if (isNaN(params.editLines[0].discount))
throw new Error(`The value should be a number`);
throw new UserError(`The value should be a number`);
let model = Self.app.models;
let thisTicketIsEditable = await model.Ticket.isEditable(params.editLines[0].ticketFk);
if (!thisTicketIsEditable)
throw new Error(`The sales of this ticket can't be modified`);
throw new UserError(`The sales of this ticket can't be modified`);
let ticket = await model.Ticket.find({
where: {

View File

@ -1,3 +1,5 @@
let UserError = require('../../helpers').UserError;
module.exports = Self => {
Self.remoteMethod('updatePrice', {
description: 'Changes the discount of a sale',
@ -21,13 +23,13 @@ module.exports = Self => {
Self.updatePrice = async params => {
if (isNaN(params.price))
throw new Error(`The value should be a number`);
throw new UserError(`The value should be a number`);
if (!params.price) params.price = 0;
let model = Self.app.models;
let thisTicketIsEditable = await model.Ticket.isEditable(params.ticketFk);
if (!thisTicketIsEditable)
throw new Error(`The sales of this ticket can't be modified`);
throw new UserError(`The sales of this ticket can't be modified`);
let ticket = await model.Ticket.find({
where: {

View File

@ -1,3 +1,5 @@
let UserError = require('../../helpers').UserError;
module.exports = Self => {
Self.remoteMethod('updateQuantity', {
description: 'Changes the quantity of a sale',
@ -26,11 +28,11 @@ module.exports = Self => {
Self.updateQuantity = async(id, quantity) => {
if (isNaN(quantity))
throw new Error(`The value should be a number`);
throw new UserError(`The value should be a number`);
let currentLine = await Self.app.models.Sale.findOne({where: {id: id}, fields: ['quantity']});
if (quantity > currentLine.quantity)
throw new Error('The new quantity should be smaller than the old one');
throw new UserError('The new quantity should be smaller than the old one');
return await Self.app.models.Sale.update({id: id}, {quantity: quantity});
};

View File

@ -1,3 +1,5 @@
let UserError = require('../../helpers').UserError;
module.exports = Self => {
Self.remoteMethod('new', {
description: 'Create a newticket and returns the new ID',
@ -22,7 +24,7 @@ module.exports = Self => {
Self.new = async params => {
let existsAddress = await Self.app.models.Address.findOne({where: {id: params.addressFk, clientFk: params.clientFk}});
if (!existsAddress)
throw new Error(`This address doesn't exist`);
throw new UserError(`This address doesn't exist`);
let query = `CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @pe);
SELECT @pe newTicketId;`;

View File

@ -40,7 +40,12 @@ module.exports = function(app) {
(validation.validation == 'custom' && !validation.isExportable))
continue;
jsonField.push(toJson(validation));
let validationCp = Object.assign({}, validation);
if (validationCp.message)
validationCp.message = req.__(validationCp.message);
jsonField.push(toJson(validationCp));
}
jsonValidations[fieldName] = jsonField;

View File

@ -1,3 +1,5 @@
const UserError = require('vn-loopback/common/helpers').UserError;
module.exports = Self => {
Self.remoteMethod('new', {
description: 'Create a new order and returns the new ID',
@ -26,18 +28,18 @@ module.exports = Self => {
});
if (client.isFreezed)
throw new Error(`You can't create an order for a frozen client`);
throw new UserError(`You can't create an order for a frozen client`);
if (!client.isActive)
throw new Error(`You can't create an order for a inactive client`);
throw new UserError(`You can't create an order for a inactive client`);
if (!client.isTaxDataChecked)
throw new Error(`You can't create an order for a client that doesn't has tax data verified`);
throw new UserError(`You can't create an order for a client that doesn't has tax data verified`);
let query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`;
let clientDebt = await Self.rawSql(query, [cli.clientFk]);
if (clientDebt[0].debt > 0)
throw new Error(`You can't create an order for a client that has a debt`);
throw new UserError(`You can't create an order for a client that has a debt`);
query = `CALL vn.orderListCreate(?, ?, ?, ?);`;
[result] = await Self.rawSql(query, [

View File

@ -14,6 +14,7 @@
"license": "GPL-3.0",
"description": "vn-order",
"dependencies": {
"uuid": "^3.1.0"
"uuid": "^3.1.0",
"vn-loopback": "file:../loopback"
}
}

View File

@ -1,4 +1,4 @@
var vnLoopback = require('../../loopback/server/server.js');
var vnLoopback = require('vn-loopback/server/server.js');
var app = module.exports = vnLoopback.loopback();
vnLoopback.boot(app, __dirname, module);

View File

@ -14,6 +14,7 @@
"license": "GPL-3.0",
"description": "vn-production",
"dependencies": {
"uuid": "^3.1.0"
"uuid": "^3.1.0",
"vn-loopback": "file:../loopback"
}
}

View File

@ -1,4 +1,4 @@
var vnLoopback = require('../../loopback/server/server.js');
var vnLoopback = require('vn-loopback/server/server.js');
var app = module.exports = vnLoopback.loopback();
vnLoopback.boot(app, __dirname, module);

View File

@ -7,6 +7,9 @@
"start": "node .",
"posttest": "npm run lint && nsp check"
},
"dependencies": {
"vn-loopback": "file:../loopback"
},
"repository": {
"type": "git",
"url": "https://git.verdnatura.es/salix"

View File

@ -1,5 +1,5 @@
var vnLoopback = require('../../loopback/server/server.js');
var vnLoopback = require('vn-loopback/server/server.js');
var app = module.exports = vnLoopback.loopback();
vnLoopback.boot(app, __dirname, module);

View File

@ -8,7 +8,8 @@
"posttest": "npm run lint && nsp check"
},
"dependencies": {
"cookie-parser": "^1.4.3"
"cookie-parser": "^1.4.3",
"vn-loopback": "file:../loopback"
},
"repository": {
"type": "git",

View File

@ -1,6 +1,6 @@
var cookieParser = require('cookie-parser');
var vnLoopback = require('../../loopback/server/server.js');
var vnLoopback = require('vn-loopback/server/server.js');
var app = module.exports = vnLoopback.loopback();

View File

@ -1,3 +1,5 @@
const UserError = require('vn-loopback/common/helpers').UserError;
module.exports = Self => {
Self.remoteMethod('changeState', {
description: 'Change the state of a ticket',
@ -24,6 +26,6 @@ module.exports = Self => {
if (isEditable)
return await Self.app.models.TicketTracking.create(params);
throw new Error(`You don't have enough privileges to change the state of this ticket`);
throw new UserError(`You don't have enough privileges to change the state of this ticket`);
};
};

View File

@ -7,6 +7,9 @@
"start": "node .",
"posttest": "npm run lint && nsp check"
},
"dependencies": {
"vn-loopback": "file:../loopback"
},
"repository": {
"type": "git",
"url": "https://git.verdnatura.es/salix"

View File

@ -1,5 +1,5 @@
var vnLoopback = require('../../loopback/server/server.js');
var vnLoopback = require('vn-loopback/server/server.js');
var app = module.exports = vnLoopback.loopback();
vnLoopback.boot(app, __dirname, module);