Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 7917-freelancerRoute2
This commit is contained in:
commit
07b07611be
|
@ -27,38 +27,47 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.sendCheckingPresence = async(ctx, recipientId, message) => {
|
Self.sendCheckingPresence = async(ctx, recipientId, message) => {
|
||||||
if (!recipientId) return false;
|
|
||||||
const models = Self.app.models;
|
|
||||||
|
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
const sender = await models.VnUser.findById(userId, {fields: ['id']});
|
|
||||||
const recipient = await models.VnUser.findById(recipientId, null);
|
|
||||||
|
|
||||||
// Prevent sending messages to yourself
|
|
||||||
if (recipientId == userId) return false;
|
|
||||||
if (!recipient)
|
|
||||||
throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`);
|
|
||||||
|
|
||||||
if (!isProduction())
|
|
||||||
message = `[Test:Environment to user ${userId}] ` + message;
|
|
||||||
|
|
||||||
const chat = await models.Chat.create({
|
|
||||||
senderFk: sender.id,
|
|
||||||
recipient: `@${recipient.name}`,
|
|
||||||
dated: Date.vnNew(),
|
|
||||||
checkUserStatus: 1,
|
|
||||||
message: message,
|
|
||||||
status: 'sending',
|
|
||||||
attempts: 0
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Self.sendCheckingUserStatus(chat);
|
const models = Self.app.models;
|
||||||
await Self.updateChat(chat, 'sent');
|
const sender = await models.VnUser.findById(userId, {fields: ['id']});
|
||||||
} catch (error) {
|
const error = `Could not send message from user ${userId}`;
|
||||||
await Self.updateChat(chat, 'error', error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
if (!recipientId) throw new Error(error);
|
||||||
|
const recipient = await models.VnUser.findById(recipientId, null);
|
||||||
|
if (!recipient)
|
||||||
|
throw new Error(error);
|
||||||
|
|
||||||
|
// Prevent sending messages to yourself
|
||||||
|
if (recipientId == userId) return false;
|
||||||
|
|
||||||
|
if (!isProduction())
|
||||||
|
message = `[Test:Environment to user ${userId}] ` + message;
|
||||||
|
|
||||||
|
const chat = await models.Chat.create({
|
||||||
|
senderFk: sender.id,
|
||||||
|
recipient: `@${recipient.name}`,
|
||||||
|
dated: Date.vnNew(),
|
||||||
|
checkUserStatus: 1,
|
||||||
|
message: message,
|
||||||
|
status: 'sending',
|
||||||
|
attempts: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await Self.sendCheckingUserStatus(chat);
|
||||||
|
await Self.updateChat(chat, 'sent');
|
||||||
|
} catch (error) {
|
||||||
|
await Self.updateChat(chat, 'error', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
await Self.rawSql(`
|
||||||
|
INSERT INTO util.debug (variable, value)
|
||||||
|
VALUES ('sendCheckingPresence_error', ?)
|
||||||
|
`, [`User: ${userId}, recipient: ${recipientId}, message: ${message}, error: ${e}`]);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,10 +16,11 @@ BEGIN
|
||||||
TRUE,
|
TRUE,
|
||||||
sc.userFk,
|
sc.userFk,
|
||||||
s.id
|
s.id
|
||||||
FROM vn.sectorCollection sc
|
FROM sectorCollection sc
|
||||||
JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id
|
JOIN sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id
|
||||||
JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk
|
JOIN saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk
|
||||||
JOIN vn.state s ON s.code = 'OK PREVIOUS'
|
JOIN state s ON s.code = 'OK PREVIOUS'
|
||||||
|
JOIN itemShelvingSale iss ON iss.saleFk = sgd.saleFk
|
||||||
WHERE sc.id = vSectorCollectionFk;
|
WHERE sc.id = vSectorCollectionFk;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -211,6 +211,7 @@
|
||||||
"Name should be uppercase": "Name should be uppercase",
|
"Name should be uppercase": "Name should be uppercase",
|
||||||
"You cannot update these fields": "You cannot update these fields",
|
"You cannot update these fields": "You cannot update these fields",
|
||||||
"CountryFK cannot be empty": "Country cannot be empty",
|
"CountryFK cannot be empty": "Country cannot be empty",
|
||||||
|
"No tickets to invoice": "There are no tickets to invoice that meet the invoicing requirements",
|
||||||
"You are not allowed to modify the alias": "You are not allowed to modify the alias",
|
"You are not allowed to modify the alias": "You are not allowed to modify the alias",
|
||||||
"You already have the mailAlias": "You already have the mailAlias",
|
"You already have the mailAlias": "You already have the mailAlias",
|
||||||
"This machine is already in use.": "This machine is already in use.",
|
"This machine is already in use.": "This machine is already in use.",
|
||||||
|
|
|
@ -339,7 +339,7 @@
|
||||||
"Incorrect pin": "Pin incorrecto.",
|
"Incorrect pin": "Pin incorrecto.",
|
||||||
"You already have the mailAlias": "Ya tienes este alias de correo",
|
"You already have the mailAlias": "Ya tienes este alias de correo",
|
||||||
"The alias cant be modified": "Este alias de correo no puede ser modificado",
|
"The alias cant be modified": "Este alias de correo no puede ser modificado",
|
||||||
"No tickets to invoice": "No hay tickets para facturar",
|
"No tickets to invoice": "No hay tickets para facturar que cumplan los requisitos de facturación",
|
||||||
"this warehouse has not dms": "El Almacén no acepta documentos",
|
"this warehouse has not dms": "El Almacén no acepta documentos",
|
||||||
"This ticket already has a cmr saved": "Este ticket ya tiene un cmr guardado",
|
"This ticket already has a cmr saved": "Este ticket ya tiene un cmr guardado",
|
||||||
"Name should be uppercase": "El nombre debe ir en mayúscula",
|
"Name should be uppercase": "El nombre debe ir en mayúscula",
|
||||||
|
|
|
@ -339,7 +339,7 @@
|
||||||
"Incorrect pin": "Pin incorrect.",
|
"Incorrect pin": "Pin incorrect.",
|
||||||
"You already have the mailAlias": "Vous avez déjà cet alias de courrier",
|
"You already have the mailAlias": "Vous avez déjà cet alias de courrier",
|
||||||
"The alias cant be modified": "Cet alias de courrier ne peut pas être modifié",
|
"The alias cant be modified": "Cet alias de courrier ne peut pas être modifié",
|
||||||
"No tickets to invoice": "Pas de tickets à facturer",
|
"No tickets to invoice": "Il n'y a pas de tickets à facturer qui répondent aux exigences de facturation",
|
||||||
"this warehouse has not dms": "L'entrepôt n'accepte pas les documents",
|
"this warehouse has not dms": "L'entrepôt n'accepte pas les documents",
|
||||||
"This ticket already has a cmr saved": "Ce ticket a déjà un cmr enregistré",
|
"This ticket already has a cmr saved": "Ce ticket a déjà un cmr enregistré",
|
||||||
"Name should be uppercase": "Le nom doit être en majuscules",
|
"Name should be uppercase": "Le nom doit être en majuscules",
|
||||||
|
|
|
@ -339,7 +339,7 @@
|
||||||
"Incorrect pin": "PIN incorreto.",
|
"Incorrect pin": "PIN incorreto.",
|
||||||
"You already have the mailAlias": "Você já tem o alias de e-mail",
|
"You already have the mailAlias": "Você já tem o alias de e-mail",
|
||||||
"The alias cant be modified": "O alias não pode ser modificado",
|
"The alias cant be modified": "O alias não pode ser modificado",
|
||||||
"No tickets to invoice": "Não há tickets para faturar",
|
"No tickets to invoice": "Não há bilhetes para faturar que atendam aos requisitos de faturamento",
|
||||||
"this warehouse has not dms": "Este armazém não tem DMS",
|
"this warehouse has not dms": "Este armazém não tem DMS",
|
||||||
"This ticket already has a cmr saved": "Este ticket já tem um CMR salvo",
|
"This ticket already has a cmr saved": "Este ticket já tem um CMR salvo",
|
||||||
"Name should be uppercase": "O nome deve estar em maiúsculas",
|
"Name should be uppercase": "O nome deve estar em maiúsculas",
|
||||||
|
|
|
@ -49,12 +49,6 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const clientCanBeInvoiced =
|
|
||||||
await Self.app.models.Client.canBeInvoiced(clientId, companyFk, myOptions);
|
|
||||||
|
|
||||||
if (!clientCanBeInvoiced)
|
|
||||||
throw new UserError(`This client can't be invoiced`);
|
|
||||||
|
|
||||||
const vIsAllInvoiceable = false;
|
const vIsAllInvoiceable = false;
|
||||||
await Self.rawSql('CALL ticketPackaging_add(?, ?, ?, ?)', [
|
await Self.rawSql('CALL ticketPackaging_add(?, ?, ?, ?)', [
|
||||||
clientId,
|
clientId,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('InvoiceOut clientsToInvoice()', () => {
|
describe('InvoiceOut clientsToInvoice()', () => {
|
||||||
const userId = 1;
|
const userId = 1;
|
||||||
|
@ -20,6 +21,21 @@ describe('InvoiceOut clientsToInvoice()', () => {
|
||||||
headers: {origin: 'http://localhost'}
|
headers: {origin: 'http://localhost'}
|
||||||
};
|
};
|
||||||
const ctx = {req: activeCtx};
|
const ctx = {req: activeCtx};
|
||||||
|
let tx;
|
||||||
|
let options;
|
||||||
|
|
||||||
|
beforeEach(async() => {
|
||||||
|
LoopBackContext.getCurrentContext = () => ({
|
||||||
|
active: activeCtx,
|
||||||
|
});
|
||||||
|
|
||||||
|
tx = await models.InvoiceOut.beginTransaction({});
|
||||||
|
options = {transaction: tx};
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async() => {
|
||||||
|
await tx.rollback();
|
||||||
|
});
|
||||||
|
|
||||||
it('should return a list of clients to invoice', async() => {
|
it('should return a list of clients to invoice', async() => {
|
||||||
spyOn(models.InvoiceOut, 'rawSql').and.callFake(query => {
|
spyOn(models.InvoiceOut, 'rawSql').and.callFake(query => {
|
||||||
|
@ -37,24 +53,14 @@ describe('InvoiceOut clientsToInvoice()', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const tx = await models.InvoiceOut.beginTransaction({});
|
const addresses = await models.InvoiceOut.clientsToInvoice(
|
||||||
const options = {transaction: tx};
|
ctx, clientId, invoiceDate, maxShipped, companyFk, options);
|
||||||
|
|
||||||
try {
|
expect(addresses.length).toBeGreaterThan(0);
|
||||||
const addresses = await models.InvoiceOut.clientsToInvoice(
|
expect(addresses[0].clientId).toBe(clientId);
|
||||||
ctx, clientId, invoiceDate, maxShipped, companyFk, options);
|
expect(addresses[0].clientName).toBe('Test Client');
|
||||||
|
expect(addresses[0].id).toBe(1);
|
||||||
expect(addresses.length).toBeGreaterThan(0);
|
expect(addresses[0].nickname).toBe('Address 1');
|
||||||
expect(addresses[0].clientId).toBe(clientId);
|
|
||||||
expect(addresses[0].clientName).toBe('Test Client');
|
|
||||||
expect(addresses[0].id).toBe(1);
|
|
||||||
expect(addresses[0].nickname).toBe('Address 1');
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle errors and rollback transaction', async() => {
|
it('should handle errors and rollback transaction', async() => {
|
||||||
|
@ -62,14 +68,20 @@ describe('InvoiceOut clientsToInvoice()', () => {
|
||||||
return Promise.reject(new Error('Test Error'));
|
return Promise.reject(new Error('Test Error'));
|
||||||
});
|
});
|
||||||
|
|
||||||
const tx = await models.InvoiceOut.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await models.InvoiceOut.clientsToInvoice(ctx, clientId, invoiceDate, maxShipped, companyFk, options);
|
await models.InvoiceOut.clientsToInvoice(ctx, clientId, invoiceDate, maxShipped, companyFk, options);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e.message).toBe('Test Error');
|
expect(e.message).toBe('Test Error');
|
||||||
await tx.rollback();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return all list', async() => {
|
||||||
|
const minShipped = Date.vnNew();
|
||||||
|
minShipped.setFullYear(maxShipped.getFullYear() - 1);
|
||||||
|
|
||||||
|
const toInvoice = await models.InvoiceOut.clientsToInvoice(
|
||||||
|
ctx, null, invoiceDate, maxShipped, companyFk, options);
|
||||||
|
|
||||||
|
expect(toInvoice).toBeDefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue