Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
feat(account.contacts): prevent contact change for in debt services
Browse files Browse the repository at this point in the history
MBE-269
  • Loading branch information
marie-j committed Sep 11, 2019
1 parent 49c0e25 commit 15fe69a
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 18 deletions.
20 changes: 14 additions & 6 deletions client/app/account/contacts/service/contacts-service.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash';
import BillingService from '../../../models/BillingService.class';

import { AVAILABLE_SERVICES } from './user-contacts.constants';

Expand All @@ -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,
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions client/app/account/contacts/service/edit/edit.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import template from './edit.html';

export default {
bindings: {
billLink: '<',
changeContact: '<',
currentUser: '<',
goBack: '<',
service: '<',
},
Expand Down
5 changes: 5 additions & 0 deletions client/app/account/contacts/service/edit/edit.constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const DEBT_ALL = 'all';

export default {
DEBT_ALL,
};
7 changes: 6 additions & 1 deletion client/app/account/contacts/service/edit/edit.controller.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import _ from 'lodash';
import BillingService from '../../../../models/BillingService.class';

export default class {
/* @ngInject */
constructor($translate) {
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'),
))
Expand Down
32 changes: 28 additions & 4 deletions client/app/account/contacts/service/edit/edit.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<form data-ng-submit="$ctrl.updateContacts()">
<form
name="$ctrl.contactsEditForm"
novalidate
data-ng-submit="$ctrl.updateContacts()">
<oui-modal
data-heading="{{:: 'account_contacts_service_edit' | translate }}"
data-primary-label="{{:: 'account_contacts_service_edit_confirm' | translate }}"
Expand All @@ -12,14 +15,34 @@
service: $ctrl.service.serviceName
}">
</p>
<oui-message
data-ng-if="$ctrl.service.hasDebt() && $ctrl.service.hasBillingRights($ctrl.currentUser.nichandle)"
data-type="warning">
<span data-translate="account_contacts_service_edit_warn_debt"></span>
<a
class="oui-link"
data-ng-href="{{ $ctrl.billLink }}"
data-translate="account_contacts_service_edit_pay">
</a>
</oui-message>
<oui-message
data-ng-if="$ctrl.service.hasDebt() && $ctrl.service.hasAdminRights($ctrl.currentUser.nichandle) && !$ctrl.service.hasBillingRights($ctrl.currentUser.nichandle)"
data-type="warning">
<span
data-translate="account_contacts_service_edit_warn_contact_billing"
data-translate-values="{
nicBilling: $ctrl.service.contactBilling
}">
</span>
</oui-message>
<oui-field
data-label="{{:: 'account_contacts_service_edit_contact_admin' | translate }}">
<input
class="oui-input"
type="text"
id="contactAdmin"
name="contactAdmin"
data-ng-model="$ctrl.service.contactAdmin"
data-ng-model="$ctrl.editedService.contactAdmin"
required>
</oui-field>
<oui-field
Expand All @@ -29,7 +52,7 @@
type="text"
id="contactTech"
name="contactTech"
data-ng-model="$ctrl.service.contactTech"
data-ng-model="$ctrl.editedService.contactTech"
required>
</oui-field>
<oui-field
Expand All @@ -39,7 +62,8 @@
type="text"
id="contactBilling"
name="contactBilling"
data-ng-model="$ctrl.service.contactBilling"
data-ng-model="$ctrl.editedService.contactBilling"
data-ng-disabled="$ctrl.service.hasDebt()"
required>
</oui-field>
</oui-modal>
Expand Down
2 changes: 2 additions & 0 deletions client/app/account/contacts/service/edit/edit.routing.js
Original file line number Diff line number Diff line change
@@ -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', {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
7 changes: 6 additions & 1 deletion client/app/models/BillingService.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 15fe69a

Please sign in to comment.