Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6085-ACLsMail
This commit is contained in:
commit
866ad7a9f9
19
CHANGELOG.md
19
CHANGELOG.md
|
@ -5,6 +5,12 @@ 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
|
||||||
|
|
||||||
|
### Added
|
||||||
|
### Changed
|
||||||
|
### Fixed
|
||||||
|
|
||||||
## [2350.01] - 2023-12-14
|
## [2350.01] - 2023-12-14
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -14,14 +20,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [2348.01] - 2023-11-30
|
## [2348.01] - 2023-11-30
|
||||||
|
|
||||||
### Added
|
### Características Añadidas 🆕
|
||||||
- (Ticket -> Adelantar) Permite mover lineas sin generar negativos
|
- **Tickets → Adelantar:** Permite mover lineas sin generar negativos
|
||||||
- (Ticket -> Adelantar) Permite modificar la fecha de los tickets
|
- **Tickets → Adelantar:** Permite modificar la fecha de los tickets
|
||||||
- (Trabajadores -> Notificaciones) Nueva sección (lilium)
|
- **Trabajadores → Notificaciones:** Nueva sección (lilium)
|
||||||
|
|
||||||
### Changed
|
### Correcciones 🛠️
|
||||||
### Fixed
|
- **Tickets → RocketChat:** Arreglada detección de cambios
|
||||||
- (Ticket -> RocketChat) Arreglada detección de cambios
|
|
||||||
|
|
||||||
|
|
||||||
## [2346.01] - 2023-11-16
|
## [2346.01] - 2023-11-16
|
||||||
|
|
|
@ -49,13 +49,7 @@ module.exports = Self => {
|
||||||
if (vnUser.twoFactor)
|
if (vnUser.twoFactor)
|
||||||
throw new ForbiddenError(null, 'REQUIRES_2FA');
|
throw new ForbiddenError(null, 'REQUIRES_2FA');
|
||||||
}
|
}
|
||||||
const validateLogin = await Self.validateLogin(user, password);
|
return Self.validateLogin(user, password, ctx);
|
||||||
await Self.app.models.SignInLog.create({
|
|
||||||
token: validateLogin.token,
|
|
||||||
userFk: vnUser.id,
|
|
||||||
ip: ctx.req.ip
|
|
||||||
});
|
|
||||||
return validateLogin;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Self.passExpired = async vnUser => {
|
Self.passExpired = async vnUser => {
|
||||||
|
|
|
@ -2,7 +2,7 @@ const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('VnUser Sign-in()', () => {
|
describe('VnUser Sign-in()', () => {
|
||||||
const employeeId = 1;
|
const employeeId = 1;
|
||||||
const unauthCtx = {
|
const unAuthCtx = {
|
||||||
req: {
|
req: {
|
||||||
headers: {},
|
headers: {},
|
||||||
connection: {
|
connection: {
|
||||||
|
@ -15,20 +15,21 @@ describe('VnUser Sign-in()', () => {
|
||||||
const {VnUser, AccessToken, SignInLog} = models;
|
const {VnUser, AccessToken, SignInLog} = models;
|
||||||
describe('when credentials are correct', () => {
|
describe('when credentials are correct', () => {
|
||||||
it('should return the token if user uses email', async() => {
|
it('should return the token if user uses email', async() => {
|
||||||
let login = await VnUser.signIn(unauthCtx, 'salesAssistant@mydomain.com', 'nightmare');
|
let login = await VnUser.signIn(unAuthCtx, 'salesAssistant@mydomain.com', 'nightmare');
|
||||||
let accessToken = await AccessToken.findById(login.token);
|
let accessToken = await AccessToken.findById(login.token);
|
||||||
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(1);
|
||||||
expect(signInLog[0].userFk).toEqual(accessToken.userId);
|
expect(signInLog[0].userFk).toEqual(accessToken.userId);
|
||||||
|
expect(signInLog[0].owner).toEqual(true);
|
||||||
expect(login.token).toBeDefined();
|
expect(login.token).toBeDefined();
|
||||||
|
|
||||||
await VnUser.logout(ctx.req.accessToken.id);
|
await VnUser.logout(ctx.req.accessToken.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the token', async() => {
|
it('should return the token', async() => {
|
||||||
let login = await VnUser.signIn(unauthCtx, 'salesAssistant', 'nightmare');
|
let login = await VnUser.signIn(unAuthCtx, 'salesAssistant', 'nightmare');
|
||||||
let accessToken = await AccessToken.findById(login.token);
|
let accessToken = await AccessToken.findById(login.token);
|
||||||
let ctx = {req: {accessToken: accessToken}};
|
let ctx = {req: {accessToken: accessToken}};
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ describe('VnUser Sign-in()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the token if the user doesnt exist but the client does', async() => {
|
it('should return the token if the user doesnt exist but the client does', async() => {
|
||||||
let login = await VnUser.signIn(unauthCtx, 'PetterParker', 'nightmare');
|
let login = await VnUser.signIn(unAuthCtx, 'PetterParker', 'nightmare');
|
||||||
let accessToken = await AccessToken.findById(login.token);
|
let accessToken = await AccessToken.findById(login.token);
|
||||||
let ctx = {req: {accessToken: accessToken}};
|
let ctx = {req: {accessToken: accessToken}};
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ describe('VnUser Sign-in()', () => {
|
||||||
let error;
|
let error;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await VnUser.signIn(unauthCtx, 'IDontExist', 'TotallyWrongPassword');
|
await VnUser.signIn(unAuthCtx, 'IDontExist', 'TotallyWrongPassword');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
@ -74,7 +75,7 @@ describe('VnUser Sign-in()', () => {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
await employee.updateAttribute('twoFactor', 'email', options);
|
await employee.updateAttribute('twoFactor', 'email', options);
|
||||||
|
|
||||||
await VnUser.signIn(unauthCtx, 'employee', 'nightmare', options);
|
await VnUser.signIn(unAuthCtx, 'employee', 'nightmare', options);
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
@ -99,7 +100,7 @@ describe('VnUser Sign-in()', () => {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
await employee.updateAttribute('passExpired', yesterday, options);
|
await employee.updateAttribute('passExpired', yesterday, options);
|
||||||
|
|
||||||
await VnUser.signIn(unauthCtx, 'employee', 'nightmare', options);
|
await VnUser.signIn(unAuthCtx, 'employee', 'nightmare', options);
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
|
|
@ -124,20 +124,42 @@ module.exports = function(Self) {
|
||||||
|
|
||||||
return email.send();
|
return email.send();
|
||||||
});
|
});
|
||||||
Self.signInValidate = (user, userToken) => {
|
|
||||||
|
/**
|
||||||
|
* Sign-in validate
|
||||||
|
* @param {String} user The user
|
||||||
|
* @param {Object} userToken Options
|
||||||
|
* @param {Object} token accessToken
|
||||||
|
* @param {Object} ctx context
|
||||||
|
*/
|
||||||
|
Self.signInValidate = async(user, userToken, token, ctx) => {
|
||||||
const [[key, value]] = Object.entries(Self.userUses(user));
|
const [[key, value]] = Object.entries(Self.userUses(user));
|
||||||
if (userToken[key].toLowerCase().trim() !== value.toLowerCase().trim()) {
|
const isOwner = Self.rawSql(`SELECT ? = ? `, [userToken[key], value]);
|
||||||
console.error('ERROR!!! - Signin with other user', userToken, user);
|
await Self.app.models.SignInLog.create({
|
||||||
|
userName: user,
|
||||||
|
token: token.id,
|
||||||
|
userFk: userToken.id,
|
||||||
|
ip: ctx.req.ip,
|
||||||
|
owner: isOwner
|
||||||
|
});
|
||||||
|
if (!isOwner)
|
||||||
throw new UserError('Try again');
|
throw new UserError('Try again');
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Self.validateLogin = async function(user, password) {
|
/**
|
||||||
|
* Validate login params
|
||||||
|
* @param {String} user The user
|
||||||
|
* @param {String} password
|
||||||
|
* @param {Object} ctx context
|
||||||
|
*/
|
||||||
|
Self.validateLogin = async function(user, password, ctx) {
|
||||||
const loginInfo = Object.assign({password}, Self.userUses(user));
|
const loginInfo = Object.assign({password}, Self.userUses(user));
|
||||||
const token = await Self.login(loginInfo, 'user');
|
const token = await Self.login(loginInfo, 'user');
|
||||||
|
|
||||||
const userToken = await token.user.get();
|
const userToken = await token.user.get();
|
||||||
Self.signInValidate(user, userToken);
|
|
||||||
|
if (ctx)
|
||||||
|
await Self.signInValidate(user, userToken, token, ctx);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Self.app.models.Account.sync(userToken.name, password);
|
await Self.app.models.Account.sync(userToken.name, password);
|
||||||
|
@ -187,8 +209,8 @@ module.exports = function(Self) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Self.sharedClass._methods.find(method => method.name == 'changePassword').ctor.settings.acls =
|
Self.sharedClass._methods.find(method => method.name == 'changePassword').ctor.settings.acls =
|
||||||
Self.sharedClass._methods.find(method => method.name == 'changePassword').ctor.settings.acls
|
Self.sharedClass._methods.find(method => method.name == 'changePassword').ctor.settings.acls
|
||||||
.filter(acl => acl.property != 'changePassword');
|
.filter(acl => acl.property != 'changePassword');
|
||||||
|
|
||||||
Self.userSecurity = async(ctx, userId, options) => {
|
Self.userSecurity = async(ctx, userId, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
@ -226,10 +248,12 @@ module.exports = function(Self) {
|
||||||
|
|
||||||
const env = process.env.NODE_ENV;
|
const env = process.env.NODE_ENV;
|
||||||
const liliumUrl = await Self.app.models.Url.findOne({
|
const liliumUrl = await Self.app.models.Url.findOne({
|
||||||
where: {and: [
|
where: {
|
||||||
{appName: 'lilium'},
|
and: [
|
||||||
{environment: env}
|
{appName: 'lilium'},
|
||||||
]}
|
{environment: env}
|
||||||
|
]
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
class Mailer {
|
class Mailer {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Table structure for table `signInLog`
|
-- Table structure for table `signInLog`
|
||||||
-- Description: log to debug cross-login error
|
-- Description: log to debug cross-login error
|
||||||
|
@ -13,7 +12,9 @@ CREATE TABLE `account`.`signInLog` (
|
||||||
`token` varchar(255) NOT NULL ,
|
`token` varchar(255) NOT NULL ,
|
||||||
`userFk` int(10) unsigned DEFAULT NULL,
|
`userFk` int(10) unsigned DEFAULT NULL,
|
||||||
`creationDate` timestamp NULL DEFAULT current_timestamp(),
|
`creationDate` timestamp NULL DEFAULT current_timestamp(),
|
||||||
|
`userName` varchar(30) NOT NULL,
|
||||||
`ip` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
|
`ip` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
|
||||||
|
`owner` tinyint(1) DEFAULT 1,
|
||||||
KEY `userFk` (`userFk`),
|
KEY `userFk` (`userFk`),
|
||||||
CONSTRAINT `signInLog_ibfk_1` FOREIGN KEY (`userFk`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
CONSTRAINT `signInLog_ibfk_1` FOREIGN KEY (`userFk`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
);
|
);
|
|
@ -1,6 +1,14 @@
|
||||||
|
CREATE ROLE 'salix';
|
||||||
|
GRANT 'salix' TO 'root'@'%';
|
||||||
|
SET DEFAULT ROLE 'salix' FOR 'root'@'%';
|
||||||
|
|
||||||
CREATE SCHEMA IF NOT EXISTS `vn2008`;
|
CREATE SCHEMA IF NOT EXISTS `vn2008`;
|
||||||
CREATE SCHEMA IF NOT EXISTS `tmp`;
|
CREATE SCHEMA IF NOT EXISTS `tmp`;
|
||||||
|
|
||||||
|
CREATE ROLE 'salix';
|
||||||
|
GRANT 'salix' TO 'root'@'%';
|
||||||
|
SET DEFAULT ROLE 'salix' FOR 'root'@'%';
|
||||||
|
|
||||||
UPDATE `util`.`config`
|
UPDATE `util`.`config`
|
||||||
SET `environment`= 'development';
|
SET `environment`= 'development';
|
||||||
|
|
||||||
|
@ -362,7 +370,7 @@ INSERT INTO `vn`.`contactChannel`(`id`, `name`)
|
||||||
|
|
||||||
INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk`, `hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`, `businessTypeFk`,`typeFk`)
|
INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk`, `hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`, `businessTypeFk`,`typeFk`)
|
||||||
VALUES
|
VALUES
|
||||||
(1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','loses'),
|
(1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'),
|
||||||
(1102, 'Petter Parker', '87945234L', 'SPIDER MAN', 'Aunt May', '20 INGRAM STREET, QUEENS, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'),
|
(1102, 'Petter Parker', '87945234L', 'SPIDER MAN', 'Aunt May', '20 INGRAM STREET, QUEENS, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'),
|
||||||
(1103, 'Clark Kent', '06815934E', 'SUPER MAN', 'lois lane', '344 CLINTON STREET, APARTAMENT 3-D', 'Gotham', 46460, 1111111111, 222222222, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 0, 19, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'),
|
(1103, 'Clark Kent', '06815934E', 'SUPER MAN', 'lois lane', '344 CLINTON STREET, APARTAMENT 3-D', 'Gotham', 46460, 1111111111, 222222222, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 0, 19, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'),
|
||||||
(1104, 'Tony Stark', '06089160W', 'IRON MAN', 'Pepper Potts', '10880 MALIBU POINT, 90265', 'Gotham', 46460, 1111111111, 222222222, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'),
|
(1104, 'Tony Stark', '06089160W', 'IRON MAN', 'Pepper Potts', '10880 MALIBU POINT, 90265', 'Gotham', 46460, 1111111111, 222222222, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'),
|
||||||
|
@ -372,8 +380,8 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city
|
||||||
(1108, 'Charles Xavier', '22641921P', 'PROFESSOR X', 'Beast', '3800 VICTORY PKWY, CINCINNATI, OH 45207, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 5, 1, 300, 13, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1, 'florist','normal'),
|
(1108, 'Charles Xavier', '22641921P', 'PROFESSOR X', 'Beast', '3800 VICTORY PKWY, CINCINNATI, OH 45207, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 5, 1, 300, 13, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1, 'florist','normal'),
|
||||||
(1109, 'Bruce Banner', '16104829E', 'HULK', 'Black widow', 'SOMEWHERE IN NEW YORK', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, 9, 0, 1, 'florist','normal'),
|
(1109, 'Bruce Banner', '16104829E', 'HULK', 'Black widow', 'SOMEWHERE IN NEW YORK', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, 9, 0, 1, 'florist','normal'),
|
||||||
(1110, 'Jessica Jones', '58282869H', 'JESSICA JONES', 'Luke Cage', 'NYCC 2015 POSTER', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1, 'florist','normal'),
|
(1110, 'Jessica Jones', '58282869H', 'JESSICA JONES', 'Luke Cage', 'NYCC 2015 POSTER', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1, 'florist','normal'),
|
||||||
(1111, 'Missing', NULL, 'MISSING MAN', 'Anton', 'THE SPACE, UNIVERSE FAR AWAY', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others','normal'),
|
(1111, 'Missing', NULL, 'MISSING MAN', 'Anton', 'THE SPACE, UNIVERSE FAR AWAY', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others','loses'),
|
||||||
(1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others','normal');
|
(1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others','loses');
|
||||||
|
|
||||||
INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`)
|
INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`)
|
||||||
SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1
|
SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1
|
||||||
|
@ -2343,9 +2351,11 @@ INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `weekDays`)
|
||||||
(8, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'),
|
(8, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'),
|
||||||
(10, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun');
|
(10, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun');
|
||||||
|
|
||||||
INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `started`, `ended`)
|
INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `started`, `ended`, `weekDays`)
|
||||||
VALUES
|
VALUES
|
||||||
(9, 'range', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR));
|
(9, 'range', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR), 'mon'),
|
||||||
|
(9, 'range', util.VN_CURDATE(), NULL, 'tue'),
|
||||||
|
(9, 'range', NULL, util.VN_CURDATE(), 'wed');
|
||||||
|
|
||||||
INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`, `isSendMail`)
|
INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`, `isSendMail`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -26,24 +26,46 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.sync = async function(userName, password, force, options) {
|
Self.sync = async function(userName, password, force, options) {
|
||||||
|
const models = 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);
|
||||||
|
|
||||||
const models = Self.app.models;
|
if (!myOptions.transaction) {
|
||||||
const user = await models.VnUser.findOne({
|
tx = await Self.beginTransaction({});
|
||||||
fields: ['id', 'password'],
|
myOptions.transaction = tx;
|
||||||
where: {name: userName}
|
};
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
if (user && password && !await user.hasPassword(password))
|
try {
|
||||||
throw new ForbiddenError('Wrong password');
|
const user = await models.VnUser.findOne({
|
||||||
|
fields: ['id', 'password'],
|
||||||
|
where: {name: userName}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
const isSync = !await models.UserSync.exists(userName, myOptions);
|
if (user && password && !await user.hasPassword(password))
|
||||||
|
throw new ForbiddenError('Wrong password');
|
||||||
|
|
||||||
if (!force && isSync && user) return;
|
const isSync = !await models.UserSync.exists(userName, myOptions);
|
||||||
await models.AccountConfig.syncUser(userName, password);
|
|
||||||
await models.UserSync.destroyById(userName, myOptions);
|
if (!force && isSync && user) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Self.rawSql(`
|
||||||
|
SELECT id
|
||||||
|
FROM account.user
|
||||||
|
WHERE id = ?
|
||||||
|
FOR UPDATE`, [user.id], myOptions);
|
||||||
|
|
||||||
|
await models.AccountConfig.syncUser(userName, password);
|
||||||
|
await models.UserSync.destroyById(userName, myOptions);
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
} catch (err) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,7 +25,15 @@
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"ip": {
|
"ip": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"userName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"owner": {
|
||||||
|
"type": "boolean",
|
||||||
|
"required": true,
|
||||||
|
"default": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
|
@ -112,7 +112,7 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
relation: 'taxTypeSage',
|
relation: 'taxTypeSage',
|
||||||
scope: {
|
scope: {
|
||||||
fields: ['vat']
|
fields: ['vat', 'rate']
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,7 +151,7 @@ describe('SalesMonitor salesFilter()', () => {
|
||||||
const result = await models.SalesMonitor.salesFilter(ctx, filter, options);
|
const result = await models.SalesMonitor.salesFilter(ctx, filter, options);
|
||||||
const firstRow = result[0];
|
const firstRow = result[0];
|
||||||
|
|
||||||
expect(result.length).toEqual(15);
|
expect(result.length).toEqual(12);
|
||||||
expect(firstRow.alertLevel).not.toEqual(0);
|
expect(firstRow.alertLevel).not.toEqual(0);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
|
|
@ -3,99 +3,101 @@ const buildFilter = require('vn-loopback/util/filter').buildFilter;
|
||||||
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('getExternalCmrs', {
|
Self.remoteMethod('getExternalCmrs', {
|
||||||
description: 'Returns an array of external cmrs',
|
description: 'Returns an array of external cmrs',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'filter',
|
arg: 'filter',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'cmrFk',
|
arg: 'cmrFk',
|
||||||
type: 'integer',
|
type: 'integer',
|
||||||
description: 'Searchs the route by id',
|
description: 'Searchs the route by id',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'ticketFk',
|
arg: 'ticketFk',
|
||||||
type: 'integer',
|
type: 'integer',
|
||||||
description: 'The worker id',
|
description: 'The worker id',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'routeFk',
|
arg: 'routeFk',
|
||||||
type: 'integer',
|
type: 'integer',
|
||||||
description: 'The route id',
|
description: 'The route id',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'country',
|
arg: 'country',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'The agencyMode id',
|
description: 'The agencyMode id',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'clientFk',
|
arg: 'clientFk',
|
||||||
type: 'integer',
|
type: 'integer',
|
||||||
description: 'The vehicle id',
|
description: 'The vehicle id',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'hasCmrDms',
|
arg: 'hasCmrDms',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
description: 'The vehicle id',
|
description: 'The vehicle id',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'shipped',
|
arg: 'shipped',
|
||||||
type: 'date',
|
type: 'date',
|
||||||
description: 'The to date filter',
|
description: 'The to date filter',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
type: ['object'],
|
type: ['object'],
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
path: `/getExternalCmrs`,
|
path: `/getExternalCmrs`,
|
||||||
verb: 'GET'
|
verb: 'GET'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getExternalCmrs = async(
|
Self.getExternalCmrs = async(
|
||||||
filter,
|
filter,
|
||||||
cmrFk,
|
cmrFk,
|
||||||
ticketFk,
|
ticketFk,
|
||||||
routeFk,
|
routeFk,
|
||||||
country,
|
country,
|
||||||
clientFk,
|
clientFk,
|
||||||
hasCmrDms,
|
hasCmrDms,
|
||||||
shipped,
|
shipped,
|
||||||
options
|
options
|
||||||
) => {
|
) => {
|
||||||
const params = {
|
const params = {
|
||||||
cmrFk,
|
cmrFk,
|
||||||
ticketFk,
|
ticketFk,
|
||||||
routeFk,
|
routeFk,
|
||||||
country,
|
country,
|
||||||
clientFk,
|
clientFk,
|
||||||
hasCmrDms,
|
hasCmrDms,
|
||||||
shipped,
|
shipped,
|
||||||
};
|
};
|
||||||
const conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
|
|
||||||
let where = buildFilter(params, (param, value) => {return {[param]: value}});
|
let where = buildFilter(params, (param, value) => {
|
||||||
filter = mergeFilters(filter, {where});
|
return {[param]: value};
|
||||||
|
});
|
||||||
|
filter = mergeFilters(filter, {where});
|
||||||
|
|
||||||
if (!filter.where) {
|
if (!filter.where) {
|
||||||
const yesterday = new Date();
|
const yesterday = new Date();
|
||||||
yesterday.setDate(yesterday.getDate() - 1);
|
yesterday.setDate(yesterday.getDate() - 1);
|
||||||
filter.where = {'shipped': yesterday.toISOString().split('T')[0]}
|
filter.where = {'shipped': yesterday.toISOString().split('T')[0]};
|
||||||
}
|
}
|
||||||
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
let stmts = [];
|
let stmts = [];
|
||||||
const stmt = new ParameterizedSQL(`
|
const stmt = new ParameterizedSQL(`
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM (
|
FROM (
|
||||||
SELECT t.cmrFk,
|
SELECT t.cmrFk,
|
||||||
|
@ -129,13 +131,13 @@ module.exports = Self => {
|
||||||
AND dm.code = 'DELIVERY'
|
AND dm.code = 'DELIVERY'
|
||||||
AND t.cmrFk
|
AND t.cmrFk
|
||||||
) sub
|
) sub
|
||||||
`);
|
`);
|
||||||
|
|
||||||
stmt.merge(conn.makeSuffix(filter));
|
stmt.merge(conn.makeSuffix(filter));
|
||||||
const itemsIndex = stmts.push(stmt) - 1;
|
const itemsIndex = stmts.push(stmt) - 1;
|
||||||
|
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
const result = await conn.executeStmt(sql);
|
const result = await conn.executeStmt(sql);
|
||||||
return itemsIndex === 0 ? result : result[itemsIndex];
|
return itemsIndex === 0 ? result : result[itemsIndex];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -63,7 +63,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
const isAvailable = itemStock.available > 0;
|
const isAvailable = itemStock.available > 0;
|
||||||
|
|
||||||
if (!isAvailable)
|
if (!isAvailable || !ctx.args.quantity)
|
||||||
throw new UserError(`This item is not available`);
|
throw new UserError(`This item is not available`);
|
||||||
|
|
||||||
if (request.saleFk)
|
if (request.saleFk)
|
||||||
|
|
|
@ -68,7 +68,7 @@ describe('ticket filter()', () => {
|
||||||
const filter = {};
|
const filter = {};
|
||||||
const result = await models.Ticket.filter(ctx, filter, options);
|
const result = await models.Ticket.filter(ctx, filter, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(9);
|
expect(result.length).toEqual(6);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -141,7 +141,6 @@ describe('ticket filter()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the tickets that are not pending', async() => {
|
it('should return the tickets that are not pending', async() => {
|
||||||
pending('#6010 test intermitente');
|
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -9,7 +9,7 @@ describe('ticket getSalesPersonMana()', () => {
|
||||||
|
|
||||||
const mana = await models.Ticket.getSalesPersonMana(1, options);
|
const mana = await models.Ticket.getSalesPersonMana(1, options);
|
||||||
|
|
||||||
expect(mana).toEqual(73);
|
expect(mana).toEqual(124);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -202,9 +202,9 @@ export default class Controller extends Section {
|
||||||
if (!ticket.landed) {
|
if (!ticket.landed) {
|
||||||
const newLanded = await this.getLanded({
|
const newLanded = await this.getLanded({
|
||||||
shipped: this.$.model.userParams.dateToAdvance,
|
shipped: this.$.model.userParams.dateToAdvance,
|
||||||
addressFk: ticket.addressFk,
|
addressFk: ticket.futureAddressFk,
|
||||||
agencyModeFk: ticket.agencyModeFk,
|
agencyModeFk: ticket.agencyModeFk ?? ticket.futureAgencyModeFk,
|
||||||
warehouseFk: ticket.warehouseFk
|
warehouseFk: ticket.futureWarehouseFk
|
||||||
});
|
});
|
||||||
if (!newLanded)
|
if (!newLanded)
|
||||||
throw new Error(this.$t(`No delivery zone available for this landing date`));
|
throw new Error(this.$t(`No delivery zone available for this landing date`));
|
||||||
|
@ -213,13 +213,13 @@ export default class Controller extends Section {
|
||||||
ticket.zoneFk = newLanded.zoneFk;
|
ticket.zoneFk = newLanded.zoneFk;
|
||||||
}
|
}
|
||||||
const params = {
|
const params = {
|
||||||
clientFk: ticket.clientFk,
|
clientFk: ticket.futureClientFk,
|
||||||
nickname: ticket.nickname,
|
nickname: ticket.nickname,
|
||||||
agencyModeFk: ticket.agencyModeFk ?? ticket.futureAgencyModeFk,
|
agencyModeFk: ticket.agencyModeFk ?? ticket.futureAgencyModeFk,
|
||||||
addressFk: ticket.addressFk,
|
addressFk: ticket.futureAddressFk,
|
||||||
zoneFk: ticket.zoneFk ?? ticket.futureZoneFk,
|
zoneFk: ticket.zoneFk ?? ticket.futureZoneFk,
|
||||||
warehouseFk: ticket.warehouseFk,
|
warehouseFk: ticket.futureWarehouseFk,
|
||||||
companyFk: ticket.companyFk,
|
companyFk: ticket.futureCompanyFk,
|
||||||
shipped: this.$.model.userParams.dateToAdvance,
|
shipped: this.$.model.userParams.dateToAdvance,
|
||||||
landed: ticket.landed,
|
landed: ticket.landed,
|
||||||
isDeleted: false,
|
isDeleted: false,
|
||||||
|
|
|
@ -111,8 +111,10 @@ class Controller extends Section {
|
||||||
dayIndex.setDate(dayIndex.getDate() + 1);
|
dayIndex.setDate(dayIndex.getDate() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fetchHours();
|
if (this.worker) {
|
||||||
this.getWeekData();
|
this.fetchHours();
|
||||||
|
this.getWeekData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set weekTotalHours(totalHours) {
|
set weekTotalHours(totalHours) {
|
||||||
|
@ -171,8 +173,6 @@ class Controller extends Section {
|
||||||
]}
|
]}
|
||||||
};
|
};
|
||||||
this.$.model.applyFilter(filter, params).then(() => {
|
this.$.model.applyFilter(filter, params).then(() => {
|
||||||
if (!this.card.hasWorkCenter) return;
|
|
||||||
|
|
||||||
this.getWorkedHours(this.started, this.ended);
|
this.getWorkedHours(this.started, this.ended);
|
||||||
this.getAbsences();
|
this.getAbsences();
|
||||||
});
|
});
|
||||||
|
|
|
@ -35,44 +35,39 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
query = `
|
ended = simpleDate(ended);
|
||||||
SELECT *
|
started = simpleDate(started);
|
||||||
FROM vn.zoneEvent
|
|
||||||
WHERE zoneFk = ?
|
|
||||||
AND ((type = 'indefinitely')
|
|
||||||
OR (type = 'day' AND dated BETWEEN ? AND ?)
|
|
||||||
OR (type = 'range'
|
|
||||||
AND (
|
|
||||||
(started BETWEEN ? AND ?)
|
|
||||||
OR
|
|
||||||
(ended BETWEEN ? AND ?)
|
|
||||||
OR
|
|
||||||
(started <= ? AND ended >= ?)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
ORDER BY type='indefinitely' DESC, type='range' DESC, type='day' DESC;`;
|
|
||||||
const events = await Self.rawSql(query,
|
|
||||||
[zoneFk, started, ended, started, ended, started, ended, started, ended], myOptions);
|
|
||||||
|
|
||||||
query = `
|
query = `
|
||||||
SELECT e.*
|
SELECT *
|
||||||
FROM vn.zoneExclusion e
|
FROM vn.zoneEvent
|
||||||
LEFT JOIN vn.zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id
|
WHERE zoneFk = ?
|
||||||
WHERE e.zoneFk = ?
|
AND (IFNULL(started, ?) <= ? AND IFNULL(ended,?) >= ?)
|
||||||
AND e.dated BETWEEN ? AND ?
|
ORDER BY type='indefinitely' DESC, type='range' DESC, type='day' DESC;`;
|
||||||
AND eg.zoneExclusionFk IS NULL;`;
|
const events = await Self.rawSql(query,
|
||||||
|
[zoneFk, started, ended, ended, started], myOptions);
|
||||||
|
|
||||||
|
query = `
|
||||||
|
SELECT e.*
|
||||||
|
FROM vn.zoneExclusion e
|
||||||
|
LEFT JOIN vn.zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id
|
||||||
|
WHERE e.zoneFk = ?
|
||||||
|
AND e.dated BETWEEN ? AND ?
|
||||||
|
AND eg.zoneExclusionFk IS NULL;`;
|
||||||
const exclusions = await Self.rawSql(query, [zoneFk, started, ended], myOptions);
|
const exclusions = await Self.rawSql(query, [zoneFk, started, ended], myOptions);
|
||||||
|
|
||||||
query = `
|
query = `
|
||||||
SELECT eg.*, e.zoneFk, e.dated, e.created, e.userFk
|
SELECT eg.*, e.zoneFk, e.dated, e.created, e.userFk
|
||||||
FROM vn.zoneExclusion e
|
FROM vn.zoneExclusion e
|
||||||
LEFT JOIN vn.zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id
|
LEFT JOIN vn.zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id
|
||||||
WHERE e.zoneFk = ?
|
WHERE e.zoneFk = ?
|
||||||
AND e.dated BETWEEN ? AND ?
|
AND e.dated BETWEEN ? AND ?
|
||||||
AND eg.zoneExclusionFk IS NOT NULL;`;
|
AND eg.zoneExclusionFk IS NOT NULL;`;
|
||||||
const geoExclusions = await Self.rawSql(query, [zoneFk, started, ended], myOptions);
|
const geoExclusions = await Self.rawSql(query, [zoneFk, started, ended], myOptions);
|
||||||
|
|
||||||
return {events, exclusions, geoExclusions};
|
return {events, exclusions, geoExclusions};
|
||||||
};
|
};
|
||||||
|
function simpleDate(date) {
|
||||||
|
return date.toISOString().split('T')[0];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,7 +30,7 @@ describe('zone getEventsFiltered()', () => {
|
||||||
|
|
||||||
const result = await models.Zone.getEventsFiltered(9, today, today, options);
|
const result = await models.Zone.getEventsFiltered(9, today, today, options);
|
||||||
|
|
||||||
expect(result.events.length).toEqual(1);
|
expect(result.events.length).toEqual(3);
|
||||||
expect(result.exclusions.length).toEqual(0);
|
expect(result.exclusions.length).toEqual(0);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
@ -47,11 +47,12 @@ describe('zone getEventsFiltered()', () => {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const date = Date.vnNew();
|
const date = Date.vnNew();
|
||||||
date.setFullYear(date.getFullYear() - 2);
|
date.setFullYear(date.getFullYear() - 2);
|
||||||
const dateTomorrow = new Date(date.setDate(date.getDate() + 1));
|
const dateTomorrow = new Date(date);
|
||||||
|
dateTomorrow.setDate(dateTomorrow.getDate() + 1);
|
||||||
|
|
||||||
const result = await models.Zone.getEventsFiltered(9, date, dateTomorrow, options);
|
const result = await models.Zone.getEventsFiltered(9, date, dateTomorrow, options);
|
||||||
|
|
||||||
expect(result.events.length).toEqual(0);
|
expect(result.events.length).toEqual(1);
|
||||||
expect(result.exclusions.length).toEqual(0);
|
expect(result.exclusions.length).toEqual(0);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "salix-back",
|
"name": "salix-back",
|
||||||
"version": "23.50.01",
|
"version": "23.52.01",
|
||||||
"author": "Verdnatura Levante SL",
|
"author": "Verdnatura Levante SL",
|
||||||
"description": "Salix backend",
|
"description": "Salix backend",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
|
|
@ -20,7 +20,7 @@ SELECT
|
||||||
u.nickName salesPersonName,
|
u.nickName salesPersonName,
|
||||||
ipkg.itemPackingTypes
|
ipkg.itemPackingTypes
|
||||||
FROM route r
|
FROM route r
|
||||||
LEFT JOIN ticket t ON t.routeFk = r.id
|
JOIN ticket t ON t.routeFk = r.id
|
||||||
LEFT JOIN address a ON a.id = t.addressFk
|
LEFT JOIN address a ON a.id = t.addressFk
|
||||||
LEFT JOIN client c ON c.id = t.clientFk
|
LEFT JOIN client c ON c.id = t.clientFk
|
||||||
LEFT JOIN worker w ON w.id = client_getSalesPerson(t.clientFk, CURDATE())
|
LEFT JOIN worker w ON w.id = client_getSalesPerson(t.clientFk, CURDATE())
|
||||||
|
|
Loading…
Reference in New Issue