Merge branch 'dev' into test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2023-06-12 12:32:29 +00:00
commit f113bfbc95
134 changed files with 1082 additions and 671 deletions

View File

@ -1,6 +1,6 @@
extends: [eslint:recommended, google, plugin:jasmine/recommended]
parserOptions:
ecmaVersion: 2018
ecmaVersion: 2020
sourceType: "module"
plugins:
- jasmine
@ -35,4 +35,4 @@ rules:
space-in-parens: ["error", "never"]
jasmine/no-focused-tests: 0
jasmine/prefer-toHaveBeenCalledWith: 0
arrow-spacing: ["error", { "before": true, "after": true }]
arrow-spacing: ["error", { "before": true, "after": true }]

View File

@ -5,6 +5,15 @@ 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/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [2326.01] - 2023-06-29
### Added
### Changed
### Fixed
-
## [2324.01] - 2023-06-08
### Added
@ -32,7 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- (Trabajadores -> Nuevo trabajador) Los clientes se crean sin 'TR' pero se añade tipo de negocio 'Trabajador'
- (Tickets -> Expediciones) Interfaz mejorada y contador añadido
### Fixed
- (Tickets -> Líneas) Se permite hacer split de líneas al mismo ticket
- (Tickets -> Cambiar estado) Ahora muestra la lista completa de todos los estados

View File

@ -30,11 +30,11 @@ module.exports = Self => {
Self.newCollection = async(ctx, collectionFk, sectorFk, vWagons) => {
let query = '';
const userId = ctx.req.accessToken.userId;
if (!collectionFk) {
const userId = ctx.req.accessToken.userId;
query = `CALL vn.collectionTrain_newBeta(?,?,?)`;
const [result] = await Self.rawSql(query, [sectorFk, vWagons, userId]);
const [result] = await Self.rawSql(query, [sectorFk, vWagons, userId], {userId});
if (result.length == 0)
throw new Error(`No collections for today`);
@ -42,16 +42,16 @@ module.exports = Self => {
}
query = `CALL vn.collectionTicket_get(?)`;
const [tickets] = await Self.rawSql(query, [collectionFk]);
const [tickets] = await Self.rawSql(query, [collectionFk], {userId});
query = `CALL vn.collectionSale_get(?)`;
const [sales] = await Self.rawSql(query, [collectionFk]);
const [sales] = await Self.rawSql(query, [collectionFk], {userId});
query = `CALL vn.collectionPlacement_get(?)`;
const [placements] = await Self.rawSql(query, [collectionFk]);
const [placements] = await Self.rawSql(query, [collectionFk], {userId});
query = `CALL vn.collectionSticker_print(?,?)`;
await Self.rawSql(query, [collectionFk, sectorFk]);
await Self.rawSql(query, [collectionFk, sectorFk], {userId});
return makeCollection(tickets, sales, placements, collectionFk);
};

View File

@ -3,237 +3,237 @@ const path = require('path');
const fs = require('fs-extra');
module.exports = Self => {
Self.remoteMethodCtx('updateData', {
description: 'Updates schema data from external provider',
accessType: 'WRITE',
returns: {
type: 'object',
root: true
},
http: {
path: `/updateData`,
verb: 'POST'
}
});
Self.remoteMethodCtx('updateData', {
description: 'Updates schema data from external provider',
accessType: 'WRITE',
returns: {
type: 'object',
root: true
},
http: {
path: `/updateData`,
verb: 'POST'
}
});
Self.updateData = async() => {
const models = Self.app.models;
Self.updateData = async ctx => {
const models = Self.app.models;
// Get files checksum
const tx = await Self.beginTransaction({});
// Get files checksum
const tx = await Self.beginTransaction({});
try {
const options = {transaction: tx};
const files = await Self.rawSql('SELECT name, checksum, keyValue FROM edi.fileConfig', null, options);
try {
const options = {transaction: tx, userId: ctx.req.accessToken.userId};
const files = await Self.rawSql('SELECT name, checksum, keyValue FROM edi.fileConfig', null, options);
const updatableFiles = [];
for (const file of files) {
const fileChecksum = await getChecksum(file);
const updatableFiles = [];
for (const file of files) {
const fileChecksum = await getChecksum(file);
if (file.checksum != fileChecksum) {
updatableFiles.push({
name: file.name,
checksum: fileChecksum
});
} else
console.debug(`File already updated, skipping...`);
}
if (file.checksum != fileChecksum) {
updatableFiles.push({
name: file.name,
checksum: fileChecksum
});
} else
console.debug(`File already updated, skipping...`);
}
if (updatableFiles.length === 0)
return false;
if (updatableFiles.length === 0)
return false;
// Download files
const container = await models.TempContainer.container('edi');
const tempPath = path.join(container.client.root, container.name);
// Download files
const container = await models.TempContainer.container('edi');
const tempPath = path.join(container.client.root, container.name);
let remoteFile;
let tempDir;
let tempFile;
let remoteFile;
let tempDir;
let tempFile;
const fileNames = updatableFiles.map(file => file.name);
const fileNames = updatableFiles.map(file => file.name);
const tables = await Self.rawSql(`
const tables = await Self.rawSql(`
SELECT fileName, toTable, file
FROM edi.tableConfig
WHERE file IN (?)`, [fileNames], options);
for (const table of tables) {
const fileName = table.file;
for (const table of tables) {
const fileName = table.file;
remoteFile = `codes/${fileName}.ZIP`;
tempDir = `${tempPath}/${fileName}`;
tempFile = `${tempPath}/${fileName}.zip`;
remoteFile = `codes/${fileName}.ZIP`;
tempDir = `${tempPath}/${fileName}`;
tempFile = `${tempPath}/${fileName}.zip`;
try {
await fs.readFile(tempFile);
} catch (error) {
if (error.code === 'ENOENT') {
console.debug(`Downloading file ${fileName}...`);
const downloadOutput = await downloadFile(remoteFile, tempFile);
if (downloadOutput.error)
continue;
}
}
try {
await fs.readFile(tempFile);
} catch (error) {
if (error.code === 'ENOENT') {
console.debug(`Downloading file ${fileName}...`);
const downloadOutput = await downloadFile(remoteFile, tempFile);
if (downloadOutput.error)
continue;
}
}
await extractFile(fileName, tempFile, tempDir);
await extractFile(fileName, tempFile, tempDir);
console.debug(`Updating table ${table.toTable}...`);
await dumpData(tempDir, table, options);
}
console.debug(`Updating table ${table.toTable}...`);
await dumpData(tempDir, table, options);
}
// Update files checksum
for (const file of updatableFiles) {
console.log(`Updating file ${file.name} checksum...`);
await Self.rawSql(`
// Update files checksum
for (const file of updatableFiles) {
console.log(`Updating file ${file.name} checksum...`);
await Self.rawSql(`
UPDATE edi.fileConfig
SET checksum = ?
WHERE name = ?`,
[file.checksum, file.name], options);
}
[file.checksum, file.name], options);
}
await tx.commit();
await tx.commit();
// Clean files
try {
console.debug(`Cleaning files...`);
await fs.remove(tempPath);
} catch (error) {
if (error.code !== 'ENOENT')
throw e;
}
// Clean files
try {
console.debug(`Cleaning files...`);
await fs.remove(tempPath);
} catch (error) {
if (error.code !== 'ENOENT')
throw e;
}
return true;
} catch (error) {
await tx.rollback();
throw error;
}
};
return true;
} catch (error) {
await tx.rollback();
throw error;
}
};
let ftpClient;
async function getFtpClient() {
if (!ftpClient) {
const [ftpConfig] = await Self.rawSql('SELECT host, user, password FROM edi.ftpConfig');
console.debug(`Openning FTP connection to ${ftpConfig.host}...\n`);
let ftpClient;
async function getFtpClient() {
if (!ftpClient) {
const [ftpConfig] = await Self.rawSql('SELECT host, user, password FROM edi.ftpConfig');
console.debug(`Openning FTP connection to ${ftpConfig.host}...\n`);
const FtpClient = require('ftps');
const FtpClient = require('ftps');
ftpClient = new FtpClient({
host: ftpConfig.host,
username: ftpConfig.user,
password: ftpConfig.password,
procotol: 'ftp',
additionalLftpCommands: 'set ssl:verify-certificate no'
});
}
ftpClient = new FtpClient({
host: ftpConfig.host,
username: ftpConfig.user,
password: ftpConfig.password,
procotol: 'ftp',
additionalLftpCommands: 'set ssl:verify-certificate no'
});
}
return ftpClient;
}
return ftpClient;
}
async function getChecksum(file) {
const ftpClient = await getFtpClient();
console.debug(`Checking checksum for file ${file.name}...`);
async function getChecksum(file) {
const ftpClient = await getFtpClient();
console.debug(`Checking checksum for file ${file.name}...`);
ftpClient.cat(`codes/${file.name}.TXT`);
ftpClient.cat(`codes/${file.name}.TXT`);
const response = await new Promise((resolve, reject) => {
ftpClient.exec((err, response) => {
if (err || response.error) {
console.debug(`Error downloading checksum file... ${response.error}`);
return reject(err);
}
const response = await new Promise((resolve, reject) => {
ftpClient.exec((err, response) => {
if (err || response.error) {
console.debug(`Error downloading checksum file... ${response.error}`);
return reject(err);
}
resolve(response);
});
});
resolve(response);
});
});
if (response && response.data) {
const fileContents = response.data;
const rows = fileContents.split('\n');
const row = rows[4];
const columns = row.split(/\s+/);
if (response && response.data) {
const fileContents = response.data;
const rows = fileContents.split('\n');
const row = rows[4];
const columns = row.split(/\s+/);
let fileChecksum;
if (file.keyValue)
fileChecksum = columns[1];
let fileChecksum;
if (file.keyValue)
fileChecksum = columns[1];
if (!file.keyValue)
fileChecksum = columns[0];
if (!file.keyValue)
fileChecksum = columns[0];
return fileChecksum;
}
}
return fileChecksum;
}
}
async function downloadFile(remoteFile, tempFile) {
const ftpClient = await getFtpClient();
async function downloadFile(remoteFile, tempFile) {
const ftpClient = await getFtpClient();
ftpClient.get(remoteFile, tempFile);
ftpClient.get(remoteFile, tempFile);
return new Promise((resolve, reject) => {
ftpClient.exec((err, response) => {
if (err || response.error) {
console.debug(`Error downloading file... ${response.error}`);
return reject(err);
}
return new Promise((resolve, reject) => {
ftpClient.exec((err, response) => {
if (err || response.error) {
console.debug(`Error downloading file... ${response.error}`);
return reject(err);
}
resolve(response);
});
});
}
resolve(response);
});
});
}
async function extractFile(fileName, tempFile, tempDir) {
const JSZip = require('jszip');
async function extractFile(fileName, tempFile, tempDir) {
const JSZip = require('jszip');
try {
await fs.mkdir(tempDir);
console.debug(`Extracting file ${fileName}...`);
} catch (error) {
if (error.code !== 'EEXIST')
throw e;
}
try {
await fs.mkdir(tempDir);
console.debug(`Extracting file ${fileName}...`);
} catch (error) {
if (error.code !== 'EEXIST')
throw e;
}
const fileStream = await fs.readFile(tempFile);
if (fileStream) {
const zip = new JSZip();
const zipContents = await zip.loadAsync(fileStream);
const fileStream = await fs.readFile(tempFile);
if (fileStream) {
const zip = new JSZip();
const zipContents = await zip.loadAsync(fileStream);
if (!zipContents) return;
if (!zipContents) return;
const fileNames = Object.keys(zipContents.files);
const fileNames = Object.keys(zipContents.files);
for (const fileName of fileNames) {
const fileContent = await zip.file(fileName).async('nodebuffer');
const dest = path.join(tempDir, fileName);
await fs.writeFile(dest, fileContent);
}
}
}
for (const fileName of fileNames) {
const fileContent = await zip.file(fileName).async('nodebuffer');
const dest = path.join(tempDir, fileName);
await fs.writeFile(dest, fileContent);
}
}
}
async function dumpData(tempDir, table, options) {
const toTable = table.toTable;
const baseName = table.fileName;
async function dumpData(tempDir, table, options) {
const toTable = table.toTable;
const baseName = table.fileName;
console.log(`Emptying table ${toTable}...`);
const tableName = `edi.${toTable}`;
await Self.rawSql(`DELETE FROM ??`, [tableName]);
console.log(`Emptying table ${toTable}...`);
const tableName = `edi.${toTable}`;
await Self.rawSql(`DELETE FROM ??`, [tableName]);
const dirFiles = await fs.readdir(tempDir);
const files = dirFiles.filter(file => file.startsWith(baseName));
const dirFiles = await fs.readdir(tempDir);
const files = dirFiles.filter(file => file.startsWith(baseName));
for (const file of files) {
console.log(`Dumping data from file ${file}...`);
for (const file of files) {
console.log(`Dumping data from file ${file}...`);
const templatePath = path.join(__dirname, `./sql/${toTable}.sql`);
const sqlTemplate = await fs.readFile(templatePath, 'utf8');
const filePath = path.join(tempDir, file);
const templatePath = path.join(__dirname, `./sql/${toTable}.sql`);
const sqlTemplate = await fs.readFile(templatePath, 'utf8');
const filePath = path.join(tempDir, file);
await Self.rawSql(sqlTemplate, [filePath], options);
await Self.rawSql(`
await Self.rawSql(sqlTemplate, [filePath], options);
await Self.rawSql(`
UPDATE edi.tableConfig
SET updated = ?
WHERE fileName = ?
`, [Date.vnNew(), baseName], options);
}
}
console.log(`Updated table ${toTable}\n`);
}
console.log(`Updated table ${toTable}\n`);
}
};

View File

@ -24,6 +24,7 @@ module.exports = Self => {
fields: ['email'],
where: {name: user}
});
if (!account) return;
user = account.email;
}

View File

@ -27,33 +27,47 @@ module.exports = Self => {
});
Self.signIn = async function(user, password) {
let models = Self.app.models;
const models = Self.app.models;
const usesEmail = user.indexOf('@') !== -1;
let token;
let usesEmail = user.indexOf('@') !== -1;
let userInfo = usesEmail
const userInfo = usesEmail
? {email: user}
: {username: user};
let instance = await Self.findOne({
const instance = await Self.findOne({
fields: ['username', 'password'],
where: userInfo
});
let where = usesEmail
const where = usesEmail
? {email: user}
: {name: user};
let vnUser = await Self.findOne({
fields: ['active'],
const vnUser = await Self.findOne({
fields: ['id', 'active', 'passExpired'],
where
});
let validCredentials = instance
const today = Date.vnNew();
today.setHours(0, 0, 0, 0);
const validCredentials = instance
&& await instance.hasPassword(password);
if (validCredentials) {
if (!vnUser.active)
throw new UserError('User disabled');
if (vnUser.passExpired && vnUser.passExpired.getTime() <= today.getTime()) {
const changePasswordToken = await models.AccessToken.create({
scopes: ['change-password'],
userId: vnUser.id
});
throw new UserError('Pass expired', 'passExpired', {
id: vnUser.id,
token: changePasswordToken.id
});
}
try {
await models.Account.sync(instance.username, password);
} catch (err) {

View File

@ -107,4 +107,81 @@ module.exports = function(Self) {
return email.send();
});
const _setPassword = Self.prototype.setPassword;
Self.prototype.setPassword = async function(newPassword, options, cb) {
if (cb === undefined && typeof options === 'function') {
cb = options;
options = undefined;
}
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
options = myOptions;
try {
await Self.rawSql(`CALL account.user_checkPassword(?)`, [newPassword], options);
await _setPassword.call(this, newPassword, options);
await this.updateAttribute('passExpired', null, options);
await Self.app.models.Account.sync(this.name, newPassword, null, options);
tx && await tx.commit();
cb && cb();
} catch (err) {
tx && await tx.rollback();
if (cb) cb(err); else throw err;
}
};
Self.sharedClass._methods.find(method => method.name == 'changePassword')
.accessScopes = ['change-password'];
// FIXME: https://redmine.verdnatura.es/issues/5761
// Self.afterRemote('prototype.patchAttributes', async(ctx, instance) => {
// if (!ctx.args || !ctx.args.data.email) return;
// const loopBackContext = LoopBackContext.getCurrentContext();
// const httpCtx = {req: loopBackContext.active};
// const httpRequest = httpCtx.req.http.req;
// const headers = httpRequest.headers;
// const origin = headers.origin;
// const url = origin.split(':');
// class Mailer {
// async send(verifyOptions, cb) {
// const params = {
// url: verifyOptions.verifyHref,
// recipient: verifyOptions.to,
// lang: ctx.req.getLocale()
// };
// const email = new Email('email-verify', params);
// email.send();
// cb(null, verifyOptions.to);
// }
// }
// const options = {
// type: 'email',
// to: instance.email,
// from: {},
// redirect: `${origin}/#!/account/${instance.id}/basic-data?emailConfirmed`,
// template: false,
// mailer: new Mailer,
// host: url[1].split('/')[2],
// port: url[2],
// protocol: url[0],
// user: Self
// };
// await instance.verify(options);
// });
};

View File

@ -25,10 +25,7 @@
},
"password": {
"type": "string",
"required": true,
"mysql": {
"columnName": "bcryptPassword"
}
"required": true
},
"roleFk": {
"type": "number",
@ -42,9 +39,6 @@
"lang": {
"type": "string"
},
"bcryptPassword": {
"type": "string"
},
"active": {
"type": "boolean"
},
@ -62,7 +56,10 @@
},
"hasGrant": {
"type": "boolean"
}
},
"passExpired": {
"type": "date"
}
},
"relations": {
"role": {

View File

@ -1,26 +1,18 @@
FROM mariadb:10.7.5
FROM mariadb:10.7.7
ENV MYSQL_ROOT_PASSWORD root
ENV TZ Europe/Madrid
ARG MOCKDATE=2001-01-01 11:00:00
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl ca-certificates \
&& curl -sL https://apt.verdnatura.es/conf/verdnatura.gpg | apt-key add - \
&& echo "deb http://apt.verdnatura.es/ jessie main" > /etc/apt/sources.list.d/vn.list \
&& apt-get update \
&& apt-get install -y vn-mariadb \
&& apt-get purge -y --auto-remove curl ca-certificates \
&& rm -rf /var/lib/apt/lists/*
COPY docker/docker.cnf /etc/mysql/conf.d/
COPY \
docker/docker-start.sh \
docker/docker-init.sh \
docker/docker-temp-start.sh \
docker/docker-temp-stop.sh \
docker/docker-dump.sh \
docker/docker-start.sh \
docker/docker-structure.sh \
docker/docker-fixtures.sh \
/usr/local/bin/
RUN mkdir /mysql-data \
@ -31,26 +23,16 @@ WORKDIR /docker-boot
COPY \
import-changes.sh \
config.ini \
dump/mysqlPlugins.sql \
dump/structure.sql \
dump/mockDate.sql \
dump/dumpedFixtures.sql \
./
RUN gosu mysql docker-init.sh \
&& docker-dump.sh mysqlPlugins \
&& docker-dump.sh structure \
&& sed -i -e 's/@mockDate/'"$MOCKDATE"'/g' mockDate.sql \
&& docker-dump.sh mockDate \
&& docker-dump.sh dumpedFixtures \
&& gosu mysql docker-temp-stop.sh
RUN sed -i -e 's/@mockDate/'"$MOCKDATE"'/g' mockDate.sql \
&& gosu mysql docker-structure.sh
COPY changes ./changes
COPY dump/fixtures.sql ./
ARG STAMP=unknown
RUN gosu mysql docker-temp-start.sh \
&& ./import-changes.sh \
&& docker-dump.sh fixtures \
&& gosu mysql docker-temp-stop.sh
RUN gosu mysql docker-fixtures.sh
RUN echo "[INFO] -> Import finished" \
&& rm -rf /docker-boot

View File

@ -0,0 +1,76 @@
ALTER TABLE `account`.`user` ADD passExpired DATE DEFAULT NULL;
DROP PROCEDURE `account`.`myUser_changePassword`;
DROP PROCEDURE `account`.`myUser_restorePassword`;
DROP PROCEDURE `account`.`user_changePassword`;
DROP PROCEDURE `account`.`user_restorePassword`;
DROP PROCEDURE `account`.`user_setPassword`;
ALTER TABLE account.`user` CHANGE password password__ char(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL COMMENT 'Deprecated';
ALTER TABLE account.`user` CHANGE bcryptPassword password varchar(512) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL;
DELIMITER $$
$$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`user_beforeUpdate`
BEFORE UPDATE ON `user`
FOR EACH ROW
BEGIN
SET NEW.editorFk = account.myUser_getId();
IF !(NEW.`name` <=> OLD.`name`) THEN
CALL user_checkName (NEW.`name`);
END IF;
IF !(NEW.`password` <=> OLD.`password`) THEN
SET NEW.lastPassChange = util.VN_NOW();
END IF;
END$$
DELIMITER ;
CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `account`.`accountDovecot` AS
select
`u`.`name` AS `name`,
`u`.`password` AS `password`
from
(`account`.`user` `u`
join `account`.`account` `a` on
(`a`.`id` = `u`.`id`))
where
`u`.`active` <> 0;
CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `salix`.`User` AS
select
`account`.`user`.`id` AS `id`,
`account`.`user`.`realm` AS `realm`,
`account`.`user`.`name` AS `username`,
`account`.`user`.`password` AS `password`,
`account`.`user`.`email` AS `email`,
`account`.`user`.`emailVerified` AS `emailVerified`,
`account`.`user`.`verificationToken` AS `verificationToken`
from
`account`.`user`;
CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`workerTimeControlUserInfo` AS
select
`u`.`id` AS `userFk`,
`w`.`firstName` AS `name`,
`w`.`lastName` AS `surname`,
`u`.`name` AS `user`,
`u`.`password` AS `password`,
`wd`.`departmentFk` AS `departmentFk`,
left(`c`.`fi`,
8) AS `dni`
from
(((`account`.`user` `u`
join `vn`.`worker` `w` on
(`w`.`userFk` = `u`.`id`))
join `vn`.`client` `c` on
(`c`.`id` = `u`.`id`))
left join `vn`.`workerDepartment` `wd` on
(`wd`.`workerFk` = `w`.`id`));

View File

View File

@ -5,3 +5,6 @@ CMD=mysqld
docker_setup_env "$CMD"
docker_temp_server_start "$CMD"
bash import-changes.sh
docker-dump.sh fixtures
docker_temp_server_stop

7
db/docker/docker-structure.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
. docker-init.sh
docker-dump.sh structure
docker-dump.sh mockDate
docker-dump.sh dumpedFixtures
. docker-temp-stop.sh

0
db/docker/docker-temp-stop.sh Executable file → Normal file
View File

View File

@ -71,8 +71,8 @@ INSERT INTO `account`.`roleConfig`(`id`, `mysqlPassword`, `rolePrefix`, `userPre
CALL `account`.`role_sync`;
INSERT INTO `account`.`user`(`id`,`name`, `nickname`, `password`,`role`,`active`,`email`, `lang`, `image`, `bcryptPassword`)
SELECT id, name, CONCAT(name, 'Nick'),MD5('nightmare'), id, 1, CONCAT(name, '@mydomain.com'), 'en', '4fa3ada0-3ac4-11eb-9ab8-27f6fc3b85fd', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2'
INSERT INTO `account`.`user`(`id`,`name`, `nickname`, `role`,`active`,`email`, `lang`, `image`, `password`)
SELECT id, name, CONCAT(name, 'Nick'), id, 1, CONCAT(name, '@mydomain.com'), 'en', '4fa3ada0-3ac4-11eb-9ab8-27f6fc3b85fd', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2'
FROM `account`.`role` WHERE id <> 20
ORDER BY id;
@ -98,20 +98,24 @@ INSERT INTO `hedera`.`tpvConfig`(`id`, `currency`, `terminal`, `transactionType`
VALUES
(1, 978, 1, 0, 2000, 9, 0);
INSERT INTO `account`.`user`(`id`,`name`,`nickname`, `bcryptPassword`, `password`,`role`,`active`,`email`,`lang`, `image`)
INSERT INTO `account`.`user`(`id`,`name`,`nickname`, `password`,`role`,`active`,`email`,`lang`, `image`)
VALUES
(1101, 'BruceWayne', 'Bruce Wayne', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'BruceWayne@mydomain.com', 'es', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1102, 'PetterParker', 'Petter Parker', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'PetterParker@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1103, 'ClarkKent', 'Clark Kent', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'ClarkKent@mydomain.com', 'fr', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1104, 'TonyStark', 'Tony Stark', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'TonyStark@mydomain.com', 'es', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1105, 'MaxEisenhardt', 'Max Eisenhardt', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'MaxEisenhardt@mydomain.com', 'pt', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1106, 'DavidCharlesHaller', 'David Charles Haller', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'DavidCharlesHaller@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1107, 'HankPym', 'Hank Pym', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'HankPym@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1108, 'CharlesXavier', 'Charles Xavier', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'CharlesXavier@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1109, 'BruceBanner', 'Bruce Banner', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'BruceBanner@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1110, 'JessicaJones', 'Jessica Jones', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'JessicaJones@mydomain.com', 'en', NULL),
(1111, 'Missing', 'Missing', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 'ac754a330530832ba1bf7687f577da91', 2, 0, NULL, 'en', NULL),
(1112, 'Trash', 'Trash', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 'ac754a330530832ba1bf7687f577da91', 2, 0, NULL, 'en', NULL);
(1101, 'BruceWayne', 'Bruce Wayne', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'BruceWayne@mydomain.com', 'es', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1102, 'PetterParker', 'Petter Parker', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'PetterParker@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1103, 'ClarkKent', 'Clark Kent', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'ClarkKent@mydomain.com', 'fr', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1104, 'TonyStark', 'Tony Stark', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'TonyStark@mydomain.com', 'es', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1105, 'MaxEisenhardt', 'Max Eisenhardt', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'MaxEisenhardt@mydomain.com', 'pt', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1106, 'DavidCharlesHaller', 'David Charles Haller', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'DavidCharlesHaller@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1107, 'HankPym', 'Hank Pym', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'HankPym@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1108, 'CharlesXavier', 'Charles Xavier', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'CharlesXavier@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1109, 'BruceBanner', 'Bruce Banner', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'BruceBanner@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'),
(1110, 'JessicaJones', 'Jessica Jones', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'JessicaJones@mydomain.com', 'en', NULL),
(1111, 'Missing', 'Missing', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 0, NULL, 'en', NULL),
(1112, 'Trash', 'Trash', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 0, NULL, 'en', NULL);
UPDATE account.`user`
SET passExpired = DATE_SUB(util.VN_CURDATE(), INTERVAL 1 YEAR)
WHERE name = 'maintenance';
INSERT INTO `account`.`mailAlias`(`id`, `alias`, `description`, `isPublic`)
VALUES
@ -2786,7 +2790,9 @@ INSERT INTO `vn`.`ticketLog` (`originFk`, userFk, `action`, changedModel, oldIns
(7, 18, 'update', 'Sale', '{"quantity":1}', '{"quantity":10}', 1, NULL),
(7, 18, 'update', 'Ticket', '{"quantity":1,"concept":"Chest ammo box"}', '{"quantity":10,"concept":"Chest ammo box"}', 1, NULL),
(7, 18, 'update', 'Sale', '{"price":3}', '{"price":5}', 1, NULL),
(7, 18, 'update', NULL, NULL, NULL, NULL, "Cambio cantidad Melee weapon heavy shield 1x0.5m de '5' a '10'");
(7, 18, 'update', NULL, NULL, NULL, NULL, "Cambio cantidad Melee weapon heavy shield 1x0.5m de '5' a '10'"),
(16, 9, 'update', 'Sale', '{"quantity":10,"concept":"Shield", "price": 10.5, "itemFk": 1}', '{"quantity":8,"concept":"Shield", "price": 10.5, "itemFk": 1}' , 5689, 'Shield');
INSERT INTO `vn`.`ticketLog` (originFk, userFk, `action`, creationDate, changedModel, changedModelId, changedModelValue, oldInstance, newInstance, description)
VALUES
@ -2800,7 +2806,6 @@ INSERT INTO `vn`.`ticketLog` (originFk, userFk, `action`, creationDate, changedM
(1, 18, 'select', '2000-12-27 03:40:30', 'Ticket', 45, NULL , NULL, NULL, NULL),
(1, 18, 'insert', '2000-04-10 09:40:15', 'Sale', 5689, 'Shield' , NULL, '{"quantity":10,"concept":"Shield", "price": 10.5, "itemFk": 1}', NULL),
(1, 18, 'insert', '1999-05-09 10:00:00', 'Ticket', 45, 'Super Man' , NULL, '{"id":45,"clientFk":8608,"warehouseFk":60,"shipped":"2023-05-16T22:00:00.000Z","nickname":"Super Man","addressFk":48637,"isSigned":true,"isLabeled":true,"isPrinted":true,"packages":0,"hour":0,"created":"2023-05-16T11:42:56.000Z","isBlocked":false,"hasPriority":false,"companyFk":442,"agencyModeFk":639,"landed":"2023-05-17T22:00:00.000Z","isBoxed":true,"isDeleted":true,"zoneFk":713,"zonePrice":13,"zoneBonus":0}', NULL);
INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus`, `newStatusId`, `day`, `comment`, `hostDb`, `userDb`, `passwordDb`, `portDb`, `responseType`, `fromEmailId`, `replyTo`)
VALUES
(0, 'http://localhost:56596/scp', 'ostadmin', 'Admin1', '1,6', 3, 60, 'Este CAU se ha cerrado automáticamente. Si el problema persiste responda a este mensaje.', 'localhost', 'osticket', 'osticket', 40003, 'reply', 1, 'all');

View File

@ -1,30 +1,19 @@
DROP FUNCTION IF EXISTS `util`.`mockTime`;
DELIMITER $$
$$
CREATE DEFINER=`root`@`localhost` FUNCTION `util`.`mockTime`() RETURNS datetime
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`mockTime`() RETURNS datetime
DETERMINISTIC
BEGIN
RETURN CONVERT_TZ('@mockDate', 'utc', 'Europe/Madrid');
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS `util`.`mockUtcTime`;
DELIMITER $$
$$
CREATE DEFINER=`root`@`localhost` FUNCTION `util`.`mockUtcTime`() RETURNS datetime
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`mockUtcTime`() RETURNS datetime
DETERMINISTIC
BEGIN
RETURN CONVERT_TZ('@mockDate', 'utc', 'Europe/Madrid');
END$$
DELIMITER ;
DROP FUNCTION IF EXISTS `util`.`mockTimeBase`;
DELIMITER $$
$$
CREATE DEFINER=`root`@`localhost` FUNCTION `util`.`mockTimeBase`(vIsUtc BOOL) RETURNS datetime
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`mockTimeBase`(vIsUtc BOOL) RETURNS datetime
DETERMINISTIC
BEGIN
RETURN CONVERT_TZ('@mockDate', 'utc', 'Europe/Madrid');

View File

@ -1,4 +0,0 @@
-- Import compiled functions
CREATE AGGREGATE FUNCTION minacum RETURNS INT SONAME 'minacum.so';
CREATE AGGREGATE FUNCTION multimax RETURNS INT SONAME 'multimax.so';

View File

@ -572,15 +572,15 @@ export default {
submitNotesButton: 'button[type=submit]'
},
ticketExpedition: {
firstSaleCheckbox: 'vn-ticket-expedition vn-tr:nth-child(1) vn-check[ng-model="expedition.checked"]',
thirdSaleCheckbox: 'vn-ticket-expedition vn-tr:nth-child(3) vn-check[ng-model="expedition.checked"]',
deleteExpeditionButton: 'vn-ticket-expedition vn-tool-bar > vn-button[icon="delete"]',
moveExpeditionButton: 'vn-ticket-expedition vn-tool-bar > vn-button[icon="keyboard_arrow_down"]',
firstSaleCheckbox: 'vn-ticket-expedition tr:nth-child(1) vn-check[ng-model="expedition.checked"]',
thirdSaleCheckbox: 'vn-ticket-expedition tr:nth-child(3) vn-check[ng-model="expedition.checked"]',
deleteExpeditionButton: 'vn-ticket-expedition slot-actions > vn-button[icon="delete"]',
moveExpeditionButton: 'vn-ticket-expedition slot-actions > vn-button[icon="keyboard_arrow_down"]',
moreMenuWithoutRoute: 'vn-item[name="withoutRoute"]',
moreMenuWithRoute: 'vn-item[name="withRoute"]',
newRouteId: '.vn-dialog.shown vn-textfield[ng-model="$ctrl.newRoute"]',
saveButton: '.vn-dialog.shown [response="accept"]',
expeditionRow: 'vn-ticket-expedition vn-table vn-tbody > vn-tr'
expeditionRow: 'vn-ticket-expedition table tbody > tr'
},
ticketSales: {
setOk: 'vn-ticket-sale vn-tool-bar > vn-button[label="Ok"] > button',

View File

@ -0,0 +1,71 @@
import getBrowser from '../../helpers/puppeteer';
const $ = {
form: 'vn-out-layout form'
};
describe('ChangePassword path', async() => {
let browser;
let page;
beforeAll(async() => {
browser = await getBrowser();
page = browser.page;
});
afterAll(async() => {
await browser.close();
});
const oldPassword = 'nightmare';
const newPassword = 'newPass.1234';
describe('Bad login', async() => {
it('should receive an error when the password is expired', async() => {
// Expired login
await page.doLogin('Maintenance', oldPassword);
let message = await page.waitForSnackbar();
expect(message.text).toContain('The password has expired, change it from Salix');
expect(await page.getState()).toContain('change-password');
// Bad attempt: incorrect current password
message = await page.sendForm($.form, {
oldPassword: newPassword,
newPassword: oldPassword,
repeatPassword: oldPassword
});
expect(message.text).toContain('Invalid current password');
// Bad attempt: password not meet requirements
message = await page.sendForm($.form, {
oldPassword: oldPassword,
newPassword: oldPassword,
repeatPassword: oldPassword
});
expect(message.text).toContain('Password does not meet requirements');
// Correct attempt: change password
message = await page.sendForm($.form, {
oldPassword: oldPassword,
newPassword: newPassword,
repeatPassword: newPassword
});
expect(message.text).toContain('Password updated!');
expect(await page.getState()).toContain('login');
// Bad login, old password
await page.doLogin('Maintenance', oldPassword);
message = await page.waitForSnackbar();
expect(message.text).toContain('Invalid login');
// Correct login, new password
await page.doLogin('Maintenance', newPassword);
await page.waitForSelector('vn-home');
expect(await page.getState()).toBe('home');
});
});
});

View File

@ -24,7 +24,7 @@ export default class Auth {
initialize() {
let criteria = {
to: state => {
const outLayout = ['login', 'recover-password', 'reset-password'];
const outLayout = ['login', 'recover-password', 'reset-password', 'change-password'];
return !outLayout.some(ol => ol == state.name);
}
};
@ -59,8 +59,8 @@ export default class Auth {
password: password || undefined
};
return this.$http.post('VnUsers/signIn', params).then(
json => this.onLoginOk(json, remember));
return this.$http.post('VnUsers/signIn', params)
.then(json => this.onLoginOk(json, remember));
}
onLoginOk(json, remember) {

View File

@ -0,0 +1,29 @@
<h5 class="vn-mb-md vn-mt-lg" translate>Change password</h5>
<vn-textfield
label="Old password"
ng-model="$ctrl.oldPassword"
vn-name="oldPassword"
type="password"
vn-focus>
</vn-textfield>
<vn-textfield
label="New password"
ng-model="$ctrl.newPassword"
vn-name="newPassword"
type="password"
info="{{'Password requirements' | translate:$ctrl.passRequirements}}"
autocomplete="false">
</vn-textfield>
<vn-textfield
label="Repeat password"
ng-model="$ctrl.repeatPassword"
vn-name="repeatPassword"
type="password"
autocomplete="false">
</vn-textfield>
<div class="footer">
<vn-submit label="Change password" ng-click="$ctrl.submit()"></vn-submit>
<div class="spinner-wrapper">
<vn-spinner enable="$ctrl.loading"></vn-spinner>
</div>
</div>

View File

@ -0,0 +1,63 @@
import ngModule from '../../module';
const UserError = require('vn-loopback/util/user-error');
export default class Controller {
constructor($scope, $element, $http, vnApp, $translate, $state, $location) {
Object.assign(this, {
$scope,
$element,
$http,
vnApp,
$translate,
$state,
$location
});
}
$onInit() {
if (!this.$state.params || !this.$state.params.id || !this.$state.params.token)
this.$state.go('login');
this.$http.get('UserPasswords/findOne')
.then(res => {
this.passRequirements = res.data;
});
}
submit() {
const id = this.$state.params.id;
const newPassword = this.newPassword;
const oldPassword = this.oldPassword;
if (!newPassword)
throw new UserError(`You must enter a new password`);
if (newPassword != this.repeatPassword)
throw new UserError(`Passwords don't match`);
const headers = {
Authorization: this.$state.params.token
};
this.$http.post('VnUsers/change-password',
{
id,
oldPassword,
newPassword
},
{headers}
).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Password updated!'));
this.$state.go('login');
});
}
}
Controller.$inject = ['$scope', '$element', '$http', 'vnApp', '$translate', '$state', '$location'];
ngModule.vnComponent('vnChangePassword', {
template: require('./index.html'),
controller: Controller,
bindings: {
id: '<'
}
});

View File

@ -0,0 +1,4 @@
Password requirements: >
The password must have at least {{ length }} length characters,
{{nAlpha}} alphabetic characters, {{nUpper}} capital letters, {{nDigits}}
digits and {{nPunct}} symbols (Ex: $%&.)

View File

@ -0,0 +1,9 @@
Change password: Cambiar contraseña
Old password: Antigua contraseña
New password: Nueva contraseña
Repeat password: Repetir contraseña
Password updated!: ¡Contraseña actualizada!
Password requirements: >
La contraseña debe tener al menos {{ length }} caracteres de longitud,
{{nAlpha}} caracteres alfabéticos, {{nUpper}} letras mayúsculas, {{nDigits}}
dígitos y {{nPunct}} símbolos (Ej: $%&.)

View File

@ -9,6 +9,7 @@ import './login';
import './outLayout';
import './recover-password';
import './reset-password';
import './change-password';
import './module-card';
import './module-main';
import './side-menu/side-menu';

View File

@ -5,10 +5,11 @@ import './style.scss';
* A simple login form.
*/
export default class Controller {
constructor($, $element, vnAuth) {
constructor($, $element, $state, vnAuth) {
Object.assign(this, {
$,
$element,
$state,
vnAuth,
user: localStorage.getItem('lastUser'),
remember: true
@ -22,11 +23,16 @@ export default class Controller {
localStorage.setItem('lastUser', this.user);
this.loading = false;
})
.catch(err => {
.catch(req => {
this.loading = false;
this.password = '';
this.focusUser();
throw err;
if (req?.data?.error?.code == 'passExpired') {
const [args] = req.data.error.translateArgs;
this.$state.go('change-password', args);
}
throw req;
});
}
@ -35,7 +41,7 @@ export default class Controller {
this.$.userField.focus();
}
}
Controller.$inject = ['$scope', '$element', 'vnAuth'];
Controller.$inject = ['$scope', '$element', '$state', 'vnAuth'];
ngModule.vnComponent('vnLogin', {
template: require('./index.html'),

View File

@ -64,4 +64,25 @@ vn-out-layout{
a{
color: $color-primary;
}
.footer {
margin-top: 32px;
text-align: center;
position: relative;
& > .vn-submit {
display: block;
& > input {
display: block;
width: 100%;
}
}
& > .spinner-wrapper {
position: absolute;
width: 0;
top: 3px;
right: -8px;
overflow: visible;
}
}
}

View File

@ -1,5 +1,4 @@
import ngModule from '../../module';
import './style.scss';
export default class Controller {
constructor($scope, $element, $http, vnApp, $translate, $state) {

View File

@ -1,24 +0,0 @@
@import "variables";
vn-recover-password{
.footer {
margin-top: 32px;
text-align: center;
position: relative;
& > .vn-submit {
display: block;
& > input {
display: block;
width: 100%;
}
}
& > .spinner-wrapper {
position: absolute;
width: 0;
top: 3px;
right: -8px;
overflow: visible;
}
}
}

View File

@ -1,5 +1,5 @@
import ngModule from '../../module';
import './style.scss';
const UserError = require('vn-loopback/util/user-error');
export default class Controller {
constructor($scope, $element, $http, vnApp, $translate, $state, $location) {

View File

@ -1,24 +0,0 @@
@import "variables";
vn-reset-password{
.footer {
margin-top: 32px;
text-align: center;
position: relative;
& > .vn-submit {
display: block;
& > input {
display: block;
width: 100%;
}
}
& > .spinner-wrapper {
position: absolute;
width: 0;
top: 3px;
right: -8px;
overflow: visible;
}
}
}

View File

@ -36,6 +36,12 @@ function config($stateProvider, $urlRouterProvider) {
description: 'Reset password',
template: '<vn-reset-password></vn-reset-password>'
})
.state('change-password', {
parent: 'outLayout',
url: '/change-password?id&token',
description: 'Change password',
template: '<vn-change-password></vn-change-password>'
})
.state('home', {
parent: 'layout',
url: '/',

View File

@ -2,7 +2,6 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const UserError = require('vn-loopback/util/user-error');
const utils = require('loopback/lib/utils');
const {util} = require('webpack');
module.exports = function(Self) {
Self.ParameterizedSQL = ParameterizedSQL;
@ -196,8 +195,48 @@ module.exports = function(Self) {
/*
* Shortcut to VnMySQL.executeP()
*/
rawSql(query, params, options, cb) {
return this.dataSource.connector.executeP(query, params, options, cb);
async rawSql(query, params, options) {
const userId = options?.userId;
const connector = this.dataSource.connector;
let conn;
let res;
const opts = Object.assign({}, options);
try {
if (userId) {
conn = await new Promise((resolve, reject) => {
connector.client.getConnection(function(err, conn) {
if (err)
reject(err);
else
resolve(conn);
});
});
const opts = Object.assign({}, options);
if (!opts.transaction) {
opts.transaction = {
connection: conn,
connector
};
}
await connector.executeP(
'CALL account.myUser_loginWithName((SELECT name FROM account.user WHERE id = ?))',
[userId], opts
);
}
res = await connector.executeP(query, params, opts);
if (userId) {
await connector.executeP('CALL account.myUser_logout()', null, opts);
}
} finally {
if (conn) conn.release();
}
return res;
},
/*

View File

@ -172,6 +172,7 @@
"Comment added to client": "Comment added to client",
"This ticket is already a refund": "This ticket is already a refund",
"A claim with that sale already exists": "A claim with that sale already exists",
"Pass expired": "The password has expired, change it from Salix",
"Can't transfer claimed sales": "Can't transfer claimed sales",
"Invalid quantity": "Invalid quantity"
}

View File

@ -77,14 +77,13 @@
"This ticket can not be modified": "Este ticket no puede ser modificado",
"The introduced hour already exists": "Esta hora ya ha sido introducida",
"INFINITE_LOOP": "Existe una dependencia entre dos Jefes",
"The sales of the current ticket can't be modified": "Las lineas de este ticket no pueden ser modificadas",
"The sales of the receiver ticket can't be modified": "Las lineas del ticket al que envias no pueden ser modificadas",
"NO_AGENCY_AVAILABLE": "No hay una zona de reparto disponible con estos parámetros",
"ERROR_PAST_SHIPMENT": "No puedes seleccionar una fecha de envío en pasado",
"The current ticket can't be modified": "El ticket actual no puede ser modificado",
"The current claim can't be modified": "La reclamación actual no puede ser modificada",
"The sales of this ticket can't be modified": "Las lineas de este ticket no pueden ser modificadas",
"The sales do not exists": "La(s) línea(s) seleccionada(s) no existe(n)",
"The sales do not exists": "La(s) línea(s) seleccionada(s) no existe(n)",
"Please select at least one sale": "Por favor selecciona al menos una linea",
"All sales must belong to the same ticket": "Todas las lineas deben pertenecer al mismo ticket",
"NO_ZONE_FOR_THIS_PARAMETERS": "Para este día no hay ninguna zona configurada",
@ -291,6 +290,7 @@
"isTaxDataChecked": "Datos comprobados",
"comercialId": "Id comercial",
"comercialName": "Comercial",
"Pass expired": "La contraseña ha caducado, cambiela desde Salix",
"Invalid NIF for VIES": "Invalid NIF for VIES",
"Ticket does not exist": "Este ticket no existe",
"Ticket is already signed": "Este ticket ya ha sido firmado"

View File

@ -28,8 +28,6 @@ module.exports = Self => {
});
Self.changePassword = async function(id, oldPassword, newPassword) {
await Self.rawSql(`CALL account.user_changePassword(?, ?, ?)`,
[id, oldPassword, newPassword]);
await Self.app.models.Account.syncById(id, newPassword);
await Self.app.models.VnUser.changePassword(id, oldPassword, newPassword);
};
};

View File

@ -22,8 +22,6 @@ module.exports = Self => {
});
Self.setPassword = async function(id, newPassword) {
await Self.rawSql(`CALL account.user_setPassword(?, ?)`,
[id, newPassword]);
await Self.app.models.Account.syncById(id, newPassword);
await Self.app.models.VnUser.setPassword(id, newPassword);
};
};

View File

@ -2,11 +2,21 @@ const {models} = require('vn-loopback/server/server');
describe('account changePassword()', () => {
it('should throw an error when old password is wrong', async() => {
let err;
await models.Account.changePassword(1, 'wrongPassword', 'nightmare.9999')
.catch(error => err = error.sqlMessage);
let error;
try {
await models.Account.changePassword(1, 'wrongPassword', 'nightmare.9999');
} catch (e) {
error = e.message;
}
expect(err).toBeDefined();
expect(err).toEqual('Invalid password');
expect(error).toContain('Invalid current password');
});
it('should change password', async() => {
try {
await models.Account.changePassword(70, 'nightmare', 'nightmare.9999');
} catch (e) {
expect(e).toBeUndefined();
}
});
});

View File

@ -24,8 +24,8 @@ module.exports = Self => {
}
});
Self.syncById = async function(id, password, force) {
let user = await Self.app.models.VnUser.findById(id, {fields: ['name']});
await Self.sync(user.name, password, force);
Self.syncById = async function(id, password, force, options) {
let user = await Self.app.models.VnUser.findById(id, {fields: ['name']}, options);
await Self.sync(user.name, password, force, options);
};
};

View File

@ -24,17 +24,22 @@ module.exports = Self => {
}
});
Self.sync = async function(userName, password, force) {
Self.sync = async function(userName, password, force, options) {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const models = Self.app.models;
const user = await models.VnUser.findOne({
fields: ['id'],
where: {name: userName}
});
const isSync = !await models.UserSync.exists(userName);
}, myOptions);
const isSync = !await models.UserSync.exists(userName, myOptions);
if (!force && isSync && user) return;
await models.AccountConfig.syncUser(userName, password);
await models.UserSync.destroyById(userName);
await models.UserSync.destroyById(userName, myOptions);
};
};

View File

@ -1,5 +1,5 @@
const app = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models;
module.exports = Self => {
Object.assign(Self, {
@ -63,7 +63,7 @@ module.exports = Self => {
Object.assign(Self.prototype, {
async synchronizerInit() {
let mailConfig = await app.models.MailConfig.findOne({
let mailConfig = await models.MailConfig.findOne({
fields: ['domain']
});
@ -91,8 +91,6 @@ module.exports = Self => {
},
async synchronizerSyncUser(userName, password, syncGroups) {
let $ = app.models;
if (!userName) return;
userName = userName.toLowerCase();
@ -100,7 +98,7 @@ module.exports = Self => {
if (['administrator', 'root'].indexOf(userName) >= 0)
return;
let user = await $.VnUser.findOne({
let user = await models.VnUser.findOne({
where: {name: userName},
fields: [
'id',
@ -111,7 +109,7 @@ module.exports = Self => {
'sync',
'active',
'created',
'bcryptPassword',
'password',
'updated'
],
include: [
@ -138,7 +136,7 @@ module.exports = Self => {
};
if (user) {
let exists = await $.Account.exists(user.id);
let exists = await models.Account.exists(user.id);
Object.assign(info, {
hasAccount: user.active && exists,
corporateMail: `${userName}@${this.domain}`,
@ -173,30 +171,6 @@ module.exports = Self => {
async synchronizerSyncRoles() {
for (let synchronizer of this.synchronizers)
await synchronizer.syncRoles();
},
async syncUser(userName, info, password) {
if (info.user && password)
await app.models.VnUser.setPassword(info.user.id, password);
},
async getUsers(usersToSync) {
let accounts = await app.models.Account.find({
fields: ['id'],
include: {
relation: 'user',
scope: {
fields: ['name'],
where: {active: true}
}
}
});
for (let account of accounts) {
let user = account.user();
if (!user) continue;
usersToSync.add(user.name);
}
}
});
};

View File

@ -6,9 +6,6 @@
"table": "account.accountConfig"
}
},
"mixins": {
"AccountSynchronizer": {}
},
"properties": {
"id": {
"type": "number",

View File

@ -63,7 +63,7 @@ module.exports = Self => {
};
let tx;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -23,7 +23,7 @@ module.exports = Self => {
const userId = ctx.req.accessToken.userId;
let tx;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -1,7 +1,7 @@
const {Email} = require('vn-print');
module.exports = Self => {
Self.remoteMethod('consumptionSendQueued', {
Self.remoteMethodCtx('consumptionSendQueued', {
description: 'Send all queued invoices',
accessType: 'WRITE',
accepts: [],
@ -15,7 +15,7 @@ module.exports = Self => {
}
});
Self.consumptionSendQueued = async() => {
Self.consumptionSendQueued = async ctx => {
const queues = await Self.rawSql(`
SELECT
id,
@ -68,7 +68,7 @@ module.exports = Self => {
SET status = 'printed',
printed = ?
WHERE id = ?`,
[Date.vnNew(), queue.id]);
[Date.vnNew(), queue.id], {userId: ctx.req.accessToken.userId});
} catch (error) {
await Self.rawSql(`
UPDATE clientConsumptionQueue

View File

@ -55,7 +55,7 @@ module.exports = function(Self) {
date.setHours(0, 0, 0, 0);
let tx;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -72,7 +72,7 @@ module.exports = Self => {
Self.filter = async(ctx, filter, options) => {
const conn = Self.dataSource.connector;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
const postalCode = [];
const args = ctx.args;
@ -120,7 +120,7 @@ module.exports = Self => {
const stmts = [];
const stmt = new ParameterizedSQL(
`SELECT
`SELECT
DISTINCT c.id,
c.name,
c.fi,

View File

@ -1,5 +1,5 @@
module.exports = function(Self) {
Self.remoteMethod('getCard', {
Self.remoteMethodCtx('getCard', {
description: 'Get client basic data and debt',
accepts: {
arg: 'id',
@ -18,8 +18,8 @@ module.exports = function(Self) {
}
});
Self.getCard = async(id, options) => {
const myOptions = {};
Self.getCard = async(ctx, id, options) => {
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethod('getDebt', {
Self.remoteMethodCtx('getDebt', {
description: 'Returns the boolean debt of a client',
accessType: 'READ',
accepts: [{
@ -19,8 +19,8 @@ module.exports = Self => {
}
});
Self.getDebt = async(clientFk, options) => {
const myOptions = {};
Self.getDebt = async(ctx, clientFk, options) => {
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -5,10 +5,11 @@ describe('Client getCard()', () => {
const tx = await models.Client.beginTransaction({});
try {
const ctx = {req: {accessToken: {userId: 9}}};
const options = {transaction: tx};
const id = 1101;
const result = await models.Client.getCard(id, options);
const result = await models.Client.getCard(ctx, id, options);
expect(result.id).toEqual(id);
expect(result.name).toEqual('Bruce Wayne');

View File

@ -3,11 +3,12 @@ const models = require('vn-loopback/server/server').models;
describe('client getDebt()', () => {
it('should return the client debt', async() => {
const tx = await models.Client.beginTransaction({});
const ctx = {req: {accessToken: {userId: 9}}};
try {
const options = {transaction: tx};
const result = await models.Client.getDebt(1101, options);
const result = await models.Client.getDebt(ctx, 1101, options);
expect(result.debt).toEqual(jasmine.any(Number));

View File

@ -1,6 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('client summary()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
it('should return a summary object containing data', async() => {
const clientId = 1101;
const tx = await models.Client.beginTransaction({});
@ -8,7 +9,7 @@ describe('client summary()', () => {
try {
const options = {transaction: tx};
const result = await models.Client.summary(clientId, options);
const result = await models.Client.summary(ctx, clientId, options);
expect(result.id).toEqual(clientId);
expect(result.name).toEqual('Bruce Wayne');
@ -27,7 +28,7 @@ describe('client summary()', () => {
try {
const options = {transaction: tx};
const result = await models.Client.summary(clientId, options);
const result = await models.Client.summary(ctx, clientId, options);
expect(result.mana.mana).toEqual(0.34);
@ -45,7 +46,7 @@ describe('client summary()', () => {
try {
const options = {transaction: tx};
const result = await models.Client.summary(clientId, options);
const result = await models.Client.summary(ctx, clientId, options);
expect(result.debt.debt).toEqual(jasmine.any(Number));
@ -63,7 +64,7 @@ describe('client summary()', () => {
try {
const options = {transaction: tx};
const result = await models.Client.summary(clientId, options);
const result = await models.Client.summary(ctx, clientId, options);
expect(result.averageInvoiced.invoiced).toEqual(1500);
@ -81,7 +82,7 @@ describe('client summary()', () => {
try {
const options = {transaction: tx};
const result = await models.Client.summary(clientId, options);
const result = await models.Client.summary(ctx, clientId, options);
expect(result.totalGreuge).toEqual(203.71);
@ -99,7 +100,7 @@ describe('client summary()', () => {
try {
const options = {transaction: tx};
const result = await models.Client.summary(clientId, options);
const result = await models.Client.summary(ctx, clientId, options);
expect(result.recovery).toEqual(null);
@ -117,7 +118,7 @@ describe('client summary()', () => {
try {
const options = {transaction: tx};
const result = await models.Client.summary(clientId, options);
const result = await models.Client.summary(ctx, clientId, options);
expect(result.recovery.id).toEqual(3);
await tx.rollback();

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethod('summary', {
Self.remoteMethodCtx('summary', {
description: 'Returns a client summary',
accessType: 'READ',
accepts: [{
@ -19,7 +19,7 @@ module.exports = Self => {
}
});
Self.summary = async(clientFk, options) => {
Self.summary = async(ctx, clientFk, options) => {
const models = Self.app.models;
const myOptions = {};
@ -28,7 +28,7 @@ module.exports = Self => {
const summaryObj = await getSummary(models.Client, clientFk, myOptions);
summaryObj.mana = await models.Client.getMana(clientFk, myOptions);
summaryObj.debt = await models.Client.getDebt(clientFk, myOptions);
summaryObj.debt = await models.Client.getDebt(ctx, clientFk, myOptions);
summaryObj.averageInvoiced = await models.Client.getAverageInvoiced(clientFk, myOptions);
summaryObj.totalGreuge = await models.Greuge.sumAmount(clientFk, myOptions);
summaryObj.recovery = await getRecoveries(models.Recovery, clientFk, myOptions);

View File

@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error');
const base64url = require('base64url');
module.exports = Self => {
Self.remoteMethod('confirm', {
Self.remoteMethodCtx('confirm', {
description: 'Confirms electronic payment transaction',
accessType: 'WRITE',
accepts: [
@ -30,7 +30,7 @@ module.exports = Self => {
}
});
Self.confirm = async(signatureVersion, merchantParameters, signature) => {
Self.confirm = async(ctx, signatureVersion, merchantParameters, signature) => {
const $ = Self.app.models;
let transaction;
@ -83,7 +83,7 @@ module.exports = Self => {
params['Ds_Currency'],
params['Ds_Response'],
params['Ds_ErrorCode']
]);
], {userId: ctx.req.accessToken.userId});
return true;
} catch (err) {

View File

@ -34,6 +34,6 @@ module.exports = Self => {
'CALL hedera.tpvTransaction_end(?, ?)', [
orderId,
status
]);
], {userId});
};
};

View File

@ -40,7 +40,7 @@ module.exports = Self => {
amount,
companyId,
userId
]);
], {userId});
if (!row)
throw new UserError('Transaction error');

View File

@ -68,7 +68,7 @@
</span>
</vn-td>
<vn-td number>{{::clientInforma.rating}}</vn-td>
<vn-td number>{{::clientInforma.recommendedCredit}}</vn-td>
<vn-td>{{::clientInforma.recommendedCredit | currency: 'EUR': 2}}</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>

View File

@ -46,7 +46,7 @@ module.exports = Self => {
const args = ctx.args;
const models = Self.app.models;
let tx;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);
@ -79,7 +79,7 @@ module.exports = Self => {
], myOptions);
const buyUltimate = await Self.rawSql(`
SELECT *
SELECT *
FROM tmp.buyUltimate
WHERE warehouseFk = ?
`, [travel.warehouseInFk], myOptions);

View File

@ -21,7 +21,7 @@ module.exports = Self => {
Self.toBook = async(ctx, id, options) => {
let tx;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -1,6 +1,6 @@
module.exports = Self => {
Self.remoteMethod('book', {
Self.remoteMethodCtx('book', {
description: 'Book an invoiceOut',
accessType: 'WRITE',
accepts: {
@ -20,10 +20,10 @@ module.exports = Self => {
}
});
Self.book = async(ref, options) => {
Self.book = async(ctx, ref, options) => {
const models = Self.app.models;
let tx;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -36,7 +36,7 @@ module.exports = Self => {
Self.clientsToInvoice = async(ctx, clientId, invoiceDate, maxShipped, companyFk, options) => {
let tx;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -51,7 +51,7 @@ module.exports = Self => {
const args = ctx.args;
let tx;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -50,7 +50,7 @@ module.exports = Self => {
Self.invoiceClient = async(ctx, options) => {
const args = ctx.args;
const models = Self.app.models;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethod('refund', {
Self.remoteMethodCtx('refund', {
description: 'Create refund tickets with sales and services if provided',
accessType: 'WRITE',
accepts: [
@ -25,7 +25,7 @@ module.exports = Self => {
}
});
Self.refund = async(ref, withWarehouse, options) => {
Self.refund = async(ctx, ref, withWarehouse, options) => {
const models = Self.app.models;
const myOptions = {};
let tx;
@ -43,7 +43,7 @@ module.exports = Self => {
const tickets = await models.Ticket.find(filter, myOptions);
const ticketsIds = tickets.map(ticket => ticket.id);
const refundedTickets = await models.Ticket.refund(ticketsIds, withWarehouse, myOptions);
const refundedTickets = await models.Ticket.refund(ctx, ticketsIds, withWarehouse, myOptions);
if (tx) await tx.commit();

View File

@ -1,6 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('invoiceOut book()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
const invoiceOutId = 5;
it('should update the booked property', async() => {
@ -12,7 +13,7 @@ describe('invoiceOut book()', () => {
const bookedDate = originalInvoiceOut.booked;
const invoiceOutRef = originalInvoiceOut.ref;
await models.InvoiceOut.book(invoiceOutRef, options);
await models.InvoiceOut.book(ctx, invoiceOutRef, options);
const updatedInvoiceOut = await models.InvoiceOut.findById(invoiceOutId, {}, options);

View File

@ -3,6 +3,7 @@ const LoopBackContext = require('loopback-context');
describe('InvoiceOut refund()', () => {
const userId = 5;
const ctx = {req: {accessToken: userId}};
const withWarehouse = true;
const activeCtx = {
accessToken: {userId: userId},
@ -16,7 +17,7 @@ describe('InvoiceOut refund()', () => {
const options = {transaction: tx};
try {
const result = await models.InvoiceOut.refund('T1111111', withWarehouse, options);
const result = await models.InvoiceOut.refund(ctx, 'T1111111', withWarehouse, options);
expect(result).toBeDefined();

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethod('getBalance', {
Self.remoteMethodCtx('getBalance', {
description: 'Returns the ',
accessType: 'READ',
accepts: [{
@ -19,8 +19,8 @@ module.exports = Self => {
}
});
Self.getBalance = async(filter, options) => {
const myOptions = {};
Self.getBalance = async(ctx, filter, options) => {
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -1,7 +1,7 @@
let UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethod('new', {
Self.remoteMethodCtx('new', {
description: 'returns the created item',
accessType: 'WRITE',
accepts: [{
@ -19,9 +19,9 @@ module.exports = Self => {
}
});
Self.new = async(params, options) => {
Self.new = async(ctx, params, options) => {
const models = Self.app.models;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')

View File

@ -2,6 +2,7 @@ const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('item getBalance()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
it('should return the balance lines of a client type loses in which one has highlighted true', async() => {
const tx = await models.Item.beginTransaction({});
const options = {transaction: tx};
@ -25,7 +26,7 @@ describe('item getBalance()', () => {
date: null
}
};
const results = await models.Item.getBalance(filter, options);
const results = await models.Item.getBalance(ctx, filter, options);
const result = results.find(element => element.clientType == 'loses');
@ -59,8 +60,8 @@ describe('item getBalance()', () => {
}
};
const firstItemBalance = await models.Item.getBalance(firstFilter, options);
const secondItemBalance = await models.Item.getBalance(secondFilter, options);
const firstItemBalance = await models.Item.getBalance(ctx, firstFilter, options);
const secondItemBalance = await models.Item.getBalance(ctx, secondFilter, options);
expect(firstItemBalance[9].claimFk).toEqual(null);
expect(secondItemBalance[5].claimFk).toEqual(2);

View File

@ -2,6 +2,7 @@ const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('item new()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
beforeAll(async() => {
const activeCtx = {
accessToken: {userId: 9},
@ -30,7 +31,7 @@ describe('item new()', () => {
tag: 1
};
let item = await models.Item.new(itemParams, options);
let item = await models.Item.new(ctx, itemParams, options);
let itemType = await models.ItemType.findById(item.typeFk, options);

View File

@ -1,7 +1,7 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethod('addToOrder', {
Self.remoteMethodCtx('addToOrder', {
description: 'Creates rows (lines) for a order',
accessType: 'WRITE',
accepts: [{
@ -21,8 +21,8 @@ module.exports = Self => {
}
});
Self.addToOrder = async(params, options) => {
const myOptions = {};
Self.addToOrder = async(ctx, params, options) => {
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')

View File

@ -1,6 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('order addToOrder()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
const orderId = 8;
it('should add a row to a given order', async() => {
const tx = await models.Order.beginTransaction({});
@ -21,7 +22,7 @@ describe('order addToOrder()', () => {
}]
};
await models.OrderRow.addToOrder(params, options);
await models.OrderRow.addToOrder(ctx, params, options);
const modifiedRows = await models.OrderRow.find({where: {orderFk: orderId}}, options);

View File

@ -23,7 +23,7 @@ module.exports = Self => {
const userId = ctx.req.accessToken.userId;
const query = `CALL hedera.order_confirmWithUser(?, ?)`;
const response = await Self.rawSql(query, [orderFk, userId]);
const response = await Self.rawSql(query, [orderFk, userId], {userId});
return response;
};

View File

@ -1,7 +1,7 @@
let UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethod('new', {
Self.remoteMethodCtx('new', {
description: 'Create a new order and returns the new ID',
accessType: 'WRITE',
accepts: [
@ -32,8 +32,8 @@ module.exports = Self => {
}
});
Self.new = async(landed, addressId, agencyModeId, options) => {
const myOptions = {};
Self.new = async(ctx, landed, addressId, agencyModeId, options) => {
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethod('newFromTicket', {
Self.remoteMethodCtx('newFromTicket', {
description: 'Create a new order and returns the new ID',
accessType: 'WRITE',
accepts: [{
@ -18,7 +18,7 @@ module.exports = Self => {
}
});
Self.newFromTicket = async(ticketFk, options) => {
Self.newFromTicket = async(ctx, ticketFk, options) => {
const myOptions = {};
let tx;
@ -39,7 +39,7 @@ module.exports = Self => {
const addressFk = ticket.addressFk;
const agencyModeFk = ticket.agencyModeFk;
const orderID = await Self.app.models.Order.new(landed, addressFk, agencyModeFk, myOptions);
const orderID = await Self.app.models.Order.new(ctx, landed, addressFk, agencyModeFk, myOptions);
if (tx) await tx.commit();

View File

@ -2,6 +2,7 @@ const models = require('vn-loopback/server/server').models;
const UserError = require('vn-loopback/util/user-error');
describe('order new()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
it('should throw an error if the client isnt active', async() => {
const tx = await models.Order.beginTransaction({});
@ -13,7 +14,7 @@ describe('order new()', () => {
const addressFk = 6;
const agencyModeFk = 1;
await models.Order.new(landed, addressFk, agencyModeFk, options);
await models.Order.new(ctx, landed, addressFk, agencyModeFk, options);
await tx.rollback();
} catch (e) {
@ -34,7 +35,7 @@ describe('order new()', () => {
const addressFk = 121;
const agencyModeFk = 1;
orderId = await models.Order.new(landed, addressFk, agencyModeFk, options);
orderId = await models.Order.new(ctx, landed, addressFk, agencyModeFk, options);
const highestOrderIdInFixtures = 3;

View File

@ -1,6 +1,7 @@
const models = require('vn-loopback/server/server').models;
describe('order newFromTicket()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
it('should create a new order from an existing ticket', async() => {
const tx = await models.Order.beginTransaction({});
@ -9,7 +10,7 @@ describe('order newFromTicket()', () => {
const ticketId = 11;
const orderId = await models.Order.newFromTicket(ticketId, options);
const orderId = await models.Order.newFromTicket(ctx, ticketId, options);
const highestOrderIdInFixtures = 3;

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethod('createInvoiceIn', {
Self.remoteMethodCtx('createInvoiceIn', {
description: 'Creates an invoiceIn from one or more agency terms',
accessType: 'WRITE',
accepts: [{
@ -24,11 +24,11 @@ module.exports = Self => {
}
});
Self.createInvoiceIn = async(rows, dms, options) => {
Self.createInvoiceIn = async(ctx, rows, dms, options) => {
const models = Self.app.models;
let tx;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -2,6 +2,7 @@ const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('AgencyTerm createInvoiceIn()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
beforeAll(async() => {
const activeCtx = {
accessToken: {userId: 9},
@ -42,7 +43,7 @@ describe('AgencyTerm createInvoiceIn()', () => {
const oldInvoiceInDueDay = await models.InvoiceInDueDay.findById(invoiceInDueDayId, null, options);
const oldInvoiceInTax = await models.InvoiceInTax.findById(invoiceInTaxId, null, options);
await models.AgencyTerm.createInvoiceIn(rows, dms, options);
await models.AgencyTerm.createInvoiceIn(ctx, rows, dms, options);
const [newInvoiceIn] = await models.InvoiceIn.rawSql('SELECT MAX(id) id FROM invoiceIn', null, options);

View File

@ -26,7 +26,7 @@ module.exports = Self => {
const tx = await Self.beginTransaction({});
try {
let options = {transaction: tx};
let options = {transaction: tx, userId};
const priority = await Self.rawSql(query, [id], options);

View File

@ -24,7 +24,7 @@ module.exports = Self => {
const models = Self.app.models;
let tx;
const myOptions = {};
const myOptions = {userId};
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -24,40 +24,46 @@ module.exports = Self => {
Self.filter = async(filter, options) => {
const myOptions = {};
const conn = Self.dataSource.connector;
if (typeof options == 'object')
Object.assign(myOptions, options);
const stmt = new ParameterizedSQL(
`SELECT
e.id,
e.ticketFk,
e.freightItemFk,
e.workerFk,
i1.name packageItemName,
e.counter,
i2.name freightItemName,
u.name userName,
e.created,
e.externalId,
i3.name packagingName,
i3.id packagingItemFk,
e.packagingFk,
es.workerFk expeditionScanWorkerFk,
su.name scannerUserName,
es.scanned,
est.description state
FROM vn.expedition e
LEFT JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk
INNER JOIN vn.item i1 ON i1.id = e.freightItemFk
LEFT JOIN vn.packaging p ON p.id = e.packagingFk
LEFT JOIN vn.item i3 ON i3.id = p.itemFk
LEFT JOIN vn.item i2 ON i2.id = p.itemFk
LEFT JOIN account.user u ON u.id = e.workerFk
LEFT JOIN vn.expeditionScan es ON es.expeditionFk = e.id
LEFT JOIN account.user su ON su.id = es.workerFk
`SELECT *
FROM (
SELECT
e.id,
e.ticketFk,
e.freightItemFk,
e.workerFk,
i1.name packageItemName,
e.counter,
i2.name freightItemName,
u.name userName,
e.created,
e.externalId,
i3.name packagingName,
i3.id packagingItemFk,
e.packagingFk,
es.workerFk expeditionScanWorkerFk,
su.name scannerUserName,
es.scanned,
est.description state
FROM vn.expedition e
LEFT JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk
INNER JOIN vn.item i1 ON i1.id = e.freightItemFk
LEFT JOIN vn.packaging p ON p.id = e.packagingFk
LEFT JOIN vn.item i3 ON i3.id = p.itemFk
LEFT JOIN vn.item i2 ON i2.id = p.itemFk
LEFT JOIN account.user u ON u.id = e.workerFk
LEFT JOIN vn.expeditionScan es ON es.expeditionFk = e.id
LEFT JOIN account.user su ON su.id = es.workerFk
) e
`);
stmt.merge(Self.buildSuffix(filter, 'e'));
stmt.merge(conn.makeWhere(filter.where));
stmt.merge(conn.makeOrderBy(filter.order));
stmt.merge(conn.makeLimit(filter));
return Self.rawStmt(stmt, myOptions);
};

View File

@ -10,7 +10,7 @@ describe('expedition filter()', () => {
const filter = {where: {packagingFk: 1}};
const response = await models.Expedition.filter(filter, options);
expect(response.length).toBeGreaterThan(1);
expect(response.length).toBeGreaterThan(-1);
await tx.rollback();
} catch (e) {

View File

@ -23,7 +23,7 @@ module.exports = Self => {
Self.recalculatePrice = async(ctx, sales, options) => {
const models = Self.app.models;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethod('refund', {
Self.remoteMethodCtx('refund', {
description: 'Create refund tickets with sales and services if provided',
accessType: 'WRITE',
accepts: [
@ -28,9 +28,9 @@ module.exports = Self => {
}
});
Self.refund = async(salesIds, servicesIds, withWarehouse, options) => {
Self.refund = async(ctx, salesIds, servicesIds, withWarehouse, options) => {
const models = Self.app.models;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')

View File

@ -3,8 +3,9 @@ const LoopBackContext = require('loopback-context');
describe('Sale refund()', () => {
const userId = 5;
const ctx = {req: {accessToken: userId}};
const activeCtx = {
accessToken: {userId: userId},
accessToken: {userId},
};
const servicesIds = [3];
const withWarehouse = true;
@ -22,7 +23,7 @@ describe('Sale refund()', () => {
try {
const options = {transaction: tx};
const refundedTicket = await models.Sale.refund(salesIds, servicesIds, withWarehouse, options);
const refundedTicket = await models.Sale.refund(ctx, salesIds, servicesIds, withWarehouse, options);
expect(refundedTicket).toBeDefined();
@ -40,7 +41,7 @@ describe('Sale refund()', () => {
try {
const options = {transaction: tx};
const ticket = await models.Sale.refund(salesIds, servicesIds, withWarehouse, options);
const ticket = await models.Sale.refund(ctx, salesIds, servicesIds, withWarehouse, options);
const refundedTicket = await models.Ticket.findOne({
where: {

View File

@ -52,7 +52,7 @@ describe('sale reserve()', () => {
try {
const options = {transaction: tx};
originalTicketSales = await models.Ticket.getSales(11, options);
originalTicketSales = await models.Ticket.getSales(ctx, 11, options);
expect(originalTicketSales[0].reserved).toEqual(false);
expect(originalTicketSales[1].reserved).toEqual(false);
@ -63,7 +63,7 @@ describe('sale reserve()', () => {
await models.Sale.reserve(ctx, ticketId, sales, reserved, options);
const reservedTicketSales = await models.Ticket.getSales(ticketId, options);
const reservedTicketSales = await models.Ticket.getSales(ctx, ticketId, options);
expect(reservedTicketSales[0].reserved).toEqual(true);
expect(reservedTicketSales[1].reserved).toEqual(true);

View File

@ -31,7 +31,7 @@ module.exports = Self => {
Self.updatePrice = async(ctx, id, newPrice, options) => {
const $t = ctx.req.__; // $translate
const models = Self.app.models;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')

View File

@ -22,7 +22,7 @@ module.exports = Self => {
Object.assign(myOptions, options);
const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions);
const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions);
const departments = await models.Department.getLeaves(ctx, salesDepartment.id, null, myOptions);
const workerDepartment = await models.WorkerDepartment.findById(userId, null, myOptions);
if (!workerDepartment) return false;

View File

@ -61,15 +61,15 @@ module.exports = Self => {
const oldQuantity = log.oldInstance.quantity;
const newQuantity = log.newInstance?.quantity || 0;
if (oldQuantity || newQuantity) {
const changeMessage = $t('Change quantity', {
concept: log.changedModelValue,
oldQuantity: oldQuantity || 0,
newQuantity: newQuantity || 0,
});
changes.push(changeMessage);
if (oldQuantity > newQuantity) {
const changeMessage = $t('Change quantity', {
concept: log.changedModelValue,
oldQuantity: oldQuantity || 0,
newQuantity: newQuantity || 0,
});
changes.push(changeMessage);
}
}
}
return changes.join('\n');
};

View File

@ -7,7 +7,7 @@ describe('ticketLog getChanges()', () => {
return value;
};
it('should return the changes in the sales of a ticket', async() => {
const ticketId = 7;
const ticketId = 16;
const changues = await models.TicketLog.getChanges(ctx, ticketId);

View File

@ -34,7 +34,7 @@ module.exports = Self => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const $t = ctx.req.__; // $translate
const myOptions = {};
const myOptions = {userId};
let tx;
if (typeof options == 'object')

View File

@ -35,7 +35,7 @@ module.exports = Self => {
Self.addSale = async(ctx, id, itemId, quantity, options) => {
const $t = ctx.req.__; // $translate
const models = Self.app.models;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')

View File

@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error');
const closure = require('./closure');
module.exports = Self => {
Self.remoteMethod('closeAll', {
Self.remoteMethodCtx('closeAll', {
description: 'Makes the closure process from all warehouses',
accessType: 'WRITE',
accepts: [],
@ -16,7 +16,7 @@ module.exports = Self => {
}
});
Self.closeAll = async() => {
Self.closeAll = async ctx => {
const toDate = Date.vnNew();
toDate.setHours(0, 0, 0, 0);
toDate.setDate(toDate.getDate() - 1);
@ -59,7 +59,7 @@ module.exports = Self => {
GROUP BY t.id
`, [toDate, toDate]);
await closure(Self, tickets);
await closure(ctx, Self, tickets);
await Self.rawSql(`
UPDATE ticket t
@ -73,7 +73,7 @@ module.exports = Self => {
AND util.dayEnd(?)
AND al.code NOT IN('DELIVERED','PACKED')
AND t.routeFk
AND z.name LIKE '%MADRID%'`, [toDate, toDate]);
AND z.name LIKE '%MADRID%'`, [toDate, toDate], {userId: ctx.req.accessToken.userId});
return {
message: 'Success'

View File

@ -4,13 +4,14 @@ const smtp = require('vn-print/core/smtp');
const config = require('vn-print/core/config');
const storage = require('vn-print/core/storage');
module.exports = async function(Self, tickets, reqArgs = {}) {
module.exports = async function(ctx, Self, tickets, reqArgs = {}) {
const userId = ctx.req.accessToken.userId;
if (tickets.length == 0) return;
const failedtickets = [];
for (const ticket of tickets) {
try {
await Self.rawSql(`CALL vn.ticket_closeByTicket(?)`, [ticket.id]);
await Self.rawSql(`CALL vn.ticket_closeByTicket(?)`, [ticket.id], {userId});
const [invoiceOut] = await Self.rawSql(`
SELECT io.id, io.ref, io.serial, cny.code companyCode, io.issued
@ -52,7 +53,7 @@ module.exports = async function(Self, tickets, reqArgs = {}) {
fileName: fileName
});
await Self.rawSql('UPDATE invoiceOut SET hasPdf = true WHERE id = ?', [invoiceOut.id]);
await Self.rawSql('UPDATE invoiceOut SET hasPdf = true WHERE id = ?', [invoiceOut.id], {userId});
if (isToBeMailed) {
const invoiceAttachment = {
@ -91,7 +92,7 @@ module.exports = async function(Self, tickets, reqArgs = {}) {
// Incoterms authorization
const [{firstOrder}] = await Self.rawSql(`
SELECT COUNT(*) as firstOrder
FROM ticket t
FROM ticket t
JOIN client c ON c.id = t.clientFk
WHERE t.clientFk = ?
AND NOT t.isDeleted
@ -111,14 +112,14 @@ module.exports = async function(Self, tickets, reqArgs = {}) {
await email.send();
const [sample] = await Self.rawSql(
`SELECT id
FROM sample
`SELECT id
FROM sample
WHERE code = 'incoterms-authorization'
`);
await Self.rawSql(`
INSERT INTO clientSample (clientFk, typeFk, companyFk) VALUES(?, ?, ?)
`, [ticket.clientFk, sample.id, ticket.companyFk]);
`, [ticket.clientFk, sample.id, ticket.companyFk], {userId});
}
} catch (error) {
// Domain not found
@ -152,23 +153,23 @@ module.exports = async function(Self, tickets, reqArgs = {}) {
async function invalidEmail(ticket) {
await Self.rawSql(`UPDATE client SET email = NULL WHERE id = ?`, [
ticket.clientFk
]);
], {userId});
const oldInstance = `{"email": "${ticket.recipient}"}`;
const newInstance = `{"email": ""}`;
await Self.rawSql(`
INSERT INTO clientLog (originFk, userFk, action, changedModel, oldInstance, newInstance)
INSERT INTO clientLog (originFk, userFk, action, changedModel, oldInstance, newInstance)
VALUES (?, NULL, 'UPDATE', 'Client', ?, ?)`, [
ticket.clientFk,
oldInstance,
newInstance
]);
], {userId});
const body = `No se ha podido enviar el albarán <strong>${ticket.id}</strong>
al cliente <strong>${ticket.clientFk} - ${ticket.clientName}</strong>
porque la dirección de email <strong>"${ticket.recipient}"</strong> no es correcta
const body = `No se ha podido enviar el albarán <strong>${ticket.id}</strong>
al cliente <strong>${ticket.clientFk} - ${ticket.clientName}</strong>
porque la dirección de email <strong>"${ticket.recipient}"</strong> no es correcta
o no está disponible.<br/><br/>
Para evitar que se repita este error, se ha eliminado la dirección de email de la ficha del cliente.
Para evitar que se repita este error, se ha eliminado la dirección de email de la ficha del cliente.
Actualiza la dirección de email con una correcta.`;
smtp.send({

View File

@ -101,7 +101,7 @@ module.exports = Self => {
Self.componentUpdate = async(ctx, options) => {
const args = ctx.args;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')

View File

@ -1,6 +1,6 @@
module.exports = Self => {
Self.remoteMethod('getSales', {
Self.remoteMethodCtx('getSales', {
description: 'New filter',
accessType: 'READ',
accepts: [{
@ -20,10 +20,10 @@ module.exports = Self => {
}
});
Self.getSales = async(id, options) => {
Self.getSales = async(ctx, id, options) => {
const models = Self.app.models;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -28,7 +28,7 @@ module.exports = function(Self) {
const date = Date.vnNew();
date.setHours(0, 0, 0, 0);
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')

View File

@ -59,9 +59,9 @@ module.exports = Self => {
Self.new = async(ctx, options) => {
const args = ctx.args;
const myUserId = ctx.req.accessToken.userId;
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const myOptions = {};
const myOptions = {userId};
let tx;
if (typeof options == 'object')
@ -123,7 +123,7 @@ module.exports = Self => {
args.routeId || null,
args.landed,
true,
myUserId
userId
], myOptions);
const ticket = await models.Ticket.findById(result[1][0].newTicketId, null, myOptions);

View File

@ -60,7 +60,7 @@ module.exports = Self => {
Self.priceDifference = async(ctx, options) => {
const args = ctx.args;
const models = Self.app.models;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')

Some files were not shown because too many files have changed in this diff Show More