오류류

This commit is contained in:
chpark 2025-01-10 17:50:59 +09:00
parent dedc797c53
commit 0a8e8c52e2
4 changed files with 36 additions and 28 deletions

View File

@ -42,12 +42,11 @@ router.post(
} }
); );
// Update carMng // Update
router.put( router.put(
"/carmngUpdate/:id", "/Update/:id",
[ [
param("id").isUUID().withMessage("유효한 ID가 필요합니다"), param("id").isUUID().withMessage("유효한 ID가 필요합니다"),
body("car_code").optional().notEmpty().withMessage("car 코드가 필요합니다"),
body("oem_id").optional().notEmpty().withMessage("고객사가 필요합니다"), body("oem_id").optional().notEmpty().withMessage("고객사가 필요합니다"),
body("companyId").optional().isUUID().withMessage("유효한 회사 ID가 필요합니다"), body("companyId").optional().isUUID().withMessage("유효한 회사 ID가 필요합니다"),
validate, validate,
@ -70,7 +69,7 @@ router.put(
}); });
} }
const updatedcarMng = await Service.updateCarMng(req.params.id, req.body, req.user); const updatedcarMng = await Service.update(req.params.id, req.body, req.user);
res.json(updatedcarMng); res.json(updatedcarMng);
} catch (error) { } catch (error) {
next(error); next(error);
@ -80,7 +79,7 @@ router.put(
// Delete CarMng // Delete CarMng
router.delete( router.delete(
"/carmngDelete/:id", "/Delete/:id",
[ [
param("id").isUUID().withMessage("유효한 ID가 필요합니다"), param("id").isUUID().withMessage("유효한 ID가 필요합니다"),
validate, validate,

View File

@ -113,13 +113,13 @@ class ContractWbsService {
return ResultData; return ResultData;
} }
async updateCarMng(id, updateData, currentUser) { async update(id, updateData, currentUser) {
const { roleId, ...carMngFields } = updateData; const { roleId, ...carMngFields } = updateData;
const carMng = await ContractWbs.findByPk(id); const carMng = await ContractWbs.findByPk(id);
if (!carMng) throw new Error("CarMng not found"); if (!carMng) throw new Error("CarMng not found");
// company_admin은 특정 필드를 수정할 수 없음 (예: role을 super_admin으로 변경 불가) // company_admin 권한 체크
if (currentUser.role === "company_admin") { if (currentUser.role === "company_admin") {
if (updateData.role && updateData.role === "super_admin") { if (updateData.role && updateData.role === "super_admin") {
throw new Error("super_admin 역할을 부여할 수 없습니다"); throw new Error("super_admin 역할을 부여할 수 없습니다");
@ -127,7 +127,13 @@ class ContractWbsService {
updateData.companyId = currentUser.companyId; updateData.companyId = currentUser.companyId;
} }
const updatedCarMng = await ContractWbs.update(carMngFields); // where 조건을 포함하여 업데이트
await ContractWbs.update(carMngFields, {
where: { id: id }
});
// 업데이트된 데이터 조회
const updatedCarMng = await ContractWbs.findByPk(id);
if (roleId) { if (roleId) {
const role = await Role.findOne({ const role = await Role.findOne({

View File

@ -47,7 +47,7 @@ const Page = () => {
}); });
return { return {
...data, ...data,
contractWbss: data.resultData.map((wbs: contractWbs) => ({ // resultData 사용 resultData: data.resultData.map((wbs: contractWbs) => ({ // resultData 사용
...wbs, ...wbs,
})), })),
}; };
@ -86,7 +86,7 @@ const Page = () => {
return data; return data;
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["carMngs"] }); queryClient.invalidateQueries({ queryKey: ["contractWbs"] }); // carMngs에서 contractWbs로 수정
setIsOpen(false); setIsOpen(false);
toast({ toast({
title: "영업 WBS 생성", title: "영업 WBS 생성",
@ -104,25 +104,25 @@ const Page = () => {
// Update user mutation // Update user mutation
const updateMutation = useMutation({ const updateMutation = useMutation({
mutationFn: async (carData: Partial<contractWbs>) => { mutationFn: async (contractWbsData: Partial<contractWbs>) => {
const { data } = await api.put<contractWbs>( const { data } = await api.put<contractWbs>(
`/api/v1/app/contractwbs/carmngUpdate/${carData.id}`, `/api/v1/app/contractwbs/Update/${contractWbsData.id}`,
carData contractWbsData
); );
return data; return data;
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["carMngs"] }); queryClient.invalidateQueries({ queryKey: ["contractWbs"] }); // carMngs에서 contractWbs로 수정
setIsOpen(false); setIsOpen(false);
setEditingUser(null); setEditingUser(null);
toast({ toast({
title: "차종 수정", title: "영업 WBS 수정",
description: "차종 정보가 수정되었습니다.", description: "영업 WBS 정보가 수정되었습니다.",
}); });
}, },
onError: (error: AxiosError) => { onError: (error: AxiosError) => {
toast({ toast({
title: "차종 수정 실패", title: "영업 WBS 수정 실패",
description: (error.response?.data as { message: string }).message, description: (error.response?.data as { message: string }).message,
variant: "destructive", variant: "destructive",
}); });
@ -132,10 +132,10 @@ const Page = () => {
// Delete user mutation // Delete user mutation
const deleteMutation = useMutation({ const deleteMutation = useMutation({
mutationFn: async (id: string) => { mutationFn: async (id: string) => {
await api.delete(`/api/v1/app/contractwbs/carmngDelete/${id}`); await api.delete(`/api/v1/app/contractwbs/Delete/${id}`);
}, },
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["carMngs"] }); queryClient.invalidateQueries({ queryKey: ["contractWbs"] }); // carMngs에서 contractWbs로 수정
toast({ toast({
title: "영업 WBS 삭제", title: "영업 WBS 삭제",
description: "영업 WBS가 삭제되었습니다.", description: "영업 WBS가 삭제되었습니다.",
@ -163,7 +163,7 @@ const Page = () => {
}, },
{ {
accessorKey: "oem.oem_name", // 중첩 객체 접근 방식 확인 accessorKey: "oem.oem_name", // 중첩 객체 접근 방식 확인
header: "고객사", header: "고객사",
meta: { meta: {
width: "120px", width: "120px",
textAlign: "center", textAlign: "center",
@ -179,31 +179,35 @@ const Page = () => {
}, },
{ {
accessorKey: "car_code", accessorKey: "car_code",
header: "차종코드", header: "WBS",
meta: { meta: {
width: "120px", width: "120px",
textAlign: "center", textAlign: "center",
}, },
}, },
{ {
accessorKey: "code.code_name", accessorKey: "writer",
header: "차종grade", header: "등록자",
meta: { meta: {
width: "120px", width: "120px",
textAlign: "center", textAlign: "center",
}, },
}, },
{ {
accessorKey: "car_desc", accessorKey: "updatedAt",
header: "설명", header: "등록일",
meta: { meta: {
width: "200px", width: "200px",
textAlign: "center", textAlign: "center",
}, },
cell: ({ row }) => {
const date = new Date(row.original.updatedAt);
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`;
}
}, },
{ {
accessorKey: "isActive", accessorKey: "isActive",
header: "활성화", header: "상태",
meta: { meta: {
width: "100px", width: "100px",
textAlign: "center", textAlign: "center",

View File

@ -19,5 +19,4 @@ export interface PaginatedResponse {
total: number; total: number;
totalPages: number; totalPages: number;
currentPage: number; currentPage: number;
resultData: contractWbs[]; // contractWbss가 아닌 resultData로 수정 resultData: contractWbs[];
}