|
|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
import { Component } from '@angular/core';
|
|
|
|
|
import { Component, ViewChild } from '@angular/core';
|
|
|
|
|
import { FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
|
|
|
|
import { PermissionNode } from '../utils/app.interfaces';
|
|
|
|
|
import { CredentialService } from '../services/credential.service';
|
|
|
|
|
@ -10,12 +10,14 @@ import { HttpErrorResponse, HttpParams } from '@angular/common/http';
|
|
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
|
import { NgSelectModule } from '@ng-select/ng-select';
|
|
|
|
|
import { filter, Observable, take } from 'rxjs';
|
|
|
|
|
import { SuccessMessages } from '../utils/enums';
|
|
|
|
|
import { ErrorMessages, SuccessMessages } from '../utils/enums';
|
|
|
|
|
import { URIService } from '../app.uri';
|
|
|
|
|
import { PasswordHideShowComponent } from '../shared/components/password-hide-show/password-hide-show.component';
|
|
|
|
|
import { error } from 'console';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-menu',
|
|
|
|
|
imports: [TranslateModule, ReactiveFormsModule, ReactiveFormsModule, CommonModule, TranslateModule, NgSelectModule, FormsModule],
|
|
|
|
|
imports: [TranslateModule, ReactiveFormsModule, ReactiveFormsModule, CommonModule, TranslateModule, NgSelectModule, FormsModule, PasswordHideShowComponent],
|
|
|
|
|
templateUrl: './menu.component.html',
|
|
|
|
|
styleUrl: './menu.component.scss'
|
|
|
|
|
})
|
|
|
|
|
@ -26,7 +28,9 @@ export class MenuComponent {
|
|
|
|
|
showPermissions = false;
|
|
|
|
|
permissions: PermissionNode[] = [];
|
|
|
|
|
saving = false;
|
|
|
|
|
passwordType: string = 'password';
|
|
|
|
|
menuItems: { endpoint: string; checked: boolean }[] = [];
|
|
|
|
|
@ViewChild('passShowMenu') passwordHideShow?: PasswordHideShowComponent;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private credentialService: CredentialService,
|
|
|
|
|
@ -48,6 +52,9 @@ export class MenuComponent {
|
|
|
|
|
this.loadTransactionEndpoints();
|
|
|
|
|
this.createThirdPartyUserForm();
|
|
|
|
|
}
|
|
|
|
|
toggleSetupPass() {
|
|
|
|
|
this.passwordType = this.passwordHideShow?.showPassword ? 'password' : 'text';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createThirdPartyUserForm(): void{
|
|
|
|
|
this.thirdPartyForm = this.fb.group({
|
|
|
|
|
@ -61,14 +68,22 @@ export class MenuComponent {
|
|
|
|
|
Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/)
|
|
|
|
|
]],
|
|
|
|
|
SUS_EMAIL: ["", [Validators.required, Validators.email]],
|
|
|
|
|
SUS_USERCELLNO: ["", [Validators.required]],
|
|
|
|
|
SUS_USERCELLNO: ["", [
|
|
|
|
|
Validators.required,
|
|
|
|
|
Validators.pattern(/^[0-9]+$/)
|
|
|
|
|
]],
|
|
|
|
|
POR_ORGACODE: [this.credentialService.getPorOrgacode()],
|
|
|
|
|
SUS_ACTIVE: [true],
|
|
|
|
|
SUS_THIRDPARTY: [true],
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onlyNumbers(event: KeyboardEvent) {
|
|
|
|
|
const charCode = event.which ? event.which : event.keyCode;
|
|
|
|
|
if (charCode < 48 || charCode > 57) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
submitForm() {
|
|
|
|
|
if (this.thirdPartyForm.invalid) {
|
|
|
|
|
this.thirdPartyForm.markAllAsTouched();
|
|
|
|
|
@ -102,12 +117,28 @@ export class MenuComponent {
|
|
|
|
|
if (!(response instanceof HttpErrorResponse)) {
|
|
|
|
|
this.i18nService.success(SuccessMessages.SAVED_SUCCESSFULLY, []);
|
|
|
|
|
this.createThirdPartyUserForm();
|
|
|
|
|
this.getAllUsers();
|
|
|
|
|
this.permission.reset();
|
|
|
|
|
this.showPermissions = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
error: (error: any) => {
|
|
|
|
|
const errorCode = error?.error?.errorCode || error?.errorCode;
|
|
|
|
|
|
|
|
|
|
switch (errorCode) {
|
|
|
|
|
case 'ERR_SEC_0002':
|
|
|
|
|
this.i18nService.error(ErrorMessages.USERNAME_ALREADY_EXISTS, []);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// handle error codes e.g. ERR_TRX_0006
|
|
|
|
|
// Once backend is ready, check response for errorCode field
|
|
|
|
|
// e.g. if (response?.errorCode === 'ERR_TRX_0006') { show error }
|
|
|
|
|
case 'ERR_SEC_0001':
|
|
|
|
|
this.i18nService.error(ErrorMessages.EMAIL_ALREADY_EXISTS, []);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
this.i18nService.error('Unexpected error', []);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|