From 40304239a345e4646f7659f49d3e935f3cda079d Mon Sep 17 00:00:00 2001 From: Marie JONES Date: Fri, 23 Aug 2019 11:54:19 +0200 Subject: [PATCH] feat(account.contacts): prevent contact change for in debt services MBE-269 --- .../service/contacts-service.service.js | 20 ++++++++---- .../contacts/service/edit/edit.component.js | 2 ++ .../contacts/service/edit/edit.constants.js | 5 +++ .../contacts/service/edit/edit.controller.js | 7 +++- .../account/contacts/service/edit/edit.html | 32 ++++++++++++++++--- .../contacts/service/edit/edit.routing.js | 2 ++ .../edit/translations/Messages_fr_FR.json | 5 ++- .../service/user-contacts-service.routes.js | 6 +--- client/app/models/BillingService.class.js | 7 +++- 9 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 client/app/account/contacts/service/edit/edit.constants.js diff --git a/client/app/account/contacts/service/contacts-service.service.js b/client/app/account/contacts/service/contacts-service.service.js index 3d404e4a2..d5216d725 100644 --- a/client/app/account/contacts/service/contacts-service.service.js +++ b/client/app/account/contacts/service/contacts-service.service.js @@ -1,4 +1,5 @@ import _ from 'lodash'; +import BillingService from '../../../models/BillingService.class'; import { AVAILABLE_SERVICES } from './user-contacts.constants'; @@ -13,11 +14,15 @@ export default class { getServiceInfos(service) { return this.OvhHttp.get(`${service.path}/${service.serviceName}/serviceInfos`, { rootPath: 'apiv6', - }); + }) + .then(serviceInfos => new BillingService({ + ...service, + ...serviceInfos, + })); } changeContact(service) { - return this.OvhHttp.post(`${service.path}/${service.serviceName}/changeContact'`, { + return this.OvhHttp.post(`${service.path}/${service.serviceName}/changeContact`, { rootPath: 'apiv6', data: { contactAdmin: service.contactAdmin, @@ -29,10 +34,13 @@ export default class { getServices() { return this.OvhApiOvhProduct.Aapi().query().$promise - .then(services => _.filter( - services, - service => AVAILABLE_SERVICES.includes(service.category), - )); + .then((services) => { + const availableServices = _.filter( + services, + service => AVAILABLE_SERVICES.includes(service.category), + ); + return availableServices.map(service => new BillingService(service)); + }); } static getAvailableCategories(services) { diff --git a/client/app/account/contacts/service/edit/edit.component.js b/client/app/account/contacts/service/edit/edit.component.js index 9e72322ac..3363dd18e 100644 --- a/client/app/account/contacts/service/edit/edit.component.js +++ b/client/app/account/contacts/service/edit/edit.component.js @@ -3,7 +3,9 @@ import template from './edit.html'; export default { bindings: { + billLink: '<', changeContact: '<', + currentUser: '<', goBack: '<', service: '<', }, diff --git a/client/app/account/contacts/service/edit/edit.constants.js b/client/app/account/contacts/service/edit/edit.constants.js new file mode 100644 index 000000000..103fb08c5 --- /dev/null +++ b/client/app/account/contacts/service/edit/edit.constants.js @@ -0,0 +1,5 @@ +export const DEBT_ALL = 'all'; + +export default { + DEBT_ALL, +}; diff --git a/client/app/account/contacts/service/edit/edit.controller.js b/client/app/account/contacts/service/edit/edit.controller.js index dac864580..1596f6fc6 100644 --- a/client/app/account/contacts/service/edit/edit.controller.js +++ b/client/app/account/contacts/service/edit/edit.controller.js @@ -1,4 +1,5 @@ import _ from 'lodash'; +import BillingService from '../../../../models/BillingService.class'; export default class { /* @ngInject */ @@ -6,10 +7,14 @@ export default class { this.$translate = $translate; } + $onInit() { + this.editedService = new BillingService(this.service); + } + updateContacts() { this.isUpdating = true; - return this.changeContact(this.service) + return this.changeContact(this.editedService) .then(() => this.goBack( this.$translate.instant('account_contacts_service_edit_success'), )) diff --git a/client/app/account/contacts/service/edit/edit.html b/client/app/account/contacts/service/edit/edit.html index 55a2b9f41..3ad160e70 100644 --- a/client/app/account/contacts/service/edit/edit.html +++ b/client/app/account/contacts/service/edit/edit.html @@ -1,4 +1,7 @@ -
+

+ + + + + + + + +
diff --git a/client/app/account/contacts/service/edit/edit.routing.js b/client/app/account/contacts/service/edit/edit.routing.js index b54af0532..1adb32693 100644 --- a/client/app/account/contacts/service/edit/edit.routing.js +++ b/client/app/account/contacts/service/edit/edit.routing.js @@ -1,4 +1,5 @@ import _ from 'lodash'; +import { DEBT_ALL } from './edit.constants'; export default /* @ngInject */ ($stateProvider) => { $stateProvider.state('app.account.useraccount.contacts.services.edit', { @@ -10,6 +11,7 @@ export default /* @ngInject */ ($stateProvider) => { }, layout: 'modal', resolve: { + billLink: /* @ngInject */ $state => $state.href('app.account.billing.main.history.pay-debt', { debtId: DEBT_ALL }), changeContact: /* @ngInject */ AccountContactsService => service => AccountContactsService.changeContact(service), goBack: /* @ngInject */ goToContacts => goToContacts, diff --git a/client/app/account/contacts/service/edit/translations/Messages_fr_FR.json b/client/app/account/contacts/service/edit/translations/Messages_fr_FR.json index 46b5c426c..ad3183da0 100644 --- a/client/app/account/contacts/service/edit/translations/Messages_fr_FR.json +++ b/client/app/account/contacts/service/edit/translations/Messages_fr_FR.json @@ -7,5 +7,8 @@ "account_contacts_service_edit_cancel": "Annuler", "account_contacts_service_edit_confirm": "Valider", "account_contacts_service_edit_error": "Une erreur est survenue lors de la demande de changement de contact : {{ message }}", - "account_contacts_service_edit_success": "La demande de changement de contact a été efféctuée avec succès. Les contacts concernés par la demande recevront un email contenant la procédure de validation." + "account_contacts_service_edit_success": "La demande de changement de contact a été effectuée avec succès. Les contacts concernés par la demande recevront un e-mail contenant la procédure de validation.", + "account_contacts_service_edit_warn_debt": "Vous ne pouvez pas modifier le contact de facturation, car une facture est en attente de règlement pour ce service. Nous vous invitons à la régler afin d’effectuer ce changement.", + "account_contacts_service_edit_pay": "Régler la facture", + "account_contacts_service_edit_warn_contact_billing": "Vous ne pouvez pas modifier le contact de facturation, car une facture est en attente de règlement pour ce service. Nous vous invitons à joindre le contact de facturation actuel {{ nicBilling }} afin qu’il effectue ce changement." } diff --git a/client/app/account/contacts/service/user-contacts-service.routes.js b/client/app/account/contacts/service/user-contacts-service.routes.js index 820895c4a..90766096e 100644 --- a/client/app/account/contacts/service/user-contacts-service.routes.js +++ b/client/app/account/contacts/service/user-contacts-service.routes.js @@ -5,11 +5,7 @@ export default /* @ngInject */ ($stateProvider) => { resolve: { editContacts: /* @ngInject */ $state => service => $state.go('app.account.useraccount.contacts.services.edit', { service: service.serviceName }), getServiceInfos: /* @ngInject */ - AccountContactsService => service => AccountContactsService.getServiceInfos(service) - .then(serviceInfos => ({ - ...service, - ...serviceInfos, - })), + AccountContactsService => service => AccountContactsService.getServiceInfos(service), goToContacts: /* @ngInject */ ($state, $timeout, Alerter) => (message = false, type = 'success') => { const reload = message && type === 'success'; diff --git a/client/app/models/BillingService.class.js b/client/app/models/BillingService.class.js index 70e1da906..6adb97f24 100644 --- a/client/app/models/BillingService.class.js +++ b/client/app/models/BillingService.class.js @@ -65,7 +65,12 @@ export default class BillingService { } hasDebt() { - return _.includes(['PENDING_DEBT', 'UN_PAID'], this.status); + return _.includes([ + 'PENDING_DEBT', + 'UN_PAID', + 'pendingDebt', + 'unPaid', + ], this.status); } hasEngagement() {