This commit is contained in:
Bernat 2019-04-16 08:36:16 +02:00
commit 97f3761e0c
16 changed files with 98 additions and 29 deletions

1
Jenkinsfile vendored
View File

@ -131,6 +131,7 @@ pipeline {
stage('Database') {
when { anyOf {
branch 'test'
branch 'master'
}}
steps {
configFileProvider([

View File

@ -0,0 +1 @@
ALTER TABLE `vn2008`.`Greuges` CHANGE COLUMN `Fecha` `Fecha` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ;

View File

@ -30,7 +30,7 @@
vn-one
label="Responsability"
value="$ctrl.claim.responsibility"
max="5"
max="$ctrl.maxResponsibility"
min="1"
step="1"
vn-acl="salesAssistant"
@ -191,4 +191,10 @@
</vn-item-descriptor-popover>
<vn-ticket-descriptor-popover
vn-id="ticketDescriptor">
</vn-ticket-descriptor-popover>
</vn-ticket-descriptor-popover>
<vn-confirm
vn-id="update-greuge"
question="Insert greuges on client card"
message="Do you want to insert greuges?"
on-response="$ctrl.onUpdateGreugeResponse(response)">
</vn-confirm>

View File

@ -23,6 +23,7 @@ class Controller {
]
};
this.resolvedState = 3;
this.maxResponsibility = 5;
}
openAddSalesDialog() {
@ -135,9 +136,29 @@ class Controller {
this.$http.post(query, data).then(() => {
this.card.reload();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
if (this.claim.responsibility >= Math.ceil(this.maxResponsibility) / 2)
this.$.updateGreuge.show();
});
}
onUpdateGreugeResponse(response) {
if (response !== 'ACCEPT')
return;
let greugeTypeFreight = 7;
let query = `claim/api/Greuges/`;
let data = {
clientFk: this.claim.clientFk,
description: `claim: ${this.claim.id}`,
amount: 11,
greugeTypeFk: greugeTypeFreight,
ticketFk: this.claim.ticketFk
};
this.$http.post(query, data).then(() => {
this.card.reload();
this.vnApp.showSuccess(this.$translate.instant('Greuge inserted!'));
});
}
// Item Descriptor
showDescriptor(event, itemFk) {
this.quicklinks = {

View File

@ -158,5 +158,37 @@ describe('claim', () => {
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
describe('onUpdateGreugeResponse()', () => {
it('should do nothing', () => {
spyOn(controller.card, 'reload');
spyOn(controller.vnApp, 'showSuccess');
controller.onUpdateGreugeResponse('CANCEL');
expect(controller.card.reload).not.toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith('Greuge inserted!');
});
it('should perform a insert into greuges', () => {
spyOn(controller.card, 'reload');
spyOn(controller.vnApp, 'showSuccess');
controller.claim.clientFk = 101;
controller.claim.id = 11;
let data = {
clientFk: 101,
description: `claim: ${controller.claim.id}`,
amount: 11,
greugeTypeFk: 7,
ticketFk: controller.claim.ticketFk
};
$httpBackend.expect('POST', `claim/api/Greuges/`, data).respond();
controller.onUpdateGreugeResponse('ACCEPT');
$httpBackend.flush();
expect(controller.card.reload).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Greuge inserted!');
});
});
});
});

View File

@ -5,4 +5,7 @@ Import claim: Importar reclamacion
Imports claim details: Importa detalles de la reclamacion
Import ticket: Importar ticket
Imports ticket lines: Importa las lineas de un ticket
Regularize: Regularizar
Regularize: Regularizar
Do you want to insert greuges?: Desea insertar greuges?
Insert greuges on client card: Insertar greuges en la ficha del cliente
Greuge inserted: Greuge insertado

View File

@ -6,11 +6,11 @@ module.exports = Self => {
Self.remoteMethodCtx('send', {
description: 'Sends SMS to a destination phone',
accepts: [{
arg: 'recipientFk',
arg: 'destinationFk',
type: 'Integer'
},
{
arg: 'recipient',
arg: 'destination',
type: 'String',
required: true,
},
@ -20,7 +20,7 @@ module.exports = Self => {
required: true,
}],
returns: {
type: 'boolean',
type: 'Object',
root: true
},
http: {
@ -29,7 +29,7 @@ module.exports = Self => {
}
});
Self.send = async(ctx, recipientFk, recipient, message) => {
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);
@ -37,7 +37,7 @@ module.exports = Self => {
user: smsConfig.user,
pass: smsConfig.password,
src: smsConfig.title,
dst: recipient,
dst: destination,
msg: message
};
@ -61,18 +61,21 @@ module.exports = Self => {
console.error(e);
}
const statusCode = status.codigo[0];
const statusDescription = status.descripcion[0];
const newSms = {
senderFk: userId,
destinationFk: recipientFk || null,
destination: recipient,
destinationFk: destinationFk || null,
destination: destination,
message: message,
statusCode: status.codigo,
status: status.descripcion
statusCode: statusCode,
status: statusDescription
};
const sms = Self.create(newSms);
const sms = await Self.create(newSms);
if (status.codigo != 200)
if (statusCode != 200)
throw new UserError(`We weren't able to send this SMS`);
return sms;

View File

@ -8,7 +8,7 @@ const app = require('vn-loopback/server/server');
describe('sms send()', () => {
it('should should return the expected message and status code', async() => {
let ctx = {req: {accessToken: {userId: 1}}};
let result = await app.models.Sms.send(ctx, null, 'Invalid', 'My SMS Body');
let result = await app.models.Sms.send(ctx, 101, 'Invalid', 'My SMS Body');
expect(result.statusCode).toEqual(200);
expect(result.status).toEqual('Envio en procesamiento');

View File

@ -1,7 +1,11 @@
{
"name": "Sms",
"description": "Sms sent to client",
"base": "VnModel",
"base": "Loggable",
"log": {
"model":"ClientLog",
"relation": "recipient"
},
"options": {
"mysql": {
"table": "sms"

View File

@ -5,8 +5,8 @@
<h5 pad-small-v translate>Send SMS</h5>
<vn-horizontal>
<vn-textfield vn-one
label="Recipient"
model="$ctrl.sms.recipient">
label="Destination"
model="$ctrl.sms.destination">
</vn-textfield>
</vn-horizontal>
<vn-horizontal >

View File

@ -18,11 +18,7 @@ class Controller extends Component {
onResponse(response) {
if (response === 'ACCEPT') {
let params = {
recipient: this.sms.recipient,
message: this.sms.message
};
this.$http.post(`/client/api/Sms/send`, params).then(res => {
this.$http.post(`/client/api/Sms/send`, this.sms).then(res => {
this.vnApp.showMessage(this.$translate.instant('SMS sent!'));
if (res.data) this.emit('send', {response: res.data});

View File

@ -17,8 +17,8 @@ describe('Client', () => {
describe('onResponse()', () => {
it('should perform a POST query and show a success snackbar', () => {
let params = {recipient: 111111111, message: 'My SMS'};
controller.sms = {recipient: 111111111, message: 'My SMS'};
let params = {destinationFk: 101, destination: 111111111, message: 'My SMS'};
controller.sms = {destinationFk: 101, destination: 111111111, message: 'My SMS'};
spyOn(controller.vnApp, 'showMessage');
$httpBackend.when('POST', `/client/api/Sms/send`, params).respond(200, params);

View File

@ -1,4 +1,4 @@
Send SMS: Enviar SMS
Recipient: Destinatario
Destination: Destinatario
Message: Mensaje
SMS sent!: ¡SMS enviado!

View File

@ -182,7 +182,8 @@ class Controller {
showSMSDialog() {
const address = this.ticket.address;
this.newSMS = {
recipient: address.mobile || null,
destinationFk: this.ticket.clientFk,
destination: address.mobile || null,
message: this.$translate.instant('SMSPayment')
};
this.$scope.sms.open();

View File

@ -331,7 +331,8 @@ class Controller {
notAvailables
};
this.newSMS = {
recipient: address.mobile || null,
destinationFk: this.ticket.clientFk,
destination: address.mobile || null,
message: this.$translate.instant('SMSAvailability', params)
};
this.$scope.sms.open();

View File

@ -180,7 +180,7 @@ describe('Ticket', () => {
controller.showSMSDialog();
expect(controller.$scope.sms.open).toHaveBeenCalledWith();
expect(controller.newSMS.recipient).toEqual(111111111);
expect(controller.newSMS.destination).toEqual(111111111);
expect(controller.newSMS.message).not.toEqual('');
});
});