From 21af45bfa635facd4726894346d988a3dfd8e1b1 Mon Sep 17 00:00:00 2001 From: Supichai Pothong Date: Thu, 2 Nov 2023 15:53:37 +0700 Subject: [PATCH] [update] --- src/app/auth/login/login.component.ts | 3 +- src/app/core/base/base-store-service.ts | 93 ------------------- .../core/service/auth/cathay-auth.service.ts | 1 - src/app/core/service/common/report.service.ts | 18 ++++ src/app/core/service/common/upload.service.ts | 16 ++++ .../kyc/presenter/list/list.component.html | 8 +- .../kyc/presenter/list/list.component.ts | 1 - .../transactions/transactions.container.html | 2 +- .../transactions/transactions.container.ts | 8 +- .../presenter/list/list.component.html | 48 +++++----- .../presenter/list/list.component.ts | 6 +- .../presenter/dialog/dialog.component.html | 4 +- .../presenter/dialog/dialog.component.ts | 63 ++++--------- .../presenter/dialog/dialog.component.html | 4 +- .../presenter/dialog/dialog.component.ts | 66 ++++--------- 15 files changed, 108 insertions(+), 233 deletions(-) delete mode 100644 src/app/core/base/base-store-service.ts create mode 100644 src/app/core/service/common/report.service.ts create mode 100644 src/app/core/service/common/upload.service.ts diff --git a/src/app/auth/login/login.component.ts b/src/app/auth/login/login.component.ts index 4ad0390..8f9b1d2 100644 --- a/src/app/auth/login/login.component.ts +++ b/src/app/auth/login/login.component.ts @@ -44,7 +44,8 @@ export class LoginComponent implements OnInit { if (!form.valid) return false; try { const result = await lastValueFrom(this.authService.login(this.dataForm)); - // const cathayResult = await lastValueFrom(this.cathayAuthService.login(this.cathayForm)) + const cathayResult: any = await lastValueFrom(this.cathayAuthService.login(this.cathayForm)); + this.appService.setToken(cathayResult.token.token) this.appService.setAuth(result); return this.router.navigate(['/pages']); } catch (err) { diff --git a/src/app/core/base/base-store-service.ts b/src/app/core/base/base-store-service.ts deleted file mode 100644 index 4188a56..0000000 --- a/src/app/core/base/base-store-service.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { HttpClient, HttpEventType } from '@angular/common/http'; -import { Optional } from '@angular/core'; - -import { Observable, of } from 'rxjs'; -import { map, catchError } from 'rxjs/operators'; -import { environment } from 'src/environments/environment'; - -export interface IapiResponse{ - apiResponse:{ - id:number, - desc:string, - }, - data:Array -} - -export class BaseStoreService { - - protected host:string = `${environment.storeApi}` - protected prefix:string = `${this.host}` - protected fullUrl:string = '' - - constructor( - endpoint:string, - protected http: HttpClient, - ) { - this.fullUrl = this.prefix + endpoint - } - - uploadDocument(target: FormData){ - return this.http.post(this.fullUrl,target,{ - reportProgress: true, - observe:'events' - }).pipe( - map((event) => { - switch(event.type){ - case HttpEventType.UploadProgress: - const progress = Math.round(100 * event.loaded / event.total); - return { status: 'progress', message: `${progress}` }; - case HttpEventType.Response: - return { status: 'success', message: event.body }; - default: - return `Unhandled event: ${event.type}`; - } - } - ), - catchError(err => { - return of({ status: 'error', message: `${err.message}` }) - }) - ) - } - - getAll(): Observable{ - return this.http.get(this.fullUrl) - } - - add(data: T): Observable { - return this.http.post(this.fullUrl,data) - } - - get(id: any): Observable { - return this.http.get(`${this.fullUrl}/${id}`) - } - - update(id: number,data: T): Observable{ - return this.http.put(`${this.fullUrl}/${id}`,data) - } - - update2(data: T): Observable{ - return this.http.put(this.fullUrl,data) - } - - - deleteData(id: number | string): Observable { - return this.http.delete(`${this.fullUrl}/${id}`) - } - - query(query: string): Observable { - return this.http.get(`${this.fullUrl}/${query}`) - } - - queryString(query: string): Observable{ - return this.http.get(`${this.fullUrl}?${query}`) - } - - addMany(data: T): Observable { - return this.http.post(`${this.fullUrl}/s`,data) - } - - updateMany(data: T): Observable { - return this.http.put(`${this.fullUrl}/s`,data) - } -} - diff --git a/src/app/core/service/auth/cathay-auth.service.ts b/src/app/core/service/auth/cathay-auth.service.ts index 8789032..c47dac2 100644 --- a/src/app/core/service/auth/cathay-auth.service.ts +++ b/src/app/core/service/auth/cathay-auth.service.ts @@ -18,5 +18,4 @@ export class CathayAuthService extends BaseService{ login(payload : {'mobileDeviceId': string , 'userName': string , 'password' : string}){ return this.http.post(`${this.fullUrl}/login`, payload) } - } diff --git a/src/app/core/service/common/report.service.ts b/src/app/core/service/common/report.service.ts new file mode 100644 index 0000000..2612c91 --- /dev/null +++ b/src/app/core/service/common/report.service.ts @@ -0,0 +1,18 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { BaseService } from 'src/app/core/base/base-service'; +import { environment } from 'src/environments/environment'; + +@Injectable({ + providedIn: 'root' +}) +export class ReportService extends BaseService{ + API_URL = environment.CATHAYAPIURL + constructor( + public http: HttpClient + ) { + super('', http) + super.fullUrl = `${this.API_URL}/v2/Payment/getTransactionWeb` + } + +} diff --git a/src/app/core/service/common/upload.service.ts b/src/app/core/service/common/upload.service.ts new file mode 100644 index 0000000..6f44c44 --- /dev/null +++ b/src/app/core/service/common/upload.service.ts @@ -0,0 +1,16 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { BaseService } from 'src/app/core/base/base-service'; + +@Injectable({ + providedIn: 'root' +}) +export class UploadService extends BaseService{ + + constructor( + public http: HttpClient + ) { + super('/common/upload', http) + } + +} diff --git a/src/app/pages/manage/kyc/presenter/list/list.component.html b/src/app/pages/manage/kyc/presenter/list/list.component.html index 90a376f..e02b9b5 100644 --- a/src/app/pages/manage/kyc/presenter/list/list.component.html +++ b/src/app/pages/manage/kyc/presenter/list/list.component.html @@ -25,7 +25,7 @@ ลำดับ - {{getIndex(i)}} + {{getIndex(i)}} @@ -46,7 +46,7 @@ - คำนำหน้า + คำนำหน้า {{item.prefix_name}} @@ -74,8 +74,8 @@ - E-mail - + E-mail +
{{item.email}}
diff --git a/src/app/pages/manage/kyc/presenter/list/list.component.ts b/src/app/pages/manage/kyc/presenter/list/list.component.ts index 50589f9..d5846f2 100644 --- a/src/app/pages/manage/kyc/presenter/list/list.component.ts +++ b/src/app/pages/manage/kyc/presenter/list/list.component.ts @@ -34,7 +34,6 @@ export class ListComponent extends BaseList implements OnChanges { } onFilterCard($event) { - // this.filterCard.next($event); const filterValue = this.query.card; this.kycList.filter = filterValue.trim().toLowerCase(); } diff --git a/src/app/pages/report/transactions/container/transactions/transactions.container.html b/src/app/pages/report/transactions/container/transactions/transactions.container.html index e42b219..050ebe8 100644 --- a/src/app/pages/report/transactions/container/transactions/transactions.container.html +++ b/src/app/pages/report/transactions/container/transactions/transactions.container.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/app/pages/report/transactions/container/transactions/transactions.container.ts b/src/app/pages/report/transactions/container/transactions/transactions.container.ts index bfa0329..423eb90 100644 --- a/src/app/pages/report/transactions/container/transactions/transactions.container.ts +++ b/src/app/pages/report/transactions/container/transactions/transactions.container.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import { Observable } from 'rxjs'; -import { KycService } from 'src/app/core/service/common/kyc.service'; +import { ReportService } from 'src/app/core/service/common/report.service'; @Component({ selector: 'app-transactions', @@ -8,10 +8,10 @@ import { KycService } from 'src/app/core/service/common/kyc.service'; styleUrls: ['./transactions.container.scss'] }) export class TransactionsContainer { - kyc$ = new Observable(); + report$ = new Observable(); constructor( - private kycService: KycService + private reportService: ReportService ) { - this.kyc$ = this.kycService.getAll(); + this.report$ = this.reportService.getAll() } } diff --git a/src/app/pages/report/transactions/presenter/list/list.component.html b/src/app/pages/report/transactions/presenter/list/list.component.html index d9d22f8..c0e33db 100644 --- a/src/app/pages/report/transactions/presenter/list/list.component.html +++ b/src/app/pages/report/transactions/presenter/list/list.component.html @@ -15,15 +15,17 @@
- - - + + + +
- - - + + + +
@@ -31,51 +33,51 @@
- +
- + - + - + - + - + - + - + @@ -87,35 +89,31 @@ @@ -131,6 +129,6 @@
ลำดับ{{item.code}}{{getIndex(i)}} Phone - {{item.name }} + {{item.phoneNumber}} ID{{item?.masterProductBrand.name }}{{ item.id }} PayeeFullname{{item?.masterProductBrand.name }}{{ item?.payeeUserAccountId }} PayerFullname{{item.size }}{{ item.payerUserAccountId }} InvoiceID{{item.weight }}{{ item.invoiceId }} ref 1{{item.color }}{{ item.referencE1 }} ref 2{{item.year }}{{ item.referencE2 }} paymentStatus -
{{item.latestPrice | number : '1.2-2' }}
+
{{ item.referencE3 }}
payment Channel -
-
- -
-
+
{{ item.paymentChannel }}
จำนวนเงิน -
{{item.latestPrice | number : '1.2-2' }}
+
{{ item.amount | number : '1.2-2' }}
Create by -
{{item.latestPrice | number : '1.2-2' }}
+
{{ item.createBy }}
Update by -
{{item.latestPrice | number : '1.2-2' }}
+
{{ item.updateBy }}
- +
\ No newline at end of file diff --git a/src/app/pages/report/transactions/presenter/list/list.component.ts b/src/app/pages/report/transactions/presenter/list/list.component.ts index 76bc684..6d64e79 100644 --- a/src/app/pages/report/transactions/presenter/list/list.component.ts +++ b/src/app/pages/report/transactions/presenter/list/list.component.ts @@ -6,12 +6,12 @@ import { Component, Input } from '@angular/core'; styleUrls: ['./list.component.scss'] }) export class ListComponent { - @Input() kycList: any = []; + @Input() reportList: any = []; constructor() { } - getData(event: any) { - + test(){ + console.log('test') } } diff --git a/src/app/pages/setting/banner/presenter/dialog/dialog.component.html b/src/app/pages/setting/banner/presenter/dialog/dialog.component.html index 1a47974..176d464 100644 --- a/src/app/pages/setting/banner/presenter/dialog/dialog.component.html +++ b/src/app/pages/setting/banner/presenter/dialog/dialog.component.html @@ -59,14 +59,14 @@
แนบรูป
-
+
- +
diff --git a/src/app/pages/setting/banner/presenter/dialog/dialog.component.ts b/src/app/pages/setting/banner/presenter/dialog/dialog.component.ts index f1008d2..5920f59 100644 --- a/src/app/pages/setting/banner/presenter/dialog/dialog.component.ts +++ b/src/app/pages/setting/banner/presenter/dialog/dialog.component.ts @@ -3,12 +3,13 @@ import { ChangeDetectorRef, Component, Inject, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { ActivatedRoute, Router } from '@angular/router'; -import { catchError, tap, throwError } from 'rxjs'; +import { catchError, lastValueFrom, tap, throwError } from 'rxjs'; import { IDialogConfigData } from 'src/app/@common/interface/Dialog'; import { EAction, EText } from 'src/app/@config/app'; import { AppService } from 'src/app/app.service'; import { BaseForm } from 'src/app/core/base/base-form'; import { BannerService } from 'src/app/core/service/common/banner.service'; +import { UploadService } from 'src/app/core/service/common/upload.service'; @Component({ selector: 'app-dialog', @@ -25,6 +26,7 @@ export class DialogComponent extends BaseForm implements OnInit { public location: Location, public bannerService: BannerService, public appService: AppService, + public uploadService: UploadService, public cdr: ChangeDetectorRef ) { super(router, activatedRoute, fb, location) @@ -82,61 +84,28 @@ export class DialogComponent extends BaseForm implements OnInit { ).subscribe() } - // async onSubmit(form: any) { - // if (!form.valid) return false; - - // const sweetalert = await lastValueFrom(this.appService.confirm(EAction.CREATE)); - // if (!sweetalert.isConfirmed) return; - - // this.dataForm.images = this.attachments?.[0] ? this.attachments.join(",") : null; - - // this.dataForm.pageAction = 'financePaying'; - // return await this.onUpdate(); - - // } - - - // async onUpdate() { - // try { - // await lastValueFrom(this.appService.post(`${this.api.quotation}/update/${this.ids}`, this.dataForm)); - // await this.appService.message(EAction.SUCCESS, EText.UPDATE); - // await this.router.navigate(["/pages/finance/paying/list", this.action]); - // } catch (err) { - // this.appService.message(EAction.ERROR, EText.ERROR); - - // } - // } - async onAttachments($event: any) { const file = $event.target.files[0]; if (!file) return; const formData = new FormData(); formData.append("ref", 'images'); formData.append("file", file); - // try { - // const res = await lastValueFrom(this.appService.post(`${API.attachments}/images`, formData)); - // this.dataForm.sellerPaymentImages = res.fileName; - // this.uploadFile.nativeElement.value = null; - // this.changeDetectorRef.detectChanges(); - // } catch (e) { - // this.appService.message(EText.ERROR); - // } + try { + const res = await lastValueFrom(this.uploadService.add(formData)); + this.form.get('file_url').setValue(res[0].file_name) + this.form.get('file_name').setValue(res[0].name) + this.cdr.detectChanges(); + } catch (e) { + this.appService.message(EText.ERROR); + } } - async onRemoveAttachments() { - // const sweetalert = await lastValueFrom(this.appService.confirm(EAction.DELETE)); - // if (!sweetalert.isConfirmed) return; - // this.dataForm.paymentImages = null; - // this.changeDetectorRef.detectChanges(); + onRemoveAttachments() { + this.form.get('file_url').setValue(null) + this.form.get('file_name').setValue(null) } - async onAttachmentsView() { - // const dialogConfig = deepCopy(this.dialogConfig); - // dialogConfig.data.action = EAction.POPUP; - // dialogConfig.data.title = 'ไฟล์แนบ'; - // dialogConfig.data.type = 'images'; - // dialogConfig.data.images = this.dataForm.sellerPaymentImages; - // const dialogRef = this.attachmentsView.open(AttachmentsViewComponent, dialogConfig); - // const afterClosed = await lastValueFrom(dialogRef.afterClosed()); + onAttachmentsView() { + window.open(this.form.get('file_url').value) } } diff --git a/src/app/pages/setting/promotion/presenter/dialog/dialog.component.html b/src/app/pages/setting/promotion/presenter/dialog/dialog.component.html index 1994f9c..3256f05 100644 --- a/src/app/pages/setting/promotion/presenter/dialog/dialog.component.html +++ b/src/app/pages/setting/promotion/presenter/dialog/dialog.component.html @@ -59,14 +59,14 @@
แนบรูป
-
+
- +
diff --git a/src/app/pages/setting/promotion/presenter/dialog/dialog.component.ts b/src/app/pages/setting/promotion/presenter/dialog/dialog.component.ts index a47fe17..051d440 100644 --- a/src/app/pages/setting/promotion/presenter/dialog/dialog.component.ts +++ b/src/app/pages/setting/promotion/presenter/dialog/dialog.component.ts @@ -3,12 +3,13 @@ import { ChangeDetectorRef, Component, Inject, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { ActivatedRoute, Router } from '@angular/router'; -import { catchError, tap, throwError } from 'rxjs'; +import { catchError, lastValueFrom, tap, throwError } from 'rxjs'; import { IDialogConfigData } from 'src/app/@common/interface/Dialog'; import { EAction, EText } from 'src/app/@config/app'; import { AppService } from 'src/app/app.service'; import { BaseForm } from 'src/app/core/base/base-form'; import { PromotionService } from 'src/app/core/service/common/promotion.service'; +import { UploadService } from 'src/app/core/service/common/upload.service'; @Component({ selector: 'app-dialog', @@ -16,7 +17,6 @@ import { PromotionService } from 'src/app/core/service/common/promotion.service' styleUrls: ['./dialog.component.scss'] }) export class DialogComponent extends BaseForm implements OnInit { - data = false; constructor( public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public dialog: IDialogConfigData, @@ -26,7 +26,8 @@ export class DialogComponent extends BaseForm implements OnInit { public location: Location, public promotionService: PromotionService, public appService: AppService, - public cdr: ChangeDetectorRef + public cdr: ChangeDetectorRef, + public uploadService: UploadService ) { super(router, activatedRoute, fb, location) } @@ -83,61 +84,28 @@ export class DialogComponent extends BaseForm implements OnInit { ).subscribe() } - // async onSubmit(form: any) { - // if (!form.valid) return false; - - // const sweetalert = await lastValueFrom(this.appService.confirm(EAction.CREATE)); - // if (!sweetalert.isConfirmed) return; - - // this.dataForm.images = this.attachments?.[0] ? this.attachments.join(",") : null; - - // this.dataForm.pageAction = 'financePaying'; - // return await this.onUpdate(); - - // } - - - // async onUpdate() { - // try { - // await lastValueFrom(this.appService.post(`${this.api.quotation}/update/${this.ids}`, this.dataForm)); - // await this.appService.message(EAction.SUCCESS, EText.UPDATE); - // await this.router.navigate(["/pages/finance/paying/list", this.action]); - // } catch (err) { - // this.appService.message(EAction.ERROR, EText.ERROR); - - // } - // } - async onAttachments($event: any) { const file = $event.target.files[0]; if (!file) return; const formData = new FormData(); formData.append("ref", 'images'); formData.append("file", file); - // try { - // const res = await lastValueFrom(this.appService.post(`${API.attachments}/images`, formData)); - // this.dataForm.sellerPaymentImages = res.fileName; - // this.uploadFile.nativeElement.value = null; - // this.changeDetectorRef.detectChanges(); - // } catch (e) { - // this.appService.message(EText.ERROR); - // } + try { + const res = await lastValueFrom(this.uploadService.add(formData)); + this.form.get('file_url').setValue(res[0].file_name) + this.form.get('file_name').setValue(res[0].name) + this.cdr.detectChanges(); + } catch (e) { + this.appService.message(EText.ERROR); + } } - async onRemoveAttachments() { - // const sweetalert = await lastValueFrom(this.appService.confirm(EAction.DELETE)); - // if (!sweetalert.isConfirmed) return; - // this.dataForm.paymentImages = null; - // this.changeDetectorRef.detectChanges(); + onRemoveAttachments() { + this.form.get('file_url').setValue(null) + this.form.get('file_name').setValue(null) } - async onAttachmentsView() { - // const dialogConfig = deepCopy(this.dialogConfig); - // dialogConfig.data.action = EAction.POPUP; - // dialogConfig.data.title = 'ไฟล์แนบ'; - // dialogConfig.data.type = 'images'; - // dialogConfig.data.images = this.dataForm.sellerPaymentImages; - // const dialogRef = this.attachmentsView.open(AttachmentsViewComponent, dialogConfig); - // const afterClosed = await lastValueFrom(dialogRef.afterClosed()); + onAttachmentsView() { + window.open(this.form.get('file_url').value) } }