From 0f361712dc35c446fa255301b18f5cfec9f14afe Mon Sep 17 00:00:00 2001 From: user Date: Fri, 26 Jan 2024 02:58:36 -0800 Subject: [PATCH] called terminal api --- package-lock.json | 12 ++++++ package.json | 1 + .../auth/singin/singin.component.ts | 4 ++ .../analytic/analytic.component.html | 14 +++---- .../dashboard/analytic/analytic.component.ts | 39 ++++++++++++++++++- .../overview/overview.component.html | 31 ++++++++------- .../dashboard/overview/overview.component.ts | 6 +-- .../components/dashboard/sidenav/nav-data.ts | 12 +++--- .../dashboard/sidenav/sidenav.component.html | 11 +++--- .../dashboard/sidenav/sidenav.component.scss | 5 +-- .../dashboard/sidenav/sidenav.component.ts | 6 +++ src/app/dashboard.service.ts | 10 +++-- src/app/services/auth.service.ts | 2 +- src/app/services/terminal.service.ts | 4 +- src/app/services/token.service.ts | 12 ++++++ src/app/services/util.service.spec.ts | 16 ++++++++ src/app/services/util.service.ts | 32 +++++++++++++++ src/app/services/utils.ts | 2 +- 18 files changed, 172 insertions(+), 47 deletions(-) create mode 100644 src/app/services/util.service.spec.ts create mode 100644 src/app/services/util.service.ts diff --git a/package-lock.json b/package-lock.json index 469ce9e..fbcbd55 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "@angular/platform-browser": "^16.0.0", "@angular/platform-browser-dynamic": "^16.0.0", "@angular/router": "^16.0.0", + "@auth0/angular-jwt": "^5.2.0", "jwt-decode": "^3.1.2", "ng-angular-popup": "^0.4.7", "ngx-otp-input": "^0.11.4", @@ -664,6 +665,17 @@ "integrity": "sha512-H71nDOOL8Y7kWRLqf6Sums+01Q5msqBW2KhDUTemh1tvY04eSkSXrK0uj/4mmY0Xr16/3zyZmsrxN7CKuRbNRg==", "dev": true }, + "node_modules/@auth0/angular-jwt": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@auth0/angular-jwt/-/angular-jwt-5.2.0.tgz", + "integrity": "sha512-9FS2L0QwGNlxA/zgeehCcsR9CZscouyXkoIj1fODM36A8BLfdzg9k9DWAXUQ2Drjk0AypGAFzeNZR4vsLMhdeQ==", + "dependencies": { + "tslib": "^2.0.0" + }, + "peerDependencies": { + "@angular/common": ">=14.0.0" + } + }, "node_modules/@babel/code-frame": { "version": "7.21.4", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.21.4.tgz", diff --git a/package.json b/package.json index 8ecb992..54d7bc0 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@angular/platform-browser": "^16.0.0", "@angular/platform-browser-dynamic": "^16.0.0", "@angular/router": "^16.0.0", + "@auth0/angular-jwt": "^5.2.0", "jwt-decode": "^3.1.2", "ng-angular-popup": "^0.4.7", "ngx-otp-input": "^0.11.4", diff --git a/src/app/components/auth/singin/singin.component.ts b/src/app/components/auth/singin/singin.component.ts index d94f990..92d3968 100644 --- a/src/app/components/auth/singin/singin.component.ts +++ b/src/app/components/auth/singin/singin.component.ts @@ -5,6 +5,7 @@ import { Router } from '@angular/router'; import { NgxOtpInputConfig } from 'ngx-otp-input'; import { NgToastService } from 'ng-angular-popup'; import { AuthService } from 'src/app/services/auth.service'; +import { UtilService } from 'src/app/services/util.service'; // import {Component} from '@angular/core'; @@ -151,6 +152,8 @@ console.log(this.formSubmitted); } this.authService.validateToken(optObj).subscribe({ next:(res: any)=>{ + // console.log("================") + // UtilService.setUserDetails(res.data); console.log(res) }, @@ -173,6 +176,7 @@ console.log(this.formSubmitted); this.authService.validateToken(JSON.stringify(optObj)).subscribe({ next:(res: any)=>{ console.log(res); + UtilService.setUserDetails(res.data); this.router.navigate(['dashboard']); window.localStorage.setItem('token', res?.token); console.log("success"); diff --git a/src/app/components/dashboard/analytic/analytic.component.html b/src/app/components/dashboard/analytic/analytic.component.html index d6f75ce..07ffe07 100644 --- a/src/app/components/dashboard/analytic/analytic.component.html +++ b/src/app/components/dashboard/analytic/analytic.component.html @@ -182,7 +182,7 @@

Analysis Overvi Pending -
@@ -190,7 +190,7 @@

Analysis Overvi Succeded

-
@@ -210,7 +210,7 @@

Analysis Overvi

- {{terminal.cardRef}} + {{terminal.paymentMethod}}
@@ -230,13 +230,13 @@

Analysis Overvi
- {{size}} Result + {{totalNumOfEntry}} Result
-
-
+
+
Previous
-
+
Next
diff --git a/src/app/components/dashboard/analytic/analytic.component.ts b/src/app/components/dashboard/analytic/analytic.component.ts index fb0ef50..5559bfb 100644 --- a/src/app/components/dashboard/analytic/analytic.component.ts +++ b/src/app/components/dashboard/analytic/analytic.component.ts @@ -17,6 +17,16 @@ export class AnalyticComponent { } + terminalFilterRequest = { + status: null, + paymentId: null, + creationDate: null, + page: 0, + size: 10 + } + numOfPages: number = 0; + totalNumOfEntry: number = 0; + constructor(private terminalService: TerminalService) { } ngOnInit(): void { @@ -29,7 +39,9 @@ export class AnalyticComponent { this.terminalService.getTransactions(this.page, this.size).subscribe({ next: (response: any) => { this.apiResponse = response; - this.data = this.apiResponse?.content; + this.data = this.apiResponse?.data?.content; + this.totalNumOfEntry = this.apiResponse?.data?.totalElements; + this.getNumberOfPages(this.totalNumOfEntry); console.log(this.data); }, error: (items: any) => { @@ -38,6 +50,7 @@ export class AnalyticComponent { }) } + getAnalyticsOverview(): void { this.terminalService.getAnalyticsOverview().subscribe({ next: (response: any) => { @@ -65,4 +78,28 @@ export class AnalyticComponent { } } + getNumberOfPages(totalEntry: number): void { + console.log(totalEntry); + console.log(this.terminalFilterRequest.size); + if (totalEntry % this.terminalFilterRequest.size == 0) { + this.numOfPages = totalEntry / this.terminalFilterRequest.size; + } else { + this.numOfPages = 1 + Math.floor(totalEntry / this.terminalFilterRequest.size); + } + } + + nextPage(): void { + if (this.terminalFilterRequest.page + 1 < this.numOfPages) { + this.terminalFilterRequest.page = this.terminalFilterRequest.page + 1; + this.getTerminals(); + } + } + + previousPage(): void { + if (this.terminalFilterRequest.page + 1 > 1) { + this.terminalFilterRequest.page = this.terminalFilterRequest.page - 1; + this.getTerminals(); + } + } + } diff --git a/src/app/components/dashboard/overview/overview.component.html b/src/app/components/dashboard/overview/overview.component.html index 69ae55b..9308fc5 100644 --- a/src/app/components/dashboard/overview/overview.component.html +++ b/src/app/components/dashboard/overview/overview.component.html @@ -48,7 +48,7 @@

Dashboard

Active

-

{{overviewReport?.balance}}

+

{{overviewReport?.numberOfTerminals}}

@@ -66,7 +66,7 @@

Dashboard

Users

-

{{overviewReport?.numberOfTerminals}}

+

{{overviewReport?.activeTerminal}}

@@ -84,7 +84,7 @@

Dashboard

Users

-

{{overviewReport?.numberOfTerminals}}

+

{{overviewReport?.numberOfUsers}}

@@ -98,7 +98,7 @@

Dashboard

Balance

-

{{overviewReport?.numberOfUsers}}

+

{{overviewReport?.balance}}

@@ -116,22 +116,25 @@

Dashboard

-
-
+
+
- + dummy
-
+
-

{{deposit?.location}}

+
+

{{deposit?.location}}

+
+
+

{{deposit?.operatorName}}

+
-
-

{{deposit?.operatorName}}

+
+

+N{{deposit?.amount}}

-
-

+N{{deposit?.amount}}

-
+
diff --git a/src/app/components/dashboard/overview/overview.component.ts b/src/app/components/dashboard/overview/overview.component.ts index 42d0f7e..6376deb 100644 --- a/src/app/components/dashboard/overview/overview.component.ts +++ b/src/app/components/dashboard/overview/overview.component.ts @@ -9,7 +9,7 @@ import { DashboardService } from 'src/app/dashboard.service'; export class OverviewComponent{ overviewReport: any; - deposits:any; + deposits:any = []; withdrawal:any; constructor( private dashboardService: DashboardService){ @@ -36,8 +36,8 @@ export class OverviewComponent{ getDeposit(): void { this.dashboardService.getDeposit().subscribe({ next: (response) => { - console.log("response =>>>>", response); - this.deposits = response.content; + console.log("response =>>>> array", response); + this.deposits = response?.data?.content; console.log(this.deposits); }, error: (error) => { diff --git a/src/app/components/dashboard/sidenav/nav-data.ts b/src/app/components/dashboard/sidenav/nav-data.ts index edf1a14..6cab615 100644 --- a/src/app/components/dashboard/sidenav/nav-data.ts +++ b/src/app/components/dashboard/sidenav/nav-data.ts @@ -4,7 +4,7 @@ export const navbarData: INavbarData[] = [ { routeLink: 'overview', - icon: 'assets/icons/Document.png', + icon: 'fas fa-eye', label: 'Overview', // items: [ // { @@ -39,12 +39,12 @@ export const navbarData: INavbarData[] = [ }, { routeLink: 'analytic', - icon: 'assets/icons/Wallet.png', + icon: 'fas fa-chart-line', label: 'Analytic' }, { - routeLink: 'manage-terminal', - icon: 'fal fa-tags', + routeLink: 'manage-terminal/*', + icon: 'fas fa-cash-register', label: 'Manage Terminal', // items: [ // { @@ -59,7 +59,7 @@ export const navbarData: INavbarData[] = [ }, { routeLink: 'refund-transaction', - icon: 'assets/icons/Stroke 1.png', + icon: 'fas fa-arrow-left', label: 'Refund Transactions' }, // { @@ -69,7 +69,7 @@ export const navbarData: INavbarData[] = [ // }, { routeLink: 'profile', - icon: 'assets/icons/Profile.png', + icon: 'fa fa-user', label: 'Profile' } , diff --git a/src/app/components/dashboard/sidenav/sidenav.component.html b/src/app/components/dashboard/sidenav/sidenav.component.html index 0f60cf5..a7bf134 100644 --- a/src/app/components/dashboard/sidenav/sidenav.component.html +++ b/src/app/components/dashboard/sidenav/sidenav.component.html @@ -13,10 +13,10 @@
@@ -62,7 +62,8 @@ [routerLink]="[data.routeLink]" routerLinkActive="active-link" [routerLinkActiveOptions]="{exact: true}" (click)="shrinkItems(data)"> - + + @@ -88,7 +89,7 @@ [expanded]="data.expanded">
-
  • +
  • diff --git a/src/app/components/dashboard/sidenav/sidenav.component.scss b/src/app/components/dashboard/sidenav/sidenav.component.scss index 4d67c52..208625f 100644 --- a/src/app/components/dashboard/sidenav/sidenav.component.scss +++ b/src/app/components/dashboard/sidenav/sidenav.component.scss @@ -243,8 +243,7 @@ background-color: #7B57FC; color: #fff; // position:; - margin-top: 330px; - + margin-top: 380px; left: 0; // display: block; @@ -252,5 +251,5 @@ padding: 20px; display: flex; gap: 1rem; - justify-content: center; + // justify-content: center; } diff --git a/src/app/components/dashboard/sidenav/sidenav.component.ts b/src/app/components/dashboard/sidenav/sidenav.component.ts index c5cbc61..66c387b 100644 --- a/src/app/components/dashboard/sidenav/sidenav.component.ts +++ b/src/app/components/dashboard/sidenav/sidenav.component.ts @@ -3,6 +3,7 @@ import { Component, Output, EventEmitter, OnInit, HostListener } from '@angular/ import { Router } from '@angular/router'; import { fadeInOut, INavbarData } from './helper'; import { navbarData } from './nav-data'; +import { UtilService } from 'src/app/services/util.service'; interface SideNavToggle { screenWidth: number; @@ -35,6 +36,7 @@ export class SidenavComponent implements OnInit { navData = navbarData; multiple: boolean = false; isClicked = false; + userDetails = UtilService.getUserDetails() || ""; @HostListener('window:resize', ['$event']) onResize(event: any) { @@ -79,4 +81,8 @@ export class SidenavComponent implements OnInit { } } } + + logOut(): void { + UtilService.clearStorage(); + } } diff --git a/src/app/dashboard.service.ts b/src/app/dashboard.service.ts index 044eb3a..ff57881 100644 --- a/src/app/dashboard.service.ts +++ b/src/app/dashboard.service.ts @@ -127,7 +127,8 @@ export class DashboardService { 'Content-Type': 'application/json', 'Authorization': `Bearer ${TokenService.getToken()}` }); - return this.http.get(`${baseURL}api/v1/analytic/dashboard`, { headers: headers }); + console.log({headers}); + return this.http.post(`${baseURL}api/v1/analytic/dashboard`, {body: {}}, { headers: headers }); } getDeposit(): Observable{ @@ -135,7 +136,10 @@ export class DashboardService { 'Content-Type': 'application/json', 'Authorization': `Bearer ${TokenService.getToken()}` }); - return this.http.get(`${baseURL}api/v1/analytic/deposit_data?page=0&size=5`, { headers: headers }); + return this.http.post(`${baseURL}api/v1/analytic/deposit_data?page=0&size=5`, {body: {}} , { headers: headers }); + // return this.http.get(`https://fakestoreapi.com/products`, { headers: headers }); + // return this.http.post(`${baseURL}api/v1/authenticate/test`, { headers: headers }); + } getWithdrawal(): Observable{ @@ -163,6 +167,4 @@ export class DashboardService { return this.http.get(`${baseURL}api/v1/analytic/transactions`, { headers: headers }); } - - } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 692f2b6..83d31bf 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -96,7 +96,7 @@ export class AuthService { 'Content-Type': 'application/json', 'Authorization': `Bearer ${TokenService.getToken()}` }); - console.log("token 2 ===>> " + TokenService.getToken()); + console.log({headers}); return this.http.post(`${baseURL}api/v1/authenticate/login`, tokenDetails, { headers: headers }); } diff --git a/src/app/services/terminal.service.ts b/src/app/services/terminal.service.ts index 7a41290..f3f5685 100644 --- a/src/app/services/terminal.service.ts +++ b/src/app/services/terminal.service.ts @@ -56,7 +56,7 @@ export class TerminalService { 'Content-Type': 'application/json', 'Authorization': `Bearer ${TokenService.getToken()}` }); - return this.http.get(`${baseURL}api/v1/analytic/transactions?page=${page}&size=${size}`, { headers: headers }); + return this.http.post(`${baseURL}api/v1/analytic/transactions?page=${page}&size=${size}`,{body: {}}, { headers: headers }); } getAnalyticsOverview(): Observable{ @@ -64,7 +64,7 @@ export class TerminalService { 'Content-Type': 'application/json', 'Authorization': `Bearer ${TokenService.getToken()}` }); - return this.http.get(`${baseURL}api/v1/analytic/terminal_statistic`, { headers: headers }); + return this.http.post(`${baseURL}api/v1/analytic/terminal_statistic`,{body: {}}, { headers: headers }); } } diff --git a/src/app/services/token.service.ts b/src/app/services/token.service.ts index 3ff1136..49feb34 100644 --- a/src/app/services/token.service.ts +++ b/src/app/services/token.service.ts @@ -1,8 +1,13 @@ import { Injectable } from '@angular/core'; import * as jwt_decode from 'jwt-decode'; +import { JwtHelperService } from '@auth0/angular-jwt'; +import { UtilService } from './util.service'; export class TokenService { + static helper = new JwtHelperService(); + + static getToken(): string | null { return localStorage.getItem('token'); // Example using localStorage } @@ -21,6 +26,13 @@ export class TokenService { // return jwt_decode(token); } + static isTokenValid(): boolean{ + if(!TokenService.getToken()){ + throw new Error("token does not exist"); + } + return !TokenService.helper.isTokenExpired(TokenService.getToken()); + } + } diff --git a/src/app/services/util.service.spec.ts b/src/app/services/util.service.spec.ts new file mode 100644 index 0000000..0c837c1 --- /dev/null +++ b/src/app/services/util.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { UtilService } from './util.service'; + +describe('UtilService', () => { + let service: UtilService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(UtilService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/util.service.ts b/src/app/services/util.service.ts new file mode 100644 index 0000000..6a4d5ec --- /dev/null +++ b/src/app/services/util.service.ts @@ -0,0 +1,32 @@ +import { Injectable } from '@angular/core'; + +export class UtilService { + + constructor() { } + + + static setUserDetails(value: string): void | null { + return localStorage.setItem('userDetails', JSON.stringify(value)); + } + + static getUserDetails():any { + let userDetails; + if (localStorage.getItem('userDetails')) { + userDetails = JSON.parse(localStorage.getItem('userDetails') || '{}'); + } + return userDetails; + } + + static clearStorage(): void{ + return localStorage.clear(); + } + + static formatBase64(base64: string): string { + console.log("ans",base64) + + let res = base64.split(",")[1]; + // let res = base64?.replace("data:image/png;base64,", ""); + console.log("ans",res) + return res; + } +} diff --git a/src/app/services/utils.ts b/src/app/services/utils.ts index 3eaf677..db78df9 100644 --- a/src/app/services/utils.ts +++ b/src/app/services/utils.ts @@ -3,4 +3,4 @@ // } -export const baseURL = "https://bfe1-155-93-95-82.ngrok-free.app/"; \ No newline at end of file +export const baseURL = "https://219b-155-93-95-82.ngrok-free.app/"; \ No newline at end of file