Files
lcbp3/frontend/lib/services/rfa.service.ts
T
admin 4cd0952482
CI / CD Pipeline / build (push) Failing after 1m52s
CI / CD Pipeline / deploy (push) Has been skipped
260324:1349 Refactor RFA #01
2026-03-24 13:49:30 +07:00

76 lines
2.4 KiB
TypeScript

// File: lib/services/rfa.service.ts
import apiClient from '@/lib/api/client';
import { CreateRfaDto, UpdateRfaDto, SearchRfaDto } from '@/types/dto/rfa/rfa.dto';
// DTO สำหรับการอนุมัติ (อาจจะย้ายไปไว้ใน folder dto/rfa/ ก็ได้ในอนาคต)
export interface WorkflowActionDto {
action: 'APPROVE' | 'REJECT' | 'COMMENT' | 'ACKNOWLEDGE';
comments?: string;
stepNumber?: number; // อาจจะไม่จำเป็นถ้า Backend เช็ค state ปัจจุบันได้เอง
}
export const rfaService = {
/**
* ดึงรายการ RFA ทั้งหมด (รองรับ Search & Filter)
*/
getAll: async (params: SearchRfaDto) => {
// GET /rfas
const response = await apiClient.get('/rfas', { params });
return response.data;
},
/**
* ดึงรายละเอียด RFA และประวัติ Workflow
*/
getByUuid: async (uuid: string) => {
// GET /rfas/:uuid (ADR-019)
const response = await apiClient.get(`/rfas/${uuid}`);
return response.data;
},
/**
* สร้าง RFA ใหม่
*/
create: async (data: CreateRfaDto) => {
// POST /rfas
const response = await apiClient.post('/rfas', data);
return response.data;
},
/**
* Submit a Draft RFA to workflow
*/
submit: async (uuid: string, templateId: number) => {
// POST /rfas/:uuid/submit (ADR-019)
const response = await apiClient.post(`/rfas/${uuid}/submit`, { templateId });
return response.data;
},
/**
* แก้ไข RFA (เฉพาะสถานะ Draft)
*/
update: async (uuid: string, data: UpdateRfaDto) => {
// PUT /rfas/:uuid (ADR-019)
const response = await apiClient.put(`/rfas/${uuid}`, data);
return response.data;
},
/**
* ดำเนินการ Workflow (อนุมัติ / ตีกลับ / ส่งต่อ)
*/
processWorkflow: async (uuid: string, actionData: WorkflowActionDto) => {
// POST /rfas/:uuid/action (ADR-019)
const response = await apiClient.post(`/rfas/${uuid}/action`, actionData);
return response.data;
},
/**
* (Optional) ลบ RFA (Soft Delete)
*/
delete: async (uuid: string) => {
// DELETE /rfas/:uuid (ADR-019)
const response = await apiClient.delete(`/rfas/${uuid}`);
return response.data;
},
};