Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2692-add_advanced_search_engine2
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
db5e786235
|
@ -0,0 +1,39 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('notifyIssues', {
|
||||||
|
description: 'Notifies new urgent issues',
|
||||||
|
accessType: 'READ',
|
||||||
|
returns: {
|
||||||
|
type: 'Object',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/notifyIssues`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.notifyIssues = async ctx => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const $t = ctx.req.__; // $translate
|
||||||
|
const [urgentIssue] = await Self.rawSql(`
|
||||||
|
SELECT * FROM managedesktop.vn_workOrderInmediata LIMIT 1
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (!urgentIssue) return;
|
||||||
|
|
||||||
|
const message = $t(`There's a new urgent ticket`, {
|
||||||
|
title: urgentIssue.title,
|
||||||
|
issueId: urgentIssue.workOrderId
|
||||||
|
});
|
||||||
|
|
||||||
|
const department = await models.Department.findOne({
|
||||||
|
where: {code: 'IT'}
|
||||||
|
});
|
||||||
|
const channelName = department && department.chatName;
|
||||||
|
|
||||||
|
if (channelName)
|
||||||
|
return Self.send(ctx, `#${channelName}`, `@all ➔ ${message}`);
|
||||||
|
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,38 @@
|
||||||
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
describe('Chat notifyIssue()', () => {
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}};
|
||||||
|
ctx.req.__ = value => {
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
const chatModel = app.models.Chat;
|
||||||
|
const departmentId = 31;
|
||||||
|
|
||||||
|
it(`should not call to the send() method and neither return a response`, async() => {
|
||||||
|
spyOn(chatModel, 'send').and.callThrough();
|
||||||
|
spyOn(chatModel, 'rawSql').and.returnValue([]);
|
||||||
|
|
||||||
|
const response = await chatModel.notifyIssues(ctx);
|
||||||
|
|
||||||
|
expect(chatModel.send).not.toHaveBeenCalled();
|
||||||
|
expect(response).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should return a response calling the send() method`, async() => {
|
||||||
|
spyOn(chatModel, 'send').and.callThrough();
|
||||||
|
spyOn(chatModel, 'rawSql').and.returnValue([{title: 'Issue title'}]);
|
||||||
|
|
||||||
|
const department = await app.models.Department.findById(departmentId);
|
||||||
|
let orgChatName = department.chatName;
|
||||||
|
await department.updateAttribute('chatName', 'IT');
|
||||||
|
|
||||||
|
const response = await chatModel.notifyIssues(ctx);
|
||||||
|
|
||||||
|
expect(response.statusCode).toEqual(200);
|
||||||
|
expect(response.message).toEqual('Fake notification sent');
|
||||||
|
expect(chatModel.send).toHaveBeenCalledWith(ctx, '#IT', `@all ➔ There's a new urgent ticket`);
|
||||||
|
|
||||||
|
// restores
|
||||||
|
await department.updateAttribute('chatName', orgChatName);
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,6 +1,6 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('chat send()', () => {
|
describe('Chat send()', () => {
|
||||||
it('should return a "Fake notification sent" as response', async() => {
|
it('should return a "Fake notification sent" as response', async() => {
|
||||||
let ctx = {req: {accessToken: {userId: 1}}};
|
let ctx = {req: {accessToken: {userId: 1}}};
|
||||||
let response = await app.models.Chat.send(ctx, '@salesPerson', 'I changed something');
|
let response = await app.models.Chat.send(ctx, '@salesPerson', 'I changed something');
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('chat sendCheckingPresence()', () => {
|
describe('Chat sendCheckingPresence()', () => {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
today.setHours(6, 0);
|
today.setHours(6, 0);
|
||||||
const ctx = {req: {accessToken: {userId: 1}}};
|
const ctx = {req: {accessToken: {userId: 1}}};
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
require('../methods/chat/send')(Self);
|
require('../methods/chat/send')(Self);
|
||||||
require('../methods/chat/sendCheckingPresence')(Self);
|
require('../methods/chat/sendCheckingPresence')(Self);
|
||||||
|
require('../methods/chat/notifyIssues')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
ALTER TABLE `vn`.`department`
|
||||||
|
ADD code VARCHAR(45) NULL AFTER id;
|
||||||
|
|
||||||
|
UPDATE `vn`.`department` t SET t.code = 'IT', t.chatName = 'informatica-cau' WHERE t.id = 31;
|
|
@ -90,5 +90,6 @@
|
||||||
"A travel with this data already exists": "A travel with this data already exists",
|
"A travel with this data already exists": "A travel with this data already exists",
|
||||||
"The observation type can't be repeated": "The observation type can't be repeated",
|
"The observation type can't be repeated": "The observation type can't be repeated",
|
||||||
"New ticket request has been created with price": "New ticket request has been created '{{description}}' for day <strong>{{shipped}}</strong>, with a quantity of <strong>{{quantity}}</strong> and a price of <strong>{{price}} €</strong>",
|
"New ticket request has been created with price": "New ticket request has been created '{{description}}' for day <strong>{{shipped}}</strong>, with a quantity of <strong>{{quantity}}</strong> and a price of <strong>{{price}} €</strong>",
|
||||||
"New ticket request has been created": "New ticket request has been created '{{description}}' for day <strong>{{shipped}}</strong>, with a quantity of <strong>{{quantity}}</strong>"
|
"New ticket request has been created": "New ticket request has been created '{{description}}' for day <strong>{{shipped}}</strong>, with a quantity of <strong>{{quantity}}</strong>",
|
||||||
|
"There's a new urgent ticket": "There's a new urgent ticket: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})"
|
||||||
}
|
}
|
|
@ -170,5 +170,6 @@
|
||||||
"Invalid account": "Cuenta inválida",
|
"Invalid account": "Cuenta inválida",
|
||||||
"New ticket request has been created with price": "Se ha creado una nueva petición de compra '{{description}}' para el día <strong>{{shipped}}</strong>, con una cantidad de <strong>{{quantity}}</strong> y un precio de <strong>{{price}} €</strong>",
|
"New ticket request has been created with price": "Se ha creado una nueva petición de compra '{{description}}' para el día <strong>{{shipped}}</strong>, con una cantidad de <strong>{{quantity}}</strong> y un precio de <strong>{{price}} €</strong>",
|
||||||
"New ticket request has been created": "Se ha creado una nueva petición de compra '{{description}}' para el día <strong>{{shipped}}</strong>, con una cantidad de <strong>{{quantity}}</strong>",
|
"New ticket request has been created": "Se ha creado una nueva petición de compra '{{description}}' para el día <strong>{{shipped}}</strong>, con una cantidad de <strong>{{quantity}}</strong>",
|
||||||
"That item doesn't exists": "Ese artículo no existe"
|
"That item doesn't exists": "Ese artículo no existe",
|
||||||
|
"There's a new urgent ticket": "Hay un nuevo ticket urgente: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})"
|
||||||
}
|
}
|
|
@ -86,16 +86,15 @@ class Controller extends Section {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
showDeleteConfirm(index) {
|
showDeleteConfirm($index) {
|
||||||
this.sale = this.salesClaimed[index];
|
this.claimedIndex = $index;
|
||||||
this.$.confirm.show();
|
this.$.confirm.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteClaimedSale() {
|
deleteClaimedSale() {
|
||||||
let query = `ClaimBeginnings/${this.sale.id}`;
|
this.$.model.remove(this.claimedIndex);
|
||||||
this.$http.delete(query).then(() => {
|
this.$.model.save().then(() => {
|
||||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||||
this.$.model.remove(this.sale);
|
|
||||||
this.calculateTotals();
|
this.calculateTotals();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,13 +73,16 @@ describe('claim', () => {
|
||||||
|
|
||||||
describe('deleteClaimedSale()', () => {
|
describe('deleteClaimedSale()', () => {
|
||||||
it('should make a delete and call refresh and showSuccess', () => {
|
it('should make a delete and call refresh and showSuccess', () => {
|
||||||
controller.sale = {id: 1};
|
const claimedIndex = 1;
|
||||||
|
controller.claimedIndex = claimedIndex;
|
||||||
jest.spyOn(controller.$.model, 'remove');
|
jest.spyOn(controller.$.model, 'remove');
|
||||||
|
jest.spyOn(controller.$.model, 'save');
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
$httpBackend.expectDELETE(`ClaimBeginnings/1`).respond('ok');
|
|
||||||
controller.deleteClaimedSale();
|
|
||||||
$httpBackend.flush();
|
|
||||||
|
|
||||||
|
controller.deleteClaimedSale();
|
||||||
|
|
||||||
|
expect(controller.$.model.remove).toHaveBeenCalledWith(claimedIndex);
|
||||||
|
expect(controller.$.model.save).toHaveBeenCalledWith();
|
||||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,28 +9,31 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
"id": true,
|
"id": true,
|
||||||
"type": "Number"
|
"type": "number"
|
||||||
|
},
|
||||||
|
"code": {
|
||||||
|
"type": "string"
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"type": "String"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"parentFk": {
|
"parentFk": {
|
||||||
"type": "Number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"lft": {
|
"lft": {
|
||||||
"type": "Number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"rgt": {
|
"rgt": {
|
||||||
"type": "Number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"sons": {
|
"sons": {
|
||||||
"type": "Number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"chatName": {
|
"chatName": {
|
||||||
"type": "String"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"notificationEmail": {
|
"notificationEmail": {
|
||||||
"type": "String"
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue