diff --git a/src/app/@config/menus.ts b/src/app/@config/menus.ts index 88c5f35..3f1f57a 100644 --- a/src/app/@config/menus.ts +++ b/src/app/@config/menus.ts @@ -14,6 +14,8 @@ export interface MENU { isChecked?: boolean; } +export const ROLE_ADMIN = 'admin' +export const NOT_ADMIN = 'not-admin' export const MENU: MENU[] = [ { name: 'Manage', @@ -21,6 +23,7 @@ export const MENU: MENU[] = [ permission: 'manage', icon: 'bi bi-card-checklist', params: [], + roles: [ROLE_ADMIN], badge: '', type: 'collapsable', children: [ @@ -32,6 +35,7 @@ export const MENU: MENU[] = [ icon: '', params: [], badge: '', + roles: [ROLE_ADMIN], }, ] }, @@ -41,6 +45,7 @@ export const MENU: MENU[] = [ permission: 'report', icon: 'bi bi-file-bar-graph', params: [], + roles:[ROLE_ADMIN,NOT_ADMIN], badge: '', type: 'collapsable', children: [ @@ -50,8 +55,9 @@ export const MENU: MENU[] = [ permission: 'transactions', type: 'link', icon: '', - params: [], + params: [ROLE_ADMIN,NOT_ADMIN], badge: '', + roles: [], }, ] }, @@ -61,6 +67,7 @@ export const MENU: MENU[] = [ permission: 'setting', icon: 'bi bi-gear-fill', params: [], + roles: [ROLE_ADMIN], badge: '', type: 'collapsable', children: [ @@ -68,6 +75,7 @@ export const MENU: MENU[] = [ name: 'Banner', link: 'setting/banner', permission: 'banner', + roles: [ROLE_ADMIN], type: 'link', icon: '', params: [], @@ -76,6 +84,7 @@ export const MENU: MENU[] = [ { name: 'Promotion', link: 'setting/promotion', + roles: [ROLE_ADMIN], permission: 'promotion', type: 'link', icon: '', diff --git a/src/app/app.request.interceptor.ts b/src/app/app.request.interceptor.ts index 418ffd3..9f12762 100644 --- a/src/app/app.request.interceptor.ts +++ b/src/app/app.request.interceptor.ts @@ -7,7 +7,12 @@ import {catchError, Observable, throwError} from 'rxjs'; @Injectable() export class AppRequestInterceptor implements HttpInterceptor { - constructor(private router: Router,private appService: AppService) {} + constructor( + private router: Router, + private appService: AppService + ) { + + } intercept(request: HttpRequest, next: HttpHandler): Observable> { const token = this.appService.token(); diff --git a/src/app/auth/login/login.component.html b/src/app/auth/login/login.component.html index 993f624..5e04bbb 100644 --- a/src/app/auth/login/login.component.html +++ b/src/app/auth/login/login.component.html @@ -9,14 +9,14 @@
- กรุณากรอกข้อมูล
- กรุณากรอกข้อมูล @@ -34,4 +34,4 @@
- \ No newline at end of file + diff --git a/src/app/auth/login/login.component.ts b/src/app/auth/login/login.component.ts index 8f9b1d2..0466d42 100644 --- a/src/app/auth/login/login.component.ts +++ b/src/app/auth/login/login.component.ts @@ -6,6 +6,7 @@ import { AuthService } from 'src/app/core/service/auth/auth.service'; import { lastValueFrom } from 'rxjs'; import { EAction, EText } from 'src/app/@config/app'; import { CathayAuthService } from 'src/app/core/service/auth/cathay-auth.service'; +import { ROLE_ADMIN } from 'src/app/@config/menus'; @Component({ @@ -32,21 +33,25 @@ export class LoginComponent implements OnInit { ngOnInit() { - if (!environment.production) { - this.dataForm = { - username: 'admin', - password: 'admin', - } - } + // if (!environment.production) { + // this.dataForm = { + // username: 'admin', + // password: 'admin', + // } + // } } async onSubmit(form: any) { if (!form.valid) return false; try { - const result = await lastValueFrom(this.authService.login(this.dataForm)); - const cathayResult: any = await lastValueFrom(this.cathayAuthService.login(this.cathayForm)); + // const result = await lastValueFrom(this.authService.login(this.dataForm)); + let cathayResult: any = await lastValueFrom(this.cathayAuthService.login(this.cathayForm)); + cathayResult = { + ...cathayResult, + isAdmin: cathayResult.token.userName == ROLE_ADMIN ? true : false + } this.appService.setToken(cathayResult.token.token) - this.appService.setAuth(result); + this.appService.setAuth(cathayResult); return this.router.navigate(['/pages']); } catch (err) { return this.appService.message(EAction.ERROR, EText.NO_DATA); diff --git a/src/app/core/service/transaction/transaction.service.spec.ts b/src/app/core/service/transaction/transaction.service.spec.ts new file mode 100644 index 0000000..82b19f8 --- /dev/null +++ b/src/app/core/service/transaction/transaction.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { TransactionService } from './transaction.service'; + +describe('TransactionService', () => { + let service: TransactionService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(TransactionService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/core/service/transaction/transaction.service.ts b/src/app/core/service/transaction/transaction.service.ts new file mode 100644 index 0000000..a51db66 --- /dev/null +++ b/src/app/core/service/transaction/transaction.service.ts @@ -0,0 +1,18 @@ +import { BaseList } from './../../base/base-list'; +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { BaseService } from 'src/app/core/base/base-service'; +import { environment } from 'src/environments/environment'; + +@Injectable({ + providedIn: 'root' +}) +export class TransactionService extends BaseService { + + constructor( + public http: HttpClient + ) { + super('', http) + this.fullUrl = `${environment.CATHAYAPIURL}/v2/Payment/getTransaction` + } +} diff --git a/src/app/core/service/users/user-cathay.service.spec.ts b/src/app/core/service/users/user-cathay.service.spec.ts new file mode 100644 index 0000000..2792604 --- /dev/null +++ b/src/app/core/service/users/user-cathay.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { UserCathayService } from './user-cathay.service'; + +describe('UserCathayService', () => { + let service: UserCathayService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(UserCathayService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/core/service/users/user-cathay.service.ts b/src/app/core/service/users/user-cathay.service.ts new file mode 100644 index 0000000..c1752b8 --- /dev/null +++ b/src/app/core/service/users/user-cathay.service.ts @@ -0,0 +1,21 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { environment } from 'src/environments/environment'; +import { BaseService } from '../../base/base-service'; + +@Injectable({ + providedIn: 'root' +}) +export class UserCathayService extends BaseService { + + constructor( + public http: HttpClient + ) { + super('', http) + this.fullUrl = `${environment.CATHAYAPIURL}/v1/user` + } + + getUserCathay(payerUid: string){ + return super.get(payerUid) + } +} diff --git a/src/app/pages/@layouts/layouts.component.html b/src/app/pages/@layouts/layouts.component.html index 6c969fc..ecb9e6b 100644 --- a/src/app/pages/@layouts/layouts.component.html +++ b/src/app/pages/@layouts/layouts.component.html @@ -16,8 +16,8 @@