Revert "Revert "Tarea #289 Cuando se modifica el crédito mostrar alerta""

This reverts commit d9862b8922.
This commit is contained in:
gerard 2018-05-11 11:16:16 +02:00
parent d9862b8922
commit 85aa3b0156
6 changed files with 167 additions and 10 deletions

View File

@ -5,7 +5,7 @@
form="form" form="form"
save="patch"> save="patch">
</vn-watcher> </vn-watcher>
<form name="form" ng-submit="watcher.submitGo('clientCard.credit.list')"> <form name="form" ng-submit="$ctrl.onSubmit()">
<vn-card pad-large> <vn-card pad-large>
<vn-title>Add credit</vn-title> <vn-title>Add credit</vn-title>
<vn-horizontal> <vn-horizontal>
@ -16,3 +16,9 @@
<vn-submit label="Save"></vn-submit> <vn-submit label="Save"></vn-submit>
</vn-button-bar> </vn-button-bar>
</form> </form>
<vn-confirm
vn-id="confirmation"
on-response="$ctrl.returnDialog(response)"
question="Esta modificación retrasará el plazo del próximo recobro"
message="¿Desea continuar?">
</vn-confirm>

View File

@ -1,7 +1,44 @@
import ngModule from '../module'; import ngModule from '../module';
class Controller {
constructor($http, $scope, $state) {
this.$http = $http;
this.$scope = $scope;
this.$state = $state;
}
onSubmit() {
this.$http.get(`/client/api/Recoveries/${this.$state.params.id}/hasActiveRecovery`).then(res => {
let activeRecovery = res.data;
if (activeRecovery)
this.$scope.confirmation.show();
else
this.addCredit();
});
}
returnDialog(response) {
if (response === 'CANCEL')
return;
this.addCredit();
}
addCredit() {
this.$scope.watcher.submit().then(
() => {
this.$state.go('clientCard.credit.list');
}
);
}
}
Controller.$inject = ['$http', '$scope', '$state'];
ngModule.component('vnClientCreditCreate', { ngModule.component('vnClientCreditCreate', {
template: require('./credit-create.html'), template: require('./credit-create.html'),
controller: Controller,
bindings: { bindings: {
client: '<' client: '<'
} }

View File

@ -0,0 +1,85 @@
import './credit-create.js';
describe('Client', () => {
describe('Component vnClientCreditCreate', () => {
let $componentController;
let controller;
let $httpBackend;
let $state;
let $scope;
let client;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_, $rootScope, _$state_) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$scope.confirmation = {show: () => {
return {
then: () => {}
};
}};
$scope.watcher = {
submit: () => {
return {
then: callback => {
callback();
}
};
}
};
client = {credit: 0};
$state = _$state_;
$state.params.id = 101;
$httpBackend = _$httpBackend_;
controller = $componentController('vnClientCreditCreate', {$scope: $scope}, {$state: $state});
}));
describe('onSubmit()', () => {
it('should perform a query to check (GET) if the client has an active recovery', () => {
$httpBackend.whenGET(`/client/api/Recoveries/101/hasActiveRecovery`).respond(true);
$httpBackend.expectGET(`/client/api/Recoveries/101/hasActiveRecovery`);
controller.onSubmit();
$httpBackend.flush();
});
it('should call show() method when the client have a recovery', () => {
spyOn(controller.$scope.confirmation, 'show');
$httpBackend.whenGET(`/client/api/Recoveries/101/hasActiveRecovery`).respond(true);
$httpBackend.expectGET(`/client/api/Recoveries/101/hasActiveRecovery`);
controller.onSubmit();
$httpBackend.flush();
expect(controller.$scope.confirmation.show).toHaveBeenCalledWith();
});
it('should call addCredit() method when the client doesnt have a recovery', () => {
spyOn(controller, 'addCredit');
$httpBackend.whenGET(`/client/api/Recoveries/101/hasActiveRecovery`).respond(false);
$httpBackend.expectGET(`/client/api/Recoveries/101/hasActiveRecovery`);
controller.onSubmit();
$httpBackend.flush();
expect(controller.addCredit).toHaveBeenCalledWith();
});
});
describe('returnDialog()', () => {
it('should call addCredit() when is called with a param disctint from CANCEL', () => {
spyOn(controller, 'addCredit');
controller.returnDialog('Manzano');
expect(controller.addCredit).toHaveBeenCalledWith();
});
});
describe('addCredit()', () => {
it('should call the function go() on $state to go to the credit list', () => {
spyOn($state, 'go');
client.credit = 1;
controller.addCredit();
expect(controller.$state.go).toHaveBeenCalledWith('clientCard.credit.list');
});
});
});
});

View File

@ -7,16 +7,22 @@ module.exports = Self => {
skip: (params.page - 1) * params.size, skip: (params.page - 1) * params.size,
limit: params.size, limit: params.size,
order: params.order || 'name ASC', // name, relevancy DESC order: params.order || 'name ASC', // name, relevancy DESC
include: { include: [
relation: 'itemType', {relation: 'itemType',
scope: { scope: {
fields: ['id', 'name', 'workerFk'], fields: ['name', 'workerFk'],
include: { include: {
relation: 'worker', relation: 'worker',
fields: ['firstName', 'name'] fields: ['firstName', 'name']
}
} }
} },
} {relation: 'origin'},
{relation: 'ink'},
{relation: 'producer'},
{relation: 'intrastat'},
{relation: 'expence'}
]
}; };
delete params.page; delete params.page;

View File

@ -0,0 +1,20 @@
module.exports = Self => {
Self.remoteMethodCtx('getCurrentWorkerMana', {
description: 'Returns the mana of the logged worker',
accessType: 'READ',
accepts: [],
returns: {
type: 'number',
root: true
},
http: {
path: `/getCurrentWorkerMana`,
verb: 'GET'
}
});
Self.getCurrentWorkerMana = async ctx => {
let loggedWorkerId = ctx.req.accessToken.userId;
return await Self.rawSql(`SELECT used AS mana FROM vn.manaSpellers WHERE worker = ?`, [loggedWorkerId]);
};
};

View File

@ -0,0 +1,3 @@
module.exports = Self => {
require('../methods/workerMana/getCurrentWorkerMana')(Self);
};