-general service formdata compltetible
All checks were successful
Build Docker Image / Build Docker Image (push) Successful in 7m27s
Build Docker Image / Restart Docker Compose (push) Successful in 1s

-projectAdd
This commit is contained in:
x2Skyz
2025-11-30 22:06:03 +07:00
parent f0f3392dbb
commit 07d49d87cf
7 changed files with 325 additions and 196 deletions

View File

@@ -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 {

View File

@@ -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>
}

View File

@@ -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']);
}
});
}
}