251225:1703 On going update to 1.7.0: Refoctory drawing Module not finish
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
// File: lib/api/client.ts
|
||||
import axios, { AxiosInstance, InternalAxiosRequestConfig, AxiosError } from "axios";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { getSession } from "next-auth/react";
|
||||
|
||||
// อ่านค่า Base URL จาก Environment Variable
|
||||
const baseURL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001/api";
|
||||
@@ -29,18 +28,20 @@ apiClient.interceptors.request.use(
|
||||
}
|
||||
|
||||
// 2. Authentication Token Injection
|
||||
// ดึง Session จาก NextAuth (ทำงานเฉพาะฝั่ง Client)
|
||||
// ดึง Token จาก Zustand persist store (localStorage)
|
||||
if (typeof window !== "undefined") {
|
||||
try {
|
||||
const session = await getSession();
|
||||
// @ts-ignore: Session type extended in types/next-auth.d.ts
|
||||
const token = session?.accessToken;
|
||||
const authStorage = localStorage.getItem('auth-storage');
|
||||
if (authStorage) {
|
||||
const parsed = JSON.parse(authStorage);
|
||||
const token = parsed?.state?.token;
|
||||
|
||||
if (token) {
|
||||
config.headers["Authorization"] = `Bearer ${token}`;
|
||||
if (token) {
|
||||
config.headers["Authorization"] = `Bearer ${token}`;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Failed to retrieve session token:", error);
|
||||
console.warn("Failed to retrieve auth token:", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,4 +74,4 @@ apiClient.interceptors.response.use(
|
||||
}
|
||||
);
|
||||
|
||||
export default apiClient;
|
||||
export default apiClient;
|
||||
|
||||
@@ -274,18 +274,19 @@ export const numberingApi = {
|
||||
*/
|
||||
previewNumber: async (ctx: {
|
||||
projectId: number;
|
||||
originatorId: number;
|
||||
typeId: number;
|
||||
originatorOrganizationId: number;
|
||||
correspondenceTypeId: number;
|
||||
disciplineId?: number;
|
||||
subTypeId?: number;
|
||||
rfaTypeId?: number;
|
||||
recipientOrganizationId?: number;
|
||||
}): Promise<{ previewNumber: string; nextSequence: number }> => {
|
||||
const res = await apiClient.post<{ previewNumber: string; nextSequence: number }>(
|
||||
const res = await apiClient.post<{ data: { previewNumber: string; nextSequence: number } }>(
|
||||
'/document-numbering/preview',
|
||||
ctx
|
||||
);
|
||||
return res.data;
|
||||
// Backend wraps response in { data: { ... }, message: "Success" }
|
||||
return res.data.data || res.data;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
245
frontend/lib/services/drawing-master-data.service.ts
Normal file
245
frontend/lib/services/drawing-master-data.service.ts
Normal file
@@ -0,0 +1,245 @@
|
||||
// File: lib/services/drawing-master-data.service.ts
|
||||
import apiClient from "@/lib/api/client";
|
||||
|
||||
// ===========================
|
||||
// Contract Drawing Volumes
|
||||
// ===========================
|
||||
export interface ContractVolume {
|
||||
id: number;
|
||||
projectId: number;
|
||||
volumeCode: string;
|
||||
volumeName: string;
|
||||
description?: string;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
export interface CreateContractVolumeDto {
|
||||
projectId: number;
|
||||
volumeCode: string;
|
||||
volumeName: string;
|
||||
description?: string;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Contract Drawing Categories
|
||||
// ===========================
|
||||
export interface ContractCategory {
|
||||
id: number;
|
||||
projectId: number;
|
||||
catCode: string;
|
||||
catName: string;
|
||||
description?: string;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
export interface CreateContractCategoryDto {
|
||||
projectId: number;
|
||||
catCode: string;
|
||||
catName: string;
|
||||
description?: string;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Contract Drawing Sub-categories
|
||||
// ===========================
|
||||
export interface ContractSubCategory {
|
||||
id: number;
|
||||
projectId: number;
|
||||
subCatCode: string;
|
||||
subCatName: string;
|
||||
description?: string;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
export interface CreateContractSubCategoryDto {
|
||||
projectId: number;
|
||||
subCatCode: string;
|
||||
subCatName: string;
|
||||
description?: string;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Shop Drawing Main Categories
|
||||
// ===========================
|
||||
export interface ShopMainCategory {
|
||||
id: number;
|
||||
projectId: number;
|
||||
mainCategoryCode: string;
|
||||
mainCategoryName: string;
|
||||
description?: string;
|
||||
isActive: boolean;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
export interface CreateShopMainCategoryDto {
|
||||
projectId: number;
|
||||
mainCategoryCode: string;
|
||||
mainCategoryName: string;
|
||||
description?: string;
|
||||
isActive?: boolean;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Shop Drawing Sub-categories
|
||||
// ===========================
|
||||
export interface ShopSubCategory {
|
||||
id: number;
|
||||
projectId: number;
|
||||
subCategoryCode: string;
|
||||
subCategoryName: string;
|
||||
description?: string;
|
||||
isActive: boolean;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
export interface CreateShopSubCategoryDto {
|
||||
projectId: number;
|
||||
subCategoryCode: string;
|
||||
subCategoryName: string;
|
||||
description?: string;
|
||||
isActive?: boolean;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// Service
|
||||
// ===========================
|
||||
export const drawingMasterDataService = {
|
||||
// --- Contract Volumes ---
|
||||
async getContractVolumes(projectId: number): Promise<ContractVolume[]> {
|
||||
const response = await apiClient.get(`/drawings/master-data/contract/volumes`, {
|
||||
params: { projectId },
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async createContractVolume(data: CreateContractVolumeDto): Promise<ContractVolume> {
|
||||
const response = await apiClient.post(`/drawings/master-data/contract/volumes`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async updateContractVolume(id: number, data: Partial<CreateContractVolumeDto>): Promise<ContractVolume> {
|
||||
const response = await apiClient.patch(`/drawings/master-data/contract/volumes/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async deleteContractVolume(id: number): Promise<void> {
|
||||
await apiClient.delete(`/drawings/master-data/contract/volumes/${id}`);
|
||||
},
|
||||
|
||||
// --- Contract Categories ---
|
||||
async getContractCategories(projectId: number): Promise<ContractCategory[]> {
|
||||
const response = await apiClient.get(`/drawings/master-data/contract/categories`, {
|
||||
params: { projectId },
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async createContractCategory(data: CreateContractCategoryDto): Promise<ContractCategory> {
|
||||
const response = await apiClient.post(`/drawings/master-data/contract/categories`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async updateContractCategory(id: number, data: Partial<CreateContractCategoryDto>): Promise<ContractCategory> {
|
||||
const response = await apiClient.patch(`/drawings/master-data/contract/categories/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async deleteContractCategory(id: number): Promise<void> {
|
||||
await apiClient.delete(`/drawings/master-data/contract/categories/${id}`);
|
||||
},
|
||||
|
||||
// --- Contract Sub-categories ---
|
||||
async getContractSubCategories(projectId: number): Promise<ContractSubCategory[]> {
|
||||
const response = await apiClient.get(`/drawings/master-data/contract/sub-categories`, {
|
||||
params: { projectId },
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async createContractSubCategory(data: CreateContractSubCategoryDto): Promise<ContractSubCategory> {
|
||||
const response = await apiClient.post(`/drawings/master-data/contract/sub-categories`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async updateContractSubCategory(id: number, data: Partial<CreateContractSubCategoryDto>): Promise<ContractSubCategory> {
|
||||
const response = await apiClient.patch(`/drawings/master-data/contract/sub-categories/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async deleteContractSubCategory(id: number): Promise<void> {
|
||||
await apiClient.delete(`/drawings/master-data/contract/sub-categories/${id}`);
|
||||
},
|
||||
|
||||
// --- Contract Category Mappings ---
|
||||
async getContractMappings(
|
||||
projectId: number,
|
||||
categoryId?: number
|
||||
): Promise<{ id: number; subCategory: ContractSubCategory; category: ContractCategory }[]> {
|
||||
const response = await apiClient.get(`/drawings/master-data/contract/mappings`, {
|
||||
params: { projectId, categoryId },
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async createContractMapping(data: {
|
||||
projectId: number;
|
||||
categoryId: number;
|
||||
subCategoryId: number;
|
||||
}): Promise<{ id: number }> {
|
||||
const response = await apiClient.post(`/drawings/master-data/contract/mappings`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async deleteContractMapping(id: number): Promise<void> {
|
||||
await apiClient.delete(`/drawings/master-data/contract/mappings/${id}`);
|
||||
},
|
||||
|
||||
// --- Shop Main Categories ---
|
||||
async getShopMainCategories(projectId: number): Promise<ShopMainCategory[]> {
|
||||
const response = await apiClient.get(`/drawings/master-data/shop/main-categories`, {
|
||||
params: { projectId },
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async createShopMainCategory(data: CreateShopMainCategoryDto): Promise<ShopMainCategory> {
|
||||
const response = await apiClient.post(`/drawings/master-data/shop/main-categories`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async updateShopMainCategory(id: number, data: Partial<CreateShopMainCategoryDto>): Promise<ShopMainCategory> {
|
||||
const response = await apiClient.patch(`/drawings/master-data/shop/main-categories/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async deleteShopMainCategory(id: number): Promise<void> {
|
||||
await apiClient.delete(`/drawings/master-data/shop/main-categories/${id}`);
|
||||
},
|
||||
|
||||
// --- Shop Sub-categories ---
|
||||
async getShopSubCategories(projectId: number, mainCategoryId?: number): Promise<ShopSubCategory[]> {
|
||||
const response = await apiClient.get(`/drawings/master-data/shop/sub-categories`, {
|
||||
params: { projectId, mainCategoryId },
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async createShopSubCategory(data: CreateShopSubCategoryDto): Promise<ShopSubCategory> {
|
||||
const response = await apiClient.post(`/drawings/master-data/shop/sub-categories`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async updateShopSubCategory(id: number, data: Partial<CreateShopSubCategoryDto>): Promise<ShopSubCategory> {
|
||||
const response = await apiClient.patch(`/drawings/master-data/shop/sub-categories/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async deleteShopSubCategory(id: number): Promise<void> {
|
||||
await apiClient.delete(`/drawings/master-data/shop/sub-categories/${id}`);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user