-general service formdata compltetible
-projectAdd
This commit is contained in:
@@ -59,6 +59,9 @@ export class LoginContentComponent implements OnInit {
|
||||
if (result.code === '200' && result.data?.token) {
|
||||
this.generalService.trowApi(result);
|
||||
localStorage.setItem('access_token', result.data.token);
|
||||
localStorage.setItem('id', result.data.usrseq);
|
||||
localStorage.setItem('usrthinam', result.data.usrthinam);
|
||||
localStorage.setItem('usrthilstnam', result.data.usrthilstnam);
|
||||
this.jwtService.restartCountdown();
|
||||
this.router.navigate(['main']);
|
||||
} else {
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<app-main-project></app-main-project>
|
||||
} @else if ( mode == 'add') {
|
||||
<app-main-project-add
|
||||
(save)="onSaveProject($event)"
|
||||
(projectAddSave)="onProjectAddSave($event)"
|
||||
(cancel)="onCancelProject()">
|
||||
</app-main-project-add>
|
||||
}
|
||||
|
||||
@@ -40,34 +40,34 @@ export class MainProjectContent implements OnInit {
|
||||
}
|
||||
|
||||
// รับ Event (save) จากลูก แล้วยิง API
|
||||
onSaveProject(projectData: any): void {
|
||||
// เปิด Loading ที่ลูก
|
||||
if (this.mainProjectAdd) {
|
||||
this.mainProjectAdd.isLoading = true;
|
||||
}
|
||||
// onSaveProject(projectData: any): void {
|
||||
// // เปิด Loading ที่ลูก
|
||||
// if (this.mainProjectAdd) {
|
||||
// this.mainProjectAdd.isLoading = true;
|
||||
// }
|
||||
|
||||
const uri = '/api/project/create'; // Endpoint Backend
|
||||
// const uri = '/api/project/create'; // Endpoint Backend
|
||||
|
||||
this.generalService.postRequest(uri, projectData).subscribe({
|
||||
next: (result: any) => {
|
||||
// ปิด Loading ที่ลูก
|
||||
if (this.mainProjectAdd) this.mainProjectAdd.isLoading = false;
|
||||
// this.generalService.postRequest(uri, projectData).subscribe({
|
||||
// next: (result: any) => {
|
||||
// // ปิด Loading ที่ลูก
|
||||
// if (this.mainProjectAdd) this.mainProjectAdd.isLoading = false;
|
||||
|
||||
this.generalService.trowApi(result);
|
||||
// this.generalService.trowApi(result);
|
||||
|
||||
if (result.code === '200') {
|
||||
// สำเร็จ -> กลับไปหน้ารายการ
|
||||
this.router.navigate(['/main/project']);
|
||||
}
|
||||
},
|
||||
error: (error: any) => {
|
||||
// Error -> ปิด Loading ที่ลูก
|
||||
if (this.mainProjectAdd) this.mainProjectAdd.isLoading = false;
|
||||
// if (result.code === '200') {
|
||||
// // สำเร็จ -> กลับไปหน้ารายการ
|
||||
// this.router.navigate(['/main/project']);
|
||||
// }
|
||||
// },
|
||||
// error: (error: any) => {
|
||||
// // Error -> ปิด Loading ที่ลูก
|
||||
// if (this.mainProjectAdd) this.mainProjectAdd.isLoading = false;
|
||||
|
||||
this.generalService.trowApi(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
// this.generalService.trowApi(error);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// ฟังก์ชันดึงข้อมูลโครงการ และ update state
|
||||
onSearchPrj(): void {
|
||||
@@ -93,4 +93,34 @@ export class MainProjectContent implements OnInit {
|
||||
onCancelProject(): void {
|
||||
this.router.navigate(['/main/project']);
|
||||
}
|
||||
|
||||
onProjectAddSave(value : FormData) {
|
||||
let formData = value;
|
||||
// const formData = new FormData();
|
||||
|
||||
// // 1. ใส่ Text Fields (Key ต้องตรงกับหลังบ้านที่ req.body รับ)
|
||||
// formData.append('prjnam', this.form.get('prjnam').value);
|
||||
// formData.append('prjwntbdg', this.form.get('prjwntbdg').value);
|
||||
// formData.append('typ', 'prj'); // สำคัญ! ตาม Logic ย้ายไฟล์
|
||||
|
||||
// 2. ใส่ไฟล์ (รองรับหลายไฟล์)
|
||||
// สมมติ this.selectedFiles เป็น Array ของ File Object
|
||||
// for (let file of this.selectedFiles) {
|
||||
// formData.append('prjdoc', file); // Key ต้องชื่อ 'prjdoc' ตาม Middleware
|
||||
// }
|
||||
|
||||
// 3. ส่งเข้า Service (ไม่ต้องทำอะไรเพิ่ม มันจะ detect FormData เอง)
|
||||
this.generalService.postRequest('/api/ttc/projectadd', formData).subscribe({
|
||||
next: (res) => {
|
||||
this.generalService.trowApi(res);
|
||||
},
|
||||
error: (err) => {
|
||||
this.generalService.trowApi(err);
|
||||
},
|
||||
complete: () => {
|
||||
this.onSearchPrj();
|
||||
this.router.navigate(['/main/project']);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user