#2687 - Travel CloneWithEntries #1887
|
@ -3,7 +3,7 @@
|
||||||
// Carácter predeterminado de final de línea.
|
// Carácter predeterminado de final de línea.
|
||||||
"files.eol": "\n",
|
"files.eol": "\n",
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll.eslint": true
|
"source.fixAll.eslint": "explicit"
|
||||||
},
|
},
|
||||||
"search.useIgnoreFiles": false,
|
"search.useIgnoreFiles": false,
|
||||||
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
|
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
|
||||||
|
|
13
CHANGELOG.md
13
CHANGELOG.md
|
@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [2352.01] - 2023-12-28
|
## [2402.01] - 2024-01-11
|
||||||
|
|
||||||
|
### Added
|
||||||
|
### Changed
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
## [2400.01] - 2024-01-04
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
### Changed
|
### Changed
|
||||||
|
@ -13,9 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [2350.01] - 2023-12-14
|
## [2350.01] - 2023-12-14
|
||||||
|
|
||||||
### Added
|
### Características Añadidas 🆕
|
||||||
### Changed
|
- **Tickets → Expediciones:** Añadido soporte para Viaexpress
|
||||||
### Fixed
|
|
||||||
|
|
||||||
|
|
||||||
## [2348.01] - 2023-11-30
|
## [2348.01] - 2023-11-30
|
||||||
|
|
|
@ -22,8 +22,8 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.removeFile = async(ctx, id, options) => {
|
Self.removeFile = async(ctx, id, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
let tx;
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
|
@ -24,15 +24,40 @@ describe('docuware upload()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should try upload file', async() => {
|
it('should try upload file', async() => {
|
||||||
|
const tx = await models.Docuware.beginTransaction({});
|
||||||
spyOn(ticketModel, 'deliveryNotePdf').and.returnValue(new Promise(resolve => resolve({})));
|
spyOn(ticketModel, 'deliveryNotePdf').and.returnValue(new Promise(resolve => resolve({})));
|
||||||
|
|
||||||
let error;
|
let error;
|
||||||
try {
|
try {
|
||||||
await models.Docuware.upload(ctx, ticketIds, fileCabinetName);
|
const options = {transaction: tx};
|
||||||
|
const user = await models.UserConfig.findById(userId, null, options);
|
||||||
|
await user.updateAttribute('tabletFk', 'Tablet1', options);
|
||||||
|
await models.Docuware.upload(ctx, ticketIds, fileCabinetName, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e.message;
|
error = e;
|
||||||
|
await tx.rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error).toEqual('Action not allowed on the test environment');
|
expect(error.message).toEqual('Action not allowed on the test environment');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw error when not have tablet assigned', async() => {
|
||||||
|
const tx = await models.Docuware.beginTransaction({});
|
||||||
|
spyOn(ticketModel, 'deliveryNotePdf').and.returnValue(new Promise(resolve => resolve({})));
|
||||||
|
|
||||||
|
let error;
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
await models.Docuware.upload(ctx, ticketIds, fileCabinetName, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
await tx.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.message).toEqual('This user does not have an assigned tablet');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,12 +29,24 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.upload = async function(ctx, ticketIds, fileCabinet) {
|
Self.upload = async function(ctx, ticketIds, fileCabinet, options) {
|
||||||
delete ctx.args.ticketIds;
|
delete ctx.args.ticketIds;
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const action = 'store';
|
const action = 'store';
|
||||||
|
|
||||||
const options = await Self.getOptions();
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const userConfig = await models.UserConfig.findById(ctx.req.accessToken.userId, {
|
||||||
|
fields: ['tabletFk']
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
if (!userConfig?.tabletFk)
|
||||||
|
throw new UserError('This user does not have an assigned tablet');
|
||||||
|
|
||||||
|
const docuwareOptions = await Self.getOptions();
|
||||||
const fileCabinetId = await Self.getFileCabinet(fileCabinet);
|
const fileCabinetId = await Self.getFileCabinet(fileCabinet);
|
||||||
const dialogId = await Self.getDialog(fileCabinet, action, fileCabinetId);
|
const dialogId = await Self.getDialog(fileCabinet, action, fileCabinetId);
|
||||||
|
|
||||||
|
@ -45,7 +57,7 @@ module.exports = Self => {
|
||||||
const deliveryNote = await models.Ticket.deliveryNotePdf(ctx, {
|
const deliveryNote = await models.Ticket.deliveryNotePdf(ctx, {
|
||||||
id,
|
id,
|
||||||
type: 'deliveryNote'
|
type: 'deliveryNote'
|
||||||
});
|
}, myOptions);
|
||||||
// get ticket data
|
// get ticket data
|
||||||
const ticket = await models.Ticket.findById(id, {
|
const ticket = await models.Ticket.findById(id, {
|
||||||
include: [{
|
include: [{
|
||||||
|
@ -54,7 +66,7 @@ module.exports = Self => {
|
||||||
fields: ['id', 'name', 'fi']
|
fields: ['id', 'name', 'fi']
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
});
|
}, myOptions);
|
||||||
|
|
||||||
// upload file
|
// upload file
|
||||||
const templateJson = {
|
const templateJson = {
|
||||||
|
@ -102,7 +114,7 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
'FieldName': 'FILTRO_TABLET',
|
'FieldName': 'FILTRO_TABLET',
|
||||||
'ItemElementName': 'string',
|
'ItemElementName': 'string',
|
||||||
'Item': 'Tablet1',
|
'Item': userConfig.tabletFk,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
@ -116,11 +128,11 @@ module.exports = Self => {
|
||||||
const deleteJson = {
|
const deleteJson = {
|
||||||
'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}]
|
'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}]
|
||||||
};
|
};
|
||||||
const deleteUri = `${options.url}/FileCabinets/${fileCabinetId}/Documents/${docuwareFile.id}/Fields`;
|
const deleteUri = `${docuwareOptions.url}/FileCabinets/${fileCabinetId}/Documents/${docuwareFile.id}/Fields`;
|
||||||
await axios.put(deleteUri, deleteJson, options.headers);
|
await axios.put(deleteUri, deleteJson, docuwareOptions.headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uploadUri = `${options.url}/FileCabinets/${fileCabinetId}/Documents?StoreDialogId=${dialogId}`;
|
const uploadUri = `${docuwareOptions.url}/FileCabinets/${fileCabinetId}/Documents?StoreDialogId=${dialogId}`;
|
||||||
const FormData = require('form-data');
|
const FormData = require('form-data');
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
|
|
||||||
|
@ -130,7 +142,7 @@ module.exports = Self => {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data',
|
'Content-Type': 'multipart/form-data',
|
||||||
'X-File-ModifiedDate': Date.vnNew(),
|
'X-File-ModifiedDate': Date.vnNew(),
|
||||||
'Cookie': options.headers.headers.Cookie,
|
'Cookie': docuwareOptions.headers.headers.Cookie,
|
||||||
...data.getHeaders()
|
...data.getHeaders()
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -141,11 +153,11 @@ module.exports = Self => {
|
||||||
const $t = ctx.req.__;
|
const $t = ctx.req.__;
|
||||||
const message = $t('Failed to upload delivery note', {id});
|
const message = $t('Failed to upload delivery note', {id});
|
||||||
if (uploaded.length)
|
if (uploaded.length)
|
||||||
await models.TicketTracking.setDelivered(ctx, uploaded);
|
await models.TicketTracking.setDelivered(ctx, uploaded, myOptions);
|
||||||
throw new UserError(message);
|
throw new UserError(message);
|
||||||
}
|
}
|
||||||
uploaded.push(id);
|
uploaded.push(id);
|
||||||
}
|
}
|
||||||
return models.TicketTracking.setDelivered(ctx, ticketIds);
|
return models.TicketTracking.setDelivered(ctx, ticketIds, myOptions);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
const handlePromiseLogout = (Self, {id}, courtesyTime) => {
|
||||||
|
new Promise(res => {
|
||||||
|
setTimeout(() => {
|
||||||
|
res(Self.logout(id));
|
||||||
|
}
|
||||||
|
, courtesyTime * 1000);
|
||||||
|
});
|
||||||
|
};
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('renewToken', {
|
Self.remoteMethodCtx('renewToken', {
|
||||||
description: 'Checks if the token has more than renewPeriod seconds to live and if so, renews it',
|
description: 'Checks if the token has more than renewPeriod seconds to live and if so, renews it',
|
||||||
|
@ -16,23 +25,32 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.renewToken = async function(ctx) {
|
Self.renewToken = async function(ctx) {
|
||||||
const models = Self.app.models;
|
const {accessToken: token} = ctx.req;
|
||||||
const token = ctx.req.accessToken;
|
|
||||||
|
|
||||||
const now = new Date();
|
// Check if current token is valid
|
||||||
const differenceMilliseconds = now - token.created;
|
const isValid = await validateToken(token);
|
||||||
const differenceSeconds = Math.floor(differenceMilliseconds / 1000);
|
if (isValid)
|
||||||
|
return token;
|
||||||
|
|
||||||
const fields = ['renewPeriod', 'courtesyTime'];
|
const {courtesyTime} = await models.AccessTokenConfig.findOne({fields: ['courtesyTime']});
|
||||||
const accessTokenConfig = await models.AccessTokenConfig.findOne({fields});
|
|
||||||
|
|
||||||
if (differenceSeconds < accessTokenConfig.renewPeriod - accessTokenConfig.courtesyTime)
|
// Schedule to remove current token
|
||||||
throw new UserError(`The renew period has not been exceeded`, 'periodNotExceeded');
|
handlePromiseLogout(Self, token, courtesyTime);
|
||||||
|
|
||||||
await Self.logout(token.id);
|
// Create new accessToken
|
||||||
const user = await Self.findById(token.userId);
|
const user = await Self.findById(token.userId);
|
||||||
const accessToken = await user.createAccessToken();
|
const accessToken = await user.createAccessToken();
|
||||||
|
|
||||||
return {id: accessToken.id, ttl: accessToken.ttl};
|
return {id: accessToken.id, ttl: accessToken.ttl};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function validateToken(token) {
|
||||||
|
const accessTokenConfig = await models.AccessTokenConfig.findOne({fields: ['renewPeriod', 'courtesyTime']});
|
||||||
|
const now = Date.now();
|
||||||
|
const differenceMilliseconds = now - token.created;
|
||||||
|
const differenceSeconds = Math.floor(differenceMilliseconds / 1000);
|
||||||
|
const isValid = differenceSeconds < accessTokenConfig.renewPeriod - accessTokenConfig.courtesyTime;
|
||||||
|
|
||||||
|
return isValid;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
describe('Renew Token', () => {
|
||||||
|
const startingTime = Date.now();
|
||||||
|
let ctx = null;
|
||||||
|
beforeAll(async() => {
|
||||||
|
const unAuthCtx = {
|
||||||
|
req: {
|
||||||
|
headers: {},
|
||||||
|
connection: {
|
||||||
|
remoteAddress: '127.0.0.1'
|
||||||
|
},
|
||||||
|
getLocale: () => 'en'
|
||||||
|
},
|
||||||
|
args: {}
|
||||||
|
};
|
||||||
|
let login = await models.VnUser.signIn(unAuthCtx, 'salesAssistant', 'nightmare');
|
||||||
|
let accessToken = await models.AccessToken.findById(login.token);
|
||||||
|
ctx = {req: {accessToken: accessToken}};
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jasmine.clock().install();
|
||||||
|
jasmine.clock().mockDate(new Date(startingTime));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jasmine.clock().uninstall();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should renew token', async() => {
|
||||||
|
const mockDate = new Date(startingTime + 26600000);
|
||||||
|
jasmine.clock().mockDate(mockDate);
|
||||||
|
const {id} = await models.VnUser.renewToken(ctx);
|
||||||
|
|
||||||
|
expect(id).not.toEqual(ctx.req.accessToken.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('NOT should renew', async() => {
|
||||||
|
let error;
|
||||||
|
let response;
|
||||||
|
try {
|
||||||
|
response = await models.VnUser.renewToken(ctx);
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error).toBeUndefined();
|
||||||
|
expect(response.id).toEqual(ctx.req.accessToken.id);
|
||||||
|
});
|
||||||
|
});
|
|
@ -20,10 +20,7 @@ describe('VnUser Sign-in()', () => {
|
||||||
let ctx = {req: {accessToken: accessToken}};
|
let ctx = {req: {accessToken: accessToken}};
|
||||||
let signInLog = await SignInLog.find({where: {token: accessToken.id}});
|
let signInLog = await SignInLog.find({where: {token: accessToken.id}});
|
||||||
|
|
||||||
expect(signInLog.length).toEqual(1);
|
expect(signInLog.length).toEqual(0);
|
||||||
expect(signInLog[0].userFk).toEqual(accessToken.userId);
|
|
||||||
expect(signInLog[0].owner).toEqual(true);
|
|
||||||
expect(login.token).toBeDefined();
|
|
||||||
|
|
||||||
await VnUser.logout(ctx.req.accessToken.id);
|
await VnUser.logout(ctx.req.accessToken.id);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethod('validateToken', {
|
|
||||||
description: 'Validates the current logged user token',
|
|
||||||
returns: {
|
|
||||||
type: 'Boolean',
|
|
||||||
root: true
|
|
||||||
},
|
|
||||||
http: {
|
|
||||||
path: `/validateToken`,
|
|
||||||
verb: 'GET'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.validateToken = async function() {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"name": "docuwareTablet",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "docuwareTablet"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"tablet": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,9 @@
|
||||||
},
|
},
|
||||||
"darkMode": {
|
"darkMode": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"tabletFk": {
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
@ -43,6 +46,11 @@
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "VnUser",
|
"model": "VnUser",
|
||||||
"foreignKey": "userFk"
|
"foreignKey": "userFk"
|
||||||
|
},
|
||||||
|
"Tablet": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "docuwareTablet",
|
||||||
|
"foreignKey": "tabletFk"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ module.exports = function(Self) {
|
||||||
require('../methods/vn-user/sign-in')(Self);
|
require('../methods/vn-user/sign-in')(Self);
|
||||||
require('../methods/vn-user/acl')(Self);
|
require('../methods/vn-user/acl')(Self);
|
||||||
require('../methods/vn-user/recover-password')(Self);
|
require('../methods/vn-user/recover-password')(Self);
|
||||||
require('../methods/vn-user/validate-token')(Self);
|
|
||||||
require('../methods/vn-user/privileges')(Self);
|
require('../methods/vn-user/privileges')(Self);
|
||||||
require('../methods/vn-user/validate-auth')(Self);
|
require('../methods/vn-user/validate-auth')(Self);
|
||||||
require('../methods/vn-user/renew-token')(Self);
|
require('../methods/vn-user/renew-token')(Self);
|
||||||
|
@ -135,6 +134,7 @@ module.exports = function(Self) {
|
||||||
Self.signInValidate = async(user, userToken, token, ctx) => {
|
Self.signInValidate = async(user, userToken, token, ctx) => {
|
||||||
const [[key, value]] = Object.entries(Self.userUses(user));
|
const [[key, value]] = Object.entries(Self.userUses(user));
|
||||||
const isOwner = Self.rawSql(`SELECT ? = ? `, [userToken[key], value]);
|
const isOwner = Self.rawSql(`SELECT ? = ? `, [userToken[key], value]);
|
||||||
|
if (!isOwner) {
|
||||||
await Self.app.models.SignInLog.create({
|
await Self.app.models.SignInLog.create({
|
||||||
userName: user,
|
userName: user,
|
||||||
token: token.id,
|
token: token.id,
|
||||||
|
@ -142,8 +142,8 @@ module.exports = function(Self) {
|
||||||
ip: ctx.req.ip,
|
ip: ctx.req.ip,
|
||||||
owner: isOwner
|
owner: isOwner
|
||||||
});
|
});
|
||||||
if (!isOwner)
|
|
||||||
throw new UserError('Try again');
|
throw new UserError('Try again');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -102,13 +102,6 @@
|
||||||
"principalType": "ROLE",
|
"principalType": "ROLE",
|
||||||
"principalId": "$everyone",
|
"principalId": "$everyone",
|
||||||
"permission": "ALLOW"
|
"permission": "ALLOW"
|
||||||
},
|
|
||||||
{
|
|
||||||
"property": "validateToken",
|
|
||||||
"accessType": "EXECUTE",
|
|
||||||
"principalType": "ROLE",
|
|
||||||
"principalId": "$authenticated",
|
|
||||||
"permission": "ALLOW"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"property": "validateAuth",
|
"property": "validateAuth",
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
-- Auto-generated SQL script #202311061003
|
||||||
|
UPDATE salix.accessTokenConfig
|
||||||
|
SET courtesyTime=60
|
||||||
|
WHERE id=1;
|
|
@ -1,4 +1,4 @@
|
||||||
RENAME TABLE `vn`.`clientCreditLimit` TO `vn`.`roleCreditLimit`;
|
RENAME TABLE `vn`.`clientCreditLimit` TO `vn`.`roleCreditLimit`;
|
||||||
ALTER TABLE `vn`.`clientCreditLimit` DROP FOREIGN KEY `clientCreditLimit_FK`;
|
ALTER TABLE `vn`.`roleCreditLimit` DROP FOREIGN KEY `clientCreditLimit_FK`;
|
||||||
ALTER TABLE `vn`.`roleCreditLimit` ADD CONSTRAINT `roleCreditLimit_FK` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
ALTER TABLE `vn`.`roleCreditLimit` ADD CONSTRAINT `roleCreditLimit_FK` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
DELETE FROM `account`.`signInLog` where owner <> FALSE
|
|
@ -1,9 +1,12 @@
|
||||||
|
CREATE SCHEMA IF NOT EXISTS `vn2008`;
|
||||||
|
USE `vn`;
|
||||||
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||||
SQL SECURITY DEFINER
|
SQL SECURITY DEFINER
|
||||||
VIEW `vn`.`ticketState`
|
VIEW `ticketState`
|
||||||
AS SELECT `tt`.`created` AS `updated`,
|
AS SELECT `tt`.`created` AS `updated`,
|
||||||
`tt`.`stateFk` AS `stateFk`,
|
`tt`.`stateFk` AS `stateFk`,
|
||||||
`tt`.`userFk` AS `userFk`,
|
`tt`.`userFk` AS `workerFk`,
|
||||||
`tls`.`ticketFk` AS `ticketFk`,
|
`tls`.`ticketFk` AS `ticketFk`,
|
||||||
`s`.`id` AS `state`,
|
`s`.`id` AS `state`,
|
||||||
`s`.`order` AS `productionOrder`,
|
`s`.`order` AS `productionOrder`,
|
||||||
|
@ -15,10 +18,10 @@ AS SELECT `tt`.`created` AS `updated`,
|
||||||
`s`.`isPicked` AS `isPicked`
|
`s`.`isPicked` AS `isPicked`
|
||||||
FROM (
|
FROM (
|
||||||
(
|
(
|
||||||
`vn`.`ticketLastState` `tls`
|
`ticketLastState` `tls`
|
||||||
JOIN `vn`.`ticketTracking` `tt` ON(`tt`.`id` = `tls`.`ticketTrackingFk`)
|
JOIN `ticketTracking` `tt` ON(`tt`.`id` = `tls`.`ticketTrackingFk`)
|
||||||
)
|
)
|
||||||
JOIN `vn`.`state` `s` ON(`s`.`id` = `tt`.`stateFk`)
|
JOIN `state` `s` ON(`s`.`id` = `tt`.`stateFk`)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||||
|
@ -33,14 +36,15 @@ AS SELECT `tt`.`id` AS `inter_id`,
|
||||||
`tt`.`supervisorFk` AS `Id_supervisor`
|
`tt`.`supervisorFk` AS `Id_supervisor`
|
||||||
FROM `vn`.`ticketTracking` `tt`;
|
FROM `vn`.`ticketTracking` `tt`;
|
||||||
|
|
||||||
CREATE OR REPLACE
|
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||||
ALGORITHM = UNDEFINED VIEW `ticketStateToday` AS
|
SQL SECURITY DEFINER
|
||||||
SELECT
|
VIEW `ticketStateToday`
|
||||||
|
AS SELECT
|
||||||
`ts`.`ticket` AS `ticket`,
|
`ts`.`ticket` AS `ticket`,
|
||||||
`ts`.`state` AS `state`,
|
`ts`.`state` AS `state`,
|
||||||
`ts`.`productionOrder` AS `productionOrder`,
|
`ts`.`productionOrder` AS `productionOrder`,
|
||||||
`ts`.`alertLevel` AS `alertLevel`,
|
`ts`.`alertLevel` AS `alertLevel`,
|
||||||
`ts`.`userFk` AS `userFk`,
|
`ts`.`worker` AS `worker`,
|
||||||
`ts`.`code` AS `code`,
|
`ts`.`code` AS `code`,
|
||||||
`ts`.`updated` AS `updated`,
|
`ts`.`updated` AS `updated`,
|
||||||
`ts`.`isPicked` AS `isPicked`
|
`ts`.`isPicked` AS `isPicked`
|
|
@ -0,0 +1,10 @@
|
||||||
|
-- vn.docuwareTablet definition
|
||||||
|
|
||||||
|
CREATE TABLE `vn`.`docuwareTablet` (
|
||||||
|
`tablet` varchar(100) NOT NULL PRIMARY KEY,
|
||||||
|
`description` varchar(255) DEFAULT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||||
|
|
||||||
|
ALTER TABLE `vn`.`userConfig`
|
||||||
|
ADD COLUMN tabletFk varchar(100) DEFAULT NULL,
|
||||||
|
ADD FOREIGN KEY (tabletFk) REFERENCES `vn`.`docuwareTablet`(tablet);
|
|
@ -2967,9 +2967,9 @@ INSERT INTO `vn`.`wagonTypeTray` (`id`, `typeFk`, `height`, `colorFk`)
|
||||||
(2, 1, 50, 2),
|
(2, 1, 50, 2),
|
||||||
(3, 1, 0, 3);
|
(3, 1, 0, 3);
|
||||||
|
|
||||||
INSERT INTO `salix`.`accessTokenConfig` (`id`, `renewPeriod`, `renewInterval`)
|
INSERT INTO `salix`.`accessTokenConfig` (`id`, `renewPeriod`, `courtesyTime`, `renewInterval`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 21600, 300);
|
(1, 21600, 60, 300);
|
||||||
|
|
||||||
INSERT INTO `vn`.`travelConfig` (`id`, `warehouseInFk`, `warehouseOutFk`, `agencyFk`, `companyFk`)
|
INSERT INTO `vn`.`travelConfig` (`id`, `warehouseInFk`, `warehouseOutFk`, `agencyFk`, `companyFk`)
|
||||||
VALUES
|
VALUES
|
||||||
|
@ -3009,3 +3009,8 @@ INSERT INTO `vn`.`invoiceCorrectionType` (`id`, `description`)
|
||||||
(1, 'Error in VAT calculation'),
|
(1, 'Error in VAT calculation'),
|
||||||
(2, 'Error in sales details'),
|
(2, 'Error in sales details'),
|
||||||
(3, 'Error in customer data');
|
(3, 'Error in customer data');
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`docuwareTablet` (`tablet`,`description`)
|
||||||
|
VALUES
|
||||||
|
('Tablet1','Jarvis tablet'),
|
||||||
|
('Tablet2','Avengers tablet');
|
||||||
|
|
|
@ -26391,6 +26391,7 @@ CREATE TABLE `cplusCorrectingType` (
|
||||||
) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Table structure for table `cplusRectificationType`
|
-- Table structure for table `cplusRectificationType`
|
||||||
--
|
--
|
||||||
|
|
|
@ -82,7 +82,7 @@ export default class Token {
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
this.renewPeriod = data.renewPeriod;
|
this.renewPeriod = data.renewPeriod;
|
||||||
this.stopRenewer();
|
this.stopRenewer();
|
||||||
this.inservalId = setInterval(() => this.checkValidity(), data.renewInterval * 1000);
|
this.intervalId = setInterval(() => this.checkValidity(), data.renewInterval * 1000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,17 +103,13 @@ export default class Token {
|
||||||
const token = res.data;
|
const token = res.data;
|
||||||
this.set(token.id, now, token.ttl, this.remember);
|
this.set(token.id, now, token.ttl, this.remember);
|
||||||
})
|
})
|
||||||
.catch(res => {
|
|
||||||
if (res.data?.error?.code !== 'periodNotExceeded')
|
|
||||||
throw res;
|
|
||||||
})
|
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.checking = false;
|
this.checking = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
stopRenewer() {
|
stopRenewer() {
|
||||||
clearInterval(this.inservalId);
|
clearInterval(this.intervalId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Token.$inject = ['vnInterceptor', '$http', '$rootScope'];
|
Token.$inject = ['vnInterceptor', '$http', '$rootScope'];
|
||||||
|
|
|
@ -18,7 +18,7 @@ Show summary: Mostrar vista previa
|
||||||
What is new: Novedades de la versión
|
What is new: Novedades de la versión
|
||||||
Settings: Ajustes
|
Settings: Ajustes
|
||||||
There is a new version, click here to reload: Hay una nueva versión, pulse aquí para recargar
|
There is a new version, click here to reload: Hay una nueva versión, pulse aquí para recargar
|
||||||
This ticket is locked.: Este ticket está bloqueado
|
This ticket is locked: Este ticket está bloqueado
|
||||||
|
|
||||||
# Actions
|
# Actions
|
||||||
|
|
||||||
|
|
|
@ -183,7 +183,7 @@
|
||||||
"Social name should be uppercase": "Social name should be uppercase",
|
"Social name should be uppercase": "Social name should be uppercase",
|
||||||
"Street should be uppercase": "Street should be uppercase",
|
"Street should be uppercase": "Street should be uppercase",
|
||||||
"You don't have enough privileges.": "You don't have enough privileges.",
|
"You don't have enough privileges.": "You don't have enough privileges.",
|
||||||
"This ticket is locked.": "This ticket is locked.",
|
"This ticket is locked": "This ticket is locked",
|
||||||
"This ticket is not editable.": "This ticket is not editable.",
|
"This ticket is not editable.": "This ticket is not editable.",
|
||||||
"The ticket doesn't exist.": "The ticket doesn't exist.",
|
"The ticket doesn't exist.": "The ticket doesn't exist.",
|
||||||
"The sales do not exists": "The sales do not exists",
|
"The sales do not exists": "The sales do not exists",
|
||||||
|
|
|
@ -312,7 +312,7 @@
|
||||||
"You cannot assign/remove an alias that you are not assigned to": "No puede asignar/eliminar un alias que no tenga asignado",
|
"You cannot assign/remove an alias that you are not assigned to": "No puede asignar/eliminar un alias que no tenga asignado",
|
||||||
"This invoice has a linked vehicle.": "Esta factura tiene un vehiculo vinculado",
|
"This invoice has a linked vehicle.": "Esta factura tiene un vehiculo vinculado",
|
||||||
"You don't have enough privileges.": "No tienes suficientes permisos.",
|
"You don't have enough privileges.": "No tienes suficientes permisos.",
|
||||||
"This ticket is locked.": "Este ticket está bloqueado.",
|
"This ticket is locked": "Este ticket está bloqueado.",
|
||||||
"This ticket is not editable.": "Este ticket no es editable.",
|
"This ticket is not editable.": "Este ticket no es editable.",
|
||||||
"The ticket doesn't exist.": "No existe el ticket.",
|
"The ticket doesn't exist.": "No existe el ticket.",
|
||||||
"Social name should be uppercase": "La razón social debe ir en mayúscula",
|
"Social name should be uppercase": "La razón social debe ir en mayúscula",
|
||||||
|
@ -329,5 +329,6 @@
|
||||||
"The amount cannot be less than the minimum": "La cantidad no puede ser menor que la cantidad mínima",
|
"The amount cannot be less than the minimum": "La cantidad no puede ser menor que la cantidad mínima",
|
||||||
"quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mínima",
|
"quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mínima",
|
||||||
"Cannot past travels with entries": "No se pueden pasar envíos con entradas",
|
"Cannot past travels with entries": "No se pueden pasar envíos con entradas",
|
||||||
"It was not able to remove the next expeditions:": "No se pudo eliminar las siguientes expediciones: {{expeditions}}"
|
"It was not able to remove the next expeditions:": "No se pudo eliminar las siguientes expediciones: {{expeditions}}",
|
||||||
|
"This user does not have an assigned tablet": "Este usuario no tiene tablet asignada"
|
||||||
}
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
Date.vnUTC = () => {
|
Date.vnUTC = (env = process.env.NODE_ENV) => {
|
||||||
const env = process.env.NODE_ENV;
|
|
||||||
if (!env || env === 'development')
|
if (!env || env === 'development')
|
||||||
return new Date(Date.UTC(2001, 0, 1, 11));
|
return new Date(Date.UTC(2001, 0, 1, 11));
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('account changePassword()', () => {
|
describe('account changePassword()', () => {
|
||||||
const userId = 70;
|
const userId = 70;
|
||||||
const unauthCtx = {
|
const unAuthCtx = {
|
||||||
req: {
|
req: {
|
||||||
headers: {},
|
headers: {},
|
||||||
connection: {
|
connection: {
|
||||||
|
@ -79,7 +79,7 @@ describe('account changePassword()', () => {
|
||||||
passExpired: yesterday
|
passExpired: yesterday
|
||||||
}
|
}
|
||||||
, options);
|
, options);
|
||||||
await models.VnUser.signIn(unauthCtx, 'trainee', 'nightmare', options);
|
await models.VnUser.signIn(unAuthCtx, 'trainee', 'nightmare', options);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.message != 'Pass expired')
|
if (e.message != 'Pass expired')
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('removeFile', {
|
Self.remoteMethodCtx('removeFile', {
|
||||||
description: 'Removes a claim document',
|
description: 'Removes a claim document',
|
||||||
|
@ -19,8 +21,8 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.removeFile = async(ctx, id, options) => {
|
Self.removeFile = async(ctx, id, options) => {
|
||||||
let tx;
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
@ -31,19 +33,18 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const models = Self.app.models;
|
const claimDms = await Self.findById(id, null, myOptions);
|
||||||
const targetClaimDms = await models.ClaimDms.findById(id, null, myOptions);
|
|
||||||
const targetDms = await models.Dms.findById(targetClaimDms.dmsFk, null, myOptions);
|
|
||||||
const trashDmsType = await models.DmsType.findOne({where: {code: 'trash'}}, myOptions);
|
|
||||||
|
|
||||||
await models.Dms.removeFile(ctx, targetClaimDms.dmsFk, myOptions);
|
const targetDms = await Self.app.models.Dms.removeFile(ctx, claimDms.dmsFk, myOptions);
|
||||||
await targetClaimDms.destroy(myOptions);
|
|
||||||
|
|
||||||
await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions);
|
if (!targetDms || ! claimDms)
|
||||||
|
throw new UserError('Try again');
|
||||||
|
|
||||||
|
const claimDmsDestroyed = await claimDms.destroy(myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return targetDms;
|
return claimDmsDestroyed;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
const fs = require('fs-extra');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('uploadFile', {
|
Self.remoteMethodCtx('uploadFile', {
|
||||||
|
@ -57,96 +54,33 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.uploadFile = async(ctx, id, options) => {
|
Self.uploadFile = async(ctx, id, options) => {
|
||||||
const tx = await Self.beginTransaction({});
|
const {Dms, ClaimDms} = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
if (!myOptions.transaction)
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
|
|
||||||
const models = Self.app.models;
|
|
||||||
const promises = [];
|
|
||||||
const TempContainer = models.TempContainer;
|
|
||||||
const ClaimContainer = models.ClaimContainer;
|
|
||||||
const fileOptions = {};
|
|
||||||
const args = ctx.args;
|
|
||||||
|
|
||||||
let srcFile;
|
|
||||||
try {
|
|
||||||
const hasWriteRole = await models.DmsType.hasWriteRole(ctx, args.dmsTypeId, myOptions);
|
|
||||||
if (!hasWriteRole)
|
|
||||||
throw new UserError(`You don't have enough privileges`);
|
|
||||||
|
|
||||||
// Upload file to temporary path
|
|
||||||
const tempContainer = await TempContainer.container('dms');
|
|
||||||
const uploaded = await TempContainer.upload(tempContainer.name, ctx.req, ctx.result, fileOptions);
|
|
||||||
const files = Object.values(uploaded.files).map(file => {
|
|
||||||
return file[0];
|
|
||||||
});
|
|
||||||
|
|
||||||
const addedDms = [];
|
|
||||||
for (const uploadedFile of files) {
|
|
||||||
const newDms = await createDms(ctx, uploadedFile, myOptions);
|
|
||||||
const pathHash = ClaimContainer.getHash(newDms.id);
|
|
||||||
|
|
||||||
const file = await TempContainer.getFile(tempContainer.name, uploadedFile.name);
|
|
||||||
srcFile = path.join(file.client.root, file.container, file.name);
|
|
||||||
|
|
||||||
const claimContainer = await ClaimContainer.container(pathHash);
|
|
||||||
const dstFile = path.join(claimContainer.client.root, pathHash, newDms.file);
|
|
||||||
|
|
||||||
await fs.move(srcFile, dstFile, {
|
|
||||||
overwrite: true
|
|
||||||
});
|
|
||||||
|
|
||||||
addedDms.push(newDms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addedDms.forEach(dms => {
|
try {
|
||||||
const newClaimDms = models.ClaimDms.create({
|
const uploadedFiles = await Dms.uploadFile(ctx, myOptions);
|
||||||
|
|
||||||
|
const promises = uploadedFiles.map(dms => ClaimDms.create({
|
||||||
claimFk: id,
|
claimFk: id,
|
||||||
dmsFk: dms.id
|
dmsFk: dms.id
|
||||||
}, myOptions);
|
}, myOptions));
|
||||||
|
await Promise.all(promises);
|
||||||
promises.push(newClaimDms);
|
|
||||||
});
|
|
||||||
const resolvedPromises = await Promise.all(promises);
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return resolvedPromises;
|
return uploadedFiles;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
|
|
||||||
if (fs.existsSync(srcFile))
|
|
||||||
await fs.unlink(srcFile);
|
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function createDms(ctx, file, myOptions) {
|
|
||||||
const models = Self.app.models;
|
|
||||||
const myUserId = ctx.req.accessToken.userId;
|
|
||||||
const args = ctx.args;
|
|
||||||
|
|
||||||
const newDms = await models.Dms.create({
|
|
||||||
workerFk: myUserId,
|
|
||||||
dmsTypeFk: args.dmsTypeId,
|
|
||||||
companyFk: args.companyId,
|
|
||||||
warehouseFk: args.warehouseId,
|
|
||||||
reference: args.reference,
|
|
||||||
description: args.description,
|
|
||||||
contentType: file.type,
|
|
||||||
hasFile: args.hasFile
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
let fileName = file.name;
|
|
||||||
const extension = models.DmsContainer.getFileExtension(fileName);
|
|
||||||
fileName = `${newDms.id}.${extension}`;
|
|
||||||
|
|
||||||
return newDms.updateAttribute('file', fileName, myOptions);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,9 +19,8 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.removeFile = async(ctx, id, options) => {
|
Self.removeFile = async(ctx, id, options) => {
|
||||||
const models = Self.app.models;
|
|
||||||
let tx;
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
@ -34,13 +33,16 @@ module.exports = Self => {
|
||||||
try {
|
try {
|
||||||
const clientDms = await Self.findById(id, null, myOptions);
|
const clientDms = await Self.findById(id, null, myOptions);
|
||||||
|
|
||||||
await models.Dms.removeFile(ctx, clientDms.dmsFk, myOptions);
|
const targetDms = await Self.app.models.Dms.removeFile(ctx, clientDms.dmsFk, myOptions);
|
||||||
|
|
||||||
const destroyedClient = await clientDms.destroy(myOptions);
|
if (!targetDms || !clientDms)
|
||||||
|
throw new UserError('Try again');
|
||||||
|
|
||||||
|
const clientDmsDestroyed = await clientDms.destroy(myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return destroyedClient;
|
return clientDmsDestroyed;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -107,17 +107,29 @@ module.exports = Self => {
|
||||||
return {or: [
|
return {or: [
|
||||||
{'c.phone': {like: `%${value}%`}},
|
{'c.phone': {like: `%${value}%`}},
|
||||||
{'c.mobile': {like: `%${value}%`}},
|
{'c.mobile': {like: `%${value}%`}},
|
||||||
|
{'a.phone': {like: `%${value}%`}},
|
||||||
]};
|
]};
|
||||||
case 'zoneFk':
|
case 'zoneFk':
|
||||||
param = 'a.postalCode';
|
return {'a.postalCode': {inq: postalCode}};
|
||||||
return {[param]: {inq: postalCode}};
|
case 'city':
|
||||||
|
return {or: [
|
||||||
|
{'c.city': {like: `%${value}%`}},
|
||||||
|
{'a.city': {like: `%${value}%`}}
|
||||||
|
]};
|
||||||
|
case 'postcode':
|
||||||
|
return {or: [
|
||||||
|
{'c.postcode': value},
|
||||||
|
{'a.postalCode': value}
|
||||||
|
]};
|
||||||
|
case 'provinceFk':
|
||||||
|
return {or: [
|
||||||
|
{'p.id': value},
|
||||||
|
{'a.provinceFk': value}
|
||||||
|
]};
|
||||||
case 'name':
|
case 'name':
|
||||||
case 'salesPersonFk':
|
case 'salesPersonFk':
|
||||||
case 'fi':
|
case 'fi':
|
||||||
case 'socialName':
|
case 'socialName':
|
||||||
case 'city':
|
|
||||||
case 'postcode':
|
|
||||||
case 'provinceFk':
|
|
||||||
case 'email':
|
case 'email':
|
||||||
param = `c.${param}`;
|
param = `c.${param}`;
|
||||||
return {[param]: {like: `%${value}%`}};
|
return {[param]: {like: `%${value}%`}};
|
||||||
|
@ -134,24 +146,29 @@ module.exports = Self => {
|
||||||
c.fi,
|
c.fi,
|
||||||
c.socialName,
|
c.socialName,
|
||||||
c.phone,
|
c.phone,
|
||||||
|
a.phone,
|
||||||
c.mobile,
|
c.mobile,
|
||||||
c.city,
|
c.city,
|
||||||
|
a.city,
|
||||||
c.postcode,
|
c.postcode,
|
||||||
|
a.postalCode,
|
||||||
c.email,
|
c.email,
|
||||||
c.isActive,
|
c.isActive,
|
||||||
c.isFreezed,
|
c.isFreezed,
|
||||||
p.id AS provinceFk,
|
p.id AS provinceClientFk,
|
||||||
|
a.provinceFk AS provinceAddressFk,
|
||||||
p.name AS province,
|
p.name AS province,
|
||||||
u.id AS salesPersonFk,
|
u.id AS salesPersonFk,
|
||||||
u.name AS salesPerson
|
u.name AS salesPerson
|
||||||
FROM client c
|
FROM client c
|
||||||
LEFT JOIN account.user u ON u.id = c.salesPersonFk
|
LEFT JOIN account.user u ON u.id = c.salesPersonFk
|
||||||
LEFT JOIN province p ON p.id = c.provinceFk
|
LEFT JOIN province p ON p.id = c.provinceFk
|
||||||
JOIN vn.address a ON a.clientFk = c.id
|
JOIN address a ON a.clientFk = c.id
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
|
|
||||||
stmt.merge(conn.makeWhere(filter.where));
|
stmt.merge(conn.makeWhere(filter.where));
|
||||||
|
stmt.merge('GROUP BY c.id');
|
||||||
stmt.merge(conn.makePagination(filter));
|
stmt.merge(conn.makePagination(filter));
|
||||||
|
|
||||||
const clientsIndex = stmts.push(stmt) - 1;
|
const clientsIndex = stmts.push(stmt) - 1;
|
||||||
|
|
|
@ -55,9 +55,9 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.uploadFile = async(ctx, id, options) => {
|
Self.uploadFile = async(ctx, id, options) => {
|
||||||
const models = Self.app.models;
|
const {Dms, ClientDms} = Self.app.models;
|
||||||
let tx;
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
@ -67,23 +67,20 @@ module.exports = Self => {
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
const promises = [];
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions);
|
const uploadedFiles = await Dms.uploadFile(ctx, myOptions);
|
||||||
uploadedFiles.forEach(dms => {
|
const promises = uploadedFiles.map(dms =>
|
||||||
const newClientDms = models.ClientDms.create({
|
ClientDms.create({
|
||||||
clientFk: id,
|
clientFk: id,
|
||||||
dmsFk: dms.id
|
dmsFk: dms.id
|
||||||
}, myOptions);
|
}, myOptions)
|
||||||
|
|
||||||
promises.push(newClientDms);
|
);
|
||||||
});
|
await Promise.all(promises);
|
||||||
const resolvedPromises = await Promise.all(promises);
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return resolvedPromises;
|
return uploadedFiles;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -90,7 +90,7 @@ module.exports = Self => {
|
||||||
AND t.refFk IS NULL
|
AND t.refFk IS NULL
|
||||||
AND c.typeFk IN ('normal','trust')
|
AND c.typeFk IN ('normal','trust')
|
||||||
GROUP BY t.clientFk, negativeBase.taxableBase
|
GROUP BY t.clientFk, negativeBase.taxableBase
|
||||||
HAVING amount <> 0`, [args.from, args.to]));
|
HAVING amount < 0`, [args.from, args.to]));
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(`
|
stmt = new ParameterizedSQL(`
|
||||||
SELECT f.*
|
SELECT f.*
|
||||||
|
|
|
@ -10,13 +10,17 @@ module.exports = Self => {
|
||||||
type: 'date',
|
type: 'date',
|
||||||
description: 'From date',
|
description: 'From date',
|
||||||
required: true
|
required: true
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
arg: 'to',
|
arg: 'to',
|
||||||
type: 'date',
|
type: 'date',
|
||||||
description: 'To date',
|
description: 'To date',
|
||||||
required: true
|
required: true
|
||||||
}],
|
}, {
|
||||||
|
arg: 'filter',
|
||||||
|
type: 'object',
|
||||||
|
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string'
|
||||||
|
},
|
||||||
|
],
|
||||||
returns: [
|
returns: [
|
||||||
{
|
{
|
||||||
arg: 'body',
|
arg: 'body',
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
name: itemShelving
|
||||||
|
columns:
|
||||||
|
id: id
|
||||||
|
itemFk: item
|
||||||
|
shelvingFk: shelving
|
||||||
|
visible: visible
|
||||||
|
created: created
|
||||||
|
grouping: grouping
|
||||||
|
packing: packing
|
||||||
|
packagingFk: package
|
||||||
|
userFk: user
|
||||||
|
isChecked: isChecked
|
||||||
|
buyFk: buy
|
|
@ -0,0 +1,13 @@
|
||||||
|
name: artículo del carro
|
||||||
|
columns:
|
||||||
|
id: id
|
||||||
|
itemFk: artículo
|
||||||
|
shelvingFk: matrícula carro
|
||||||
|
visible: visible
|
||||||
|
created: creado
|
||||||
|
grouping: grouping
|
||||||
|
packing: packing
|
||||||
|
packagingFk: embalaje
|
||||||
|
userFk: usuario
|
||||||
|
isChecked: está revisado
|
||||||
|
buyFk: compra
|
|
@ -17,3 +17,18 @@ columns:
|
||||||
agencyModeFk: agency
|
agencyModeFk: agency
|
||||||
routeFk: route
|
routeFk: route
|
||||||
zoneFk: zone
|
zoneFk: zone
|
||||||
|
name: name
|
||||||
|
beachFk: beach
|
||||||
|
ticketPacked: tickets packed
|
||||||
|
ticketFree: tickets free
|
||||||
|
ticketProduction: tickets production
|
||||||
|
packages: packages
|
||||||
|
note: note
|
||||||
|
dated: dated
|
||||||
|
dockFk: dock
|
||||||
|
priority: priority
|
||||||
|
etd: etd
|
||||||
|
expeditionTruckFk: truck
|
||||||
|
m3boxes: m3 boxes
|
||||||
|
bufferFk: buffer
|
||||||
|
isPickingAllowed: is picking allowed
|
|
@ -17,3 +17,18 @@ columns:
|
||||||
agencyModeFk: agencia
|
agencyModeFk: agencia
|
||||||
routeFk: ruta
|
routeFk: ruta
|
||||||
zoneFk: zona
|
zoneFk: zona
|
||||||
|
name: nombre
|
||||||
|
beachFk: playa
|
||||||
|
ticketPacked: tickets encajados
|
||||||
|
ticketFree: tickets libres
|
||||||
|
ticketProduction: tickets producción
|
||||||
|
packages: paquetes
|
||||||
|
note: nota
|
||||||
|
dated: fecha
|
||||||
|
dockFk: muelle
|
||||||
|
priority: prioridad
|
||||||
|
etd: etd
|
||||||
|
expeditionTruckFk: camión
|
||||||
|
m3boxes: m3 cajas
|
||||||
|
bufferFk: buffer
|
||||||
|
isPickingAllowed: está permitido recoger
|
|
@ -19,7 +19,6 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.removeFile = async(ctx, id, options) => {
|
Self.removeFile = async(ctx, id, options) => {
|
||||||
const models = Self.app.models;
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
|
||||||
|
@ -32,18 +31,18 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const targetTicketDms = await models.TicketDms.findById(id, null, myOptions);
|
const ticketDms = await Self.findById(id, null, myOptions);
|
||||||
const targetDms = await models.Dms.findById(targetTicketDms.dmsFk, null, myOptions);
|
|
||||||
const trashDmsType = await models.DmsType.findOne({where: {code: 'trash'}}, myOptions);
|
|
||||||
|
|
||||||
await models.Dms.removeFile(ctx, targetTicketDms.dmsFk, myOptions);
|
const targetDms = await Self.app.models.Dms.removeFile(ctx, ticketDms.dmsFk, myOptions);
|
||||||
await targetTicketDms.destroy(myOptions);
|
|
||||||
|
|
||||||
await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions);
|
if (!targetDms || !ticketDms)
|
||||||
|
throw new UserError('Try again');
|
||||||
|
|
||||||
|
const ticketDmsDestroyed = await ticketDms.destroy(myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return targetDms;
|
return ticketDmsDestroyed;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -41,7 +41,7 @@ module.exports = Self => {
|
||||||
throw new ForbiddenError(`This ticket is not editable.`);
|
throw new ForbiddenError(`This ticket is not editable.`);
|
||||||
|
|
||||||
if (isLocked && !isWeekly)
|
if (isLocked && !isWeekly)
|
||||||
throw new ForbiddenError(`This ticket is locked.`);
|
throw new ForbiddenError(`This ticket is locked`);
|
||||||
|
|
||||||
if (isWeekly && !canEditWeeklyTicket)
|
if (isWeekly && !canEditWeeklyTicket)
|
||||||
throw new ForbiddenError(`You don't have enough privileges.`);
|
throw new ForbiddenError(`You don't have enough privileges.`);
|
||||||
|
|
|
@ -89,6 +89,6 @@ describe('ticket addSale()', () => {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error.message).toEqual(`This ticket is locked.`);
|
expect(error.message).toEqual(`This ticket is locked`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -40,7 +40,7 @@ describe('ticket isEditableOrThrow()', () => {
|
||||||
expect(error.message).toEqual(`This ticket is not editable.`);
|
expect(error.message).toEqual(`This ticket is not editable.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error as this ticket is locked.', async() => {
|
it('should throw an error as This ticket is locked', async() => {
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
let error;
|
let error;
|
||||||
try {
|
try {
|
||||||
|
@ -57,7 +57,7 @@ describe('ticket isEditableOrThrow()', () => {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error.message).toEqual(`This ticket is locked.`);
|
expect(error.message).toEqual(`This ticket is locked`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error as you do not have enough privileges.', async() => {
|
it('should throw an error as you do not have enough privileges.', async() => {
|
||||||
|
|
|
@ -39,6 +39,6 @@ describe('ticket recalculateComponents()', () => {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error).toEqual(new ForbiddenError(`This ticket is locked.`));
|
expect(error).toEqual(new ForbiddenError(`This ticket is locked`));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,7 +23,7 @@ describe('Ticket transferClient()', () => {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error.message).toEqual(`This ticket is locked.`);
|
expect(error.message).toEqual(`This ticket is locked`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be assigned a different clientFk', async() => {
|
it('should be assigned a different clientFk', async() => {
|
||||||
|
|
|
@ -47,7 +47,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.uploadFile = async(ctx, id, options) => {
|
Self.uploadFile = async(ctx, id, options) => {
|
||||||
const models = Self.app.models;
|
const {Dms, TicketDms} = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
|
||||||
|
@ -59,22 +59,19 @@ module.exports = Self => {
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
const promises = [];
|
|
||||||
try {
|
try {
|
||||||
const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions);
|
const uploadedFiles = await Dms.uploadFile(ctx, myOptions);
|
||||||
uploadedFiles.forEach(dms => {
|
|
||||||
const newTicketDms = models.TicketDms.create({
|
const promises = uploadedFiles.map(dms => TicketDms.create({
|
||||||
ticketFk: id,
|
ticketFk: id,
|
||||||
dmsFk: dms.id
|
dmsFk: dms.id
|
||||||
}, myOptions);
|
}, myOptions));
|
||||||
|
|
||||||
promises.push(newTicketDms);
|
await Promise.all(promises);
|
||||||
});
|
|
||||||
const resolvedPromises = await Promise.all(promises);
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return resolvedPromises;
|
return uploadedFiles;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
"user": {
|
"user": {
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "VnUser",
|
"model": "VnUser",
|
||||||
"foreignKey": "userFk"
|
"foreignKey": "workerFk"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,35 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.removeFile = async(ctx, id) => {
|
Self.removeFile = async(ctx, dmsFk, options) => {
|
||||||
const models = Self.app.models;
|
const myOptions = {};
|
||||||
const workerDms = await Self.findById(id);
|
let tx;
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
await models.Dms.removeFile(ctx, workerDms.dmsFk);
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
return workerDms.destroy();
|
try {
|
||||||
|
const WorkerDms = await Self.findOne({
|
||||||
|
where: {document: dmsFk}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
const targetDms = await Self.app.models.Dms.removeFile(ctx, dmsFk, myOptions);
|
||||||
|
|
||||||
|
if (!targetDms || !WorkerDms)
|
||||||
|
throw new UserError('Try again');
|
||||||
|
|
||||||
|
const workerDmsDestroyed = await WorkerDms.destroy(myOptions);
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return workerDmsDestroyed;
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -47,30 +47,33 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.uploadFile = async(ctx, id) => {
|
Self.uploadFile = async(ctx, id) => {
|
||||||
const models = Self.app.models;
|
const {Dms, WorkerDms} = Self.app.models;
|
||||||
const promises = [];
|
const myOptions = {};
|
||||||
const tx = await Self.beginTransaction({});
|
let tx;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const uploadedFiles = await Dms.uploadFile(ctx, myOptions);
|
||||||
|
const promises = uploadedFiles.map(dms =>
|
||||||
const uploadedFiles = await models.Dms.uploadFile(ctx, options);
|
WorkerDms.create({
|
||||||
uploadedFiles.forEach(dms => {
|
|
||||||
const newWorkerDms = models.WorkerDms.create({
|
|
||||||
workerFk: id,
|
workerFk: id,
|
||||||
dmsFk: dms.id
|
dmsFk: dms.id
|
||||||
}, options);
|
}, myOptions));
|
||||||
|
await Promise.all(promises);
|
||||||
|
|
||||||
promises.push(newWorkerDms);
|
if (tx) await tx.commit();
|
||||||
});
|
|
||||||
const resolvedPromises = await Promise.all(promises);
|
|
||||||
|
|
||||||
await tx.commit();
|
return uploadedFiles;
|
||||||
|
} catch (e) {
|
||||||
return resolvedPromises;
|
if (tx) await tx.rollback();
|
||||||
} catch (err) {
|
throw e;
|
||||||
await tx.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "salix-back",
|
"name": "salix-back",
|
||||||
"version": "23.50.01",
|
"version": "24.02.01",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "salix-back",
|
"name": "salix-back",
|
||||||
"version": "23.50.01",
|
"version": "24.02.01",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.2.2",
|
"axios": "^1.2.2",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "salix-back",
|
"name": "salix-back",
|
||||||
"version": "23.52.01",
|
"version": "24.02.01",
|
||||||
"author": "Verdnatura Levante SL",
|
"author": "Verdnatura Levante SL",
|
||||||
"description": "Salix backend",
|
"description": "Salix backend",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
|
Loading…
Reference in New Issue