Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 3472-supplier_summary
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-01-12 14:56:34 +01:00
commit 6f7c1b6a46
18 changed files with 2735 additions and 23606 deletions

View File

@ -120,7 +120,7 @@ module.exports = Self => {
}
const defaultOptions = {
body: params
form: params
};
if (options) Object.assign(defaultOptions, options);

View File

@ -0,0 +1,5 @@
ALTER TABLE `vn`.`smsConfig` ADD apiKey varchar(50) NULL;
ALTER TABLE `vn`.`smsConfig` CHANGE `user` user__ varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
ALTER TABLE `vn`.`smsConfig` CHANGE password password__ varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
ALTER TABLE `vn`.`sms` MODIFY COLUMN statusCode smallint(9) DEFAULT 0 NULL;
ALTER TABLE `vn`.`sms` MODIFY COLUMN status varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT 'OK' NULL;

View File

@ -0,0 +1,7 @@
UPDATE `vn`.`smsConfig`
SET `uri` = 'https://api.gateway360.com/api/3.0/sms/send'
WHERE `id` = 1;
UPDATE `vn`.`smsConfig`
SET `apiKey` = '5715476da95b46d686a5a255e6459523'
WHERE `id` = 1;

View File

@ -1906,9 +1906,9 @@ INSERT INTO `postgresql`.`calendar_employee` (`business_id`, `calendar_state_id`
(1107, 1, IF(MONTH(CURDATE()) >= 1 AND DAY(CURDATE()) > 20, DATE_ADD(CURDATE(), INTERVAL -14 DAY), DATE_ADD(CURDATE(), INTERVAL 9 DAY))),
(1107, 2, IF(MONTH(CURDATE()) >= 1 AND DAY(CURDATE()) > 20, DATE_ADD(CURDATE(), INTERVAL -15 DAY), DATE_ADD(CURDATE(), INTERVAL 7 DAY)));
INSERT INTO `vn`.`smsConfig` (`id`, `uri`, `title`)
INSERT INTO `vn`.`smsConfig` (`id`, `uri`, `title`, `apiKey`)
VALUES
('1', 'https://websms.xtratelecom.es/api_php/server.wsdl', 'Verdnatura');
('1', 'https://api.gateway360.com/api/3.0/sms/send', 'Verdnatura', '5715476da95b46d686a5a255e6459523');
INSERT INTO `vn`.`sharingClient`(`id`, `workerFk`, `started`, `ended`, `clientFk`)
VALUES

View File

@ -215,5 +215,6 @@
"You can't create a claim from a ticket delivered more than seven days ago": "No puedes crear una reclamación de un ticket entregado hace más de siete días",
"The worker has hours recorded that day": "El trabajador tiene horas fichadas ese día",
"The worker has a marked absence that day": "El trabajador tiene marcada una ausencia ese día",
"You can not modify is pay method checked": "No se puede modificar el campo método de pago validado"
}
"You can not modify is pay method checked": "No se puede modificar el campo método de pago validado",
"Can't transfer claimed sales": "No puedes transferir lineas reclamadas"
}

View File

@ -1,5 +1,4 @@
const soap = require('soap');
const xmlParser = require('xml2js').parseString;
const got = require('got');
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
@ -35,57 +34,48 @@ module.exports = Self => {
Self.send = async(ctx, destinationFk, destination, message) => {
const userId = ctx.req.accessToken.userId;
const smsConfig = await Self.app.models.SmsConfig.findOne();
const soapClient = await soap.createClientAsync(smsConfig.uri);
if (destination.length == 9) {
const spainPrefix = '0034';
destination = spainPrefix + destination;
}
const params = {
user: smsConfig.user,
pass: smsConfig.password,
src: smsConfig.title,
dst: destination,
msg: message
api_key: smsConfig.apiKey,
messages: [{
from: smsConfig.title,
to: destination,
text: message
}]
};
let xmlResponse;
let xmlResult;
let xmlParsed;
let status;
let response;
try {
if (process.env.NODE_ENV !== 'production') {
status = {
codigo: [200],
descripcion: ['Fake response']
};
} else {
[xmlResponse] = await soapClient.sendSMSAsync(params);
xmlResult = xmlResponse.result.$value;
xmlParsed = await new Promise((resolve, reject) => {
xmlParser(xmlResult, (err, result) => {
if (err)
reject(err);
resolve(result);
});
});
[status] = xmlParsed['xtratelecom-sms-response'].sms;
}
if (process.env.NODE_ENV !== 'production')
params.fake = 1;
const jsonTest = {
json: params
};
response = await got.post(smsConfig.uri, jsonTest).json();
} catch (e) {
console.error(e);
}
const statusCode = status.codigo[0];
const statusDescription = status.descripcion[0];
const [result] = response.result;
const error = result.error_id;
const newSms = {
senderFk: userId,
destinationFk: destinationFk || null,
destination: destination,
message: message,
statusCode: statusCode,
status: statusDescription
status: error
};
const sms = await Self.create(newSms);
if (statusCode != 200)
if (error)
throw new UserError(`We weren't able to send this SMS`);
return sms;

View File

@ -1,14 +1,10 @@
const app = require('vn-loopback/server/server');
const soap = require('soap');
describe('sms send()', () => {
it('should return the expected message and status code', async() => {
const code = 200;
spyOn(soap, 'createClientAsync').and.returnValue('a so fake client');
let ctx = {req: {accessToken: {userId: 1}}};
let result = await app.models.Sms.send(ctx, 1105, 'destination', 'My SMS Body');
it('should not return status error', async() => {
const ctx = {req: {accessToken: {userId: 1}}};
const result = await app.models.Sms.send(ctx, 1105, '123456789', 'My SMS Body');
expect(result.statusCode).toEqual(code);
expect(result.status).toContain('Fake response');
expect(result.status).toBeUndefined();
});
});

View File

@ -284,7 +284,7 @@ module.exports = Self => {
replyTo: worker.email
};
await got.get(`${origin}/api/email/payment-update`, {
query: params
searchParams: params
});
}

View File

@ -16,10 +16,7 @@
"uri": {
"type": "String"
},
"user": {
"type": "String"
},
"password": {
"apiKey": {
"type": "String"
},
"title": {

View File

@ -26,8 +26,7 @@
"required": true
},
"statusCode": {
"type": "Number",
"required": true
"type": "Number"
},
"status": {
"type": "String"

View File

@ -58,7 +58,7 @@ module.exports = Self => {
}, myOptions);
const response = got.stream(`${origin}/api/report/invoice`, {
query: {
searchParams: {
authorization: auth.id,
invoiceId: id
}

View File

@ -10,7 +10,12 @@
],
"card": []
},
"keybindings": [],
"keybindings": [
{
"key": "m",
"state": "monitor.index"
}
],
"routes": [
{
"url": "/monitor",

View File

@ -15,6 +15,12 @@
{"state": "order.card.line", "icon": "icon-lines"}
]
},
"keybindings": [
{
"key": "o",
"state": "order.index"
}
],
"routes": [
{
"url": "/order",

View File

@ -58,13 +58,63 @@ describe('sale transferSales()', () => {
expect(error.message).toEqual(`The sales of the receiver ticket can't be modified`);
});
it('should transfer the sales from one ticket to a new one then send them back and delete the created ticket', async() => {
it('should throw an error if any of the sales has a claim', async() => {
const tx = await models.Ticket.beginTransaction({});
let error;
try {
const options = {transaction: tx};
const ticketId = 11;
const receiverTicketId = null;
const sales = await models.Ticket.getSales(ticketId, options);
await models.Ticket.transferSales(ctx, ticketId, receiverTicketId, sales, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error.message).toEqual(`Can't transfer claimed sales`);
});
it('should be able to transfer claimed sales if the role is claimManager', async() => {
const tx = await models.Ticket.beginTransaction({});
let error;
try {
const options = {transaction: tx};
const claimManagerId = 72;
const myActiveCtx = {
accessToken: {userId: claimManagerId},
};
const myCtx = {req: myActiveCtx};
const ticketId = 11;
const receiverTicketId = null;
const sales = await models.Ticket.getSales(ticketId, options);
await models.Ticket.transferSales(myCtx, ticketId, receiverTicketId, sales, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error).toBeUndefined();
});
it('should transfer the sales from a ticket to a new one', async() => {
const tx = await models.Ticket.beginTransaction({});
try {
const options = {transaction: tx};
const formerTicketId = 11;
const formerTicketId = 22;
let createdTicketId = undefined;
let formerTicketSales = await models.Ticket.getSales(formerTicketId, options);
@ -77,23 +127,11 @@ describe('sale transferSales()', () => {
createdTicketId = createdTicket.id;
formerTicketSales = await models.Ticket.getSales(formerTicketId, options);
createdTicketSales = await models.Ticket.getSales(createdTicketId, options);
let createdTicketSales = await models.Ticket.getSales(createdTicketId, options);
expect(formerTicketSales.length).toEqual(0);
expect(createdTicketSales.length).toEqual(2);
await models.Ticket.transferSales(
ctx, createdTicketId, formerTicketId, createdTicketSales, options);
formerTicketSales = await models.Ticket.getSales(formerTicketId, options);
createdTicketSales = await models.Ticket.getSales(createdTicketId, options);
createdTicket = await models.Ticket.findById(createdTicketId, null, options);
expect(createdTicket.isDeleted).toBeTruthy();
expect(formerTicketSales.length).toEqual(2);
expect(createdTicketSales.length).toEqual(0);
await tx.rollback();
} catch (e) {
await tx.rollback();
@ -109,10 +147,9 @@ describe('sale transferSales()', () => {
try {
const options = {transaction: tx};
const currentTicket = await models.Ticket.findById(11, null, options);
const currentTicketSales = await models.Ticket.getSales(currentTicket.id, options);
const currentTicketId = 22;
const currentTicketSales = await models.Ticket.getSales(currentTicketId, options);
const currentTicketId = currentTicket.id;
const receiverTicketId = undefined;
currentTicketSales[0].quantity = 99;
@ -135,7 +172,7 @@ describe('sale transferSales()', () => {
try {
const options = {transaction: tx};
const formerTicketId = 11;
const formerTicketId = 22;
let createdTicketId = undefined;
let formerTicketSales = await models.Ticket.getSales(formerTicketId, options);
@ -143,7 +180,7 @@ describe('sale transferSales()', () => {
const completeSaleId = formerTicketSales[1].id;
let partialSaleTotalQuantity = formerTicketSales[0].quantity;
expect(partialSaleTotalQuantity).toEqual(15);
expect(partialSaleTotalQuantity).toEqual(30);
formerTicketSales[0].quantity = 1;

View File

@ -75,6 +75,13 @@ module.exports = Self => {
for (const sale of originalSales)
map.set(sale.id, sale);
const saleIds = sales.map(sale => sale.id);
const isClaimManager = await models.Account.hasRole(userId, 'claimManager');
const hasClaimedSales = await models.ClaimBeginning.findOne({where: {saleFk: {inq: saleIds}}});
if (hasClaimedSales && !isClaimManager)
throw new UserError(`Can't transfer claimed sales`);
for (const sale of sales) {
const originalSale = map.get(sale.id);
const originalSaleData = { // <-- Loopback modifies original instance on save

View File

@ -24,6 +24,12 @@
{"state": "worker.card.workerLog", "icon": "history"}
]
},
"keybindings": [
{
"key": "w",
"state": "worker.index"
}
],
"routes": [
{
"url": "/worker",

26129
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@
"bmp-js": "^0.1.0",
"compression": "^1.7.3",
"fs-extra": "^5.0.0",
"got": "^6.7.1",
"got": "^10.7.0",
"helmet": "^3.21.2",
"i18n": "^0.8.4",
"image-type": "^4.1.0",