회사코드 입력, 작성자 입력가능하게 수정완료
This commit is contained in:
parent
4dba7c0a16
commit
94e5a5de0b
|
|
@ -12,6 +12,14 @@ export const saveFormData = async (
|
|||
const { companyCode, userId } = req.user as any;
|
||||
const { screenId, tableName, data } = req.body;
|
||||
|
||||
// 🔍 디버깅: 사용자 정보 확인
|
||||
console.log("🔍 [saveFormData] 사용자 정보:", {
|
||||
userId,
|
||||
companyCode,
|
||||
reqUser: req.user,
|
||||
dataWriter: data.writer,
|
||||
});
|
||||
|
||||
// 필수 필드 검증 (screenId는 0일 수 있으므로 undefined 체크)
|
||||
if (screenId === undefined || screenId === null || !tableName || !data) {
|
||||
return res.status(400).json({
|
||||
|
|
@ -25,9 +33,12 @@ export const saveFormData = async (
|
|||
...data,
|
||||
created_by: userId,
|
||||
updated_by: userId,
|
||||
writer: data.writer || userId, // ✅ writer가 없으면 userId로 설정
|
||||
screen_id: screenId,
|
||||
};
|
||||
|
||||
console.log("✅ [saveFormData] 최종 writer 값:", formDataWithMeta.writer);
|
||||
|
||||
// company_code는 사용자가 명시적으로 입력한 경우에만 추가
|
||||
if (data.company_code !== undefined) {
|
||||
formDataWithMeta.company_code = data.company_code;
|
||||
|
|
@ -86,6 +97,7 @@ export const saveFormDataEnhanced = async (
|
|||
...data,
|
||||
created_by: userId,
|
||||
updated_by: userId,
|
||||
writer: data.writer || userId, // ✅ writer가 없으면 userId로 설정
|
||||
screen_id: screenId,
|
||||
};
|
||||
|
||||
|
|
@ -134,6 +146,7 @@ export const updateFormData = async (
|
|||
const formDataWithMeta = {
|
||||
...data,
|
||||
updated_by: userId,
|
||||
writer: data.writer || userId, // ✅ writer가 없으면 userId로 설정
|
||||
updated_at: new Date(),
|
||||
};
|
||||
|
||||
|
|
@ -186,6 +199,7 @@ export const updateFormDataPartial = async (
|
|||
const newDataWithMeta = {
|
||||
...newData,
|
||||
updated_by: userId,
|
||||
writer: newData.writer || userId, // ✅ writer가 없으면 userId로 설정
|
||||
};
|
||||
|
||||
const result = await dynamicFormService.updateFormDataPartial(
|
||||
|
|
|
|||
|
|
@ -363,7 +363,7 @@ export class DDLExecutionService {
|
|||
"id" varchar(500) PRIMARY KEY DEFAULT gen_random_uuid()::text,
|
||||
"created_date" timestamp DEFAULT now(),
|
||||
"updated_date" timestamp DEFAULT now(),
|
||||
"writer" varchar(500),
|
||||
"writer" varchar(500) DEFAULT NULL,
|
||||
"company_code" varchar(500)`;
|
||||
|
||||
// 최종 CREATE TABLE 쿼리
|
||||
|
|
|
|||
|
|
@ -1221,6 +1221,12 @@ export const InteractiveScreenViewer: React.FC<InteractiveScreenViewerProps> = (
|
|||
const handleSaveAction = async () => {
|
||||
// console.log("💾 저장 시작");
|
||||
|
||||
// ✅ 사용자 정보가 로드되지 않았으면 저장 불가
|
||||
if (!user?.userId) {
|
||||
alert("사용자 정보를 불러오는 중입니다. 잠시 후 다시 시도해주세요.");
|
||||
return;
|
||||
}
|
||||
|
||||
// 개선된 검증 시스템이 활성화된 경우
|
||||
if (enhancedValidation) {
|
||||
// console.log("🔍 개선된 검증 시스템 사용");
|
||||
|
|
@ -1357,19 +1363,26 @@ export const InteractiveScreenViewer: React.FC<InteractiveScreenViewerProps> = (
|
|||
allComponents.find(c => c.columnName)?.tableName ||
|
||||
"dynamic_form_data"; // 기본값
|
||||
|
||||
// 🆕 자동으로 작성자 정보 추가
|
||||
const writerValue = user?.userId || userName || "unknown";
|
||||
// 🆕 자동으로 작성자 정보 추가 (user.userId가 확실히 있음)
|
||||
const writerValue = user.userId;
|
||||
const companyCodeValue = user.companyCode || "";
|
||||
|
||||
console.log("👤 현재 사용자 정보:", {
|
||||
userId: user?.userId,
|
||||
userId: user.userId,
|
||||
userName: userName,
|
||||
writerValue: writerValue,
|
||||
companyCode: user.companyCode, // ✅ 회사 코드
|
||||
formDataWriter: mappedData.writer, // ✅ 폼에서 입력한 writer 값
|
||||
formDataCompanyCode: mappedData.company_code, // ✅ 폼에서 입력한 company_code 값
|
||||
defaultWriterValue: writerValue,
|
||||
companyCodeValue, // ✅ 최종 회사 코드 값
|
||||
});
|
||||
|
||||
const dataWithUserInfo = {
|
||||
...mappedData,
|
||||
writer: writerValue, // 테이블 생성 시 자동 생성되는 컬럼
|
||||
created_by: writerValue,
|
||||
updated_by: writerValue,
|
||||
writer: mappedData.writer || writerValue, // ✅ 입력값 우선, 없으면 userId
|
||||
created_by: writerValue, // created_by는 항상 로그인한 사람
|
||||
updated_by: writerValue, // updated_by는 항상 로그인한 사람
|
||||
company_code: mappedData.company_code || companyCodeValue, // ✅ 입력값 우선, 없으면 user.companyCode
|
||||
};
|
||||
|
||||
const saveData: DynamicFormData = {
|
||||
|
|
|
|||
|
|
@ -190,6 +190,9 @@ export const InteractiveScreenViewerDynamic: React.FC<InteractiveScreenViewerPro
|
|||
onFormDataChange={handleFormDataChange}
|
||||
screenId={screenInfo?.id}
|
||||
tableName={screenInfo?.tableName}
|
||||
userId={user?.userId} // ✅ 사용자 ID 전달
|
||||
userName={user?.userName} // ✅ 사용자 이름 전달
|
||||
companyCode={user?.companyCode} // ✅ 회사 코드 전달
|
||||
selectedRowsData={selectedRowsData}
|
||||
onSelectedRowsChange={(selectedRows, selectedData) => {
|
||||
console.log("🔍 테이블에서 선택된 행 데이터:", selectedData);
|
||||
|
|
|
|||
|
|
@ -105,6 +105,12 @@ export const SaveModal: React.FC<SaveModalProps> = ({
|
|||
const handleSave = async () => {
|
||||
if (!screenData || !screenId) return;
|
||||
|
||||
// ✅ 사용자 정보가 로드되지 않았으면 저장 불가
|
||||
if (!user?.userId) {
|
||||
toast.error("사용자 정보를 불러오는 중입니다. 잠시 후 다시 시도해주세요.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setIsSaving(true);
|
||||
|
||||
|
|
@ -129,19 +135,26 @@ export const SaveModal: React.FC<SaveModalProps> = ({
|
|||
// 저장할 데이터 준비
|
||||
const dataToSave = initialData ? changedData : formData;
|
||||
|
||||
// 🆕 자동으로 작성자 정보 추가
|
||||
const writerValue = user?.userId || userName || "unknown";
|
||||
// 🆕 자동으로 작성자 정보 추가 (user.userId가 확실히 있음)
|
||||
const writerValue = user.userId;
|
||||
const companyCodeValue = user.companyCode || "";
|
||||
|
||||
console.log("👤 현재 사용자 정보:", {
|
||||
userId: user?.userId,
|
||||
userId: user.userId,
|
||||
userName: userName,
|
||||
writerValue: writerValue,
|
||||
companyCode: user.companyCode, // ✅ 회사 코드
|
||||
formDataWriter: dataToSave.writer, // ✅ 폼에서 입력한 writer 값
|
||||
formDataCompanyCode: dataToSave.company_code, // ✅ 폼에서 입력한 company_code 값
|
||||
defaultWriterValue: writerValue,
|
||||
companyCodeValue, // ✅ 최종 회사 코드 값
|
||||
});
|
||||
|
||||
const dataWithUserInfo = {
|
||||
...dataToSave,
|
||||
writer: writerValue, // 테이블 생성 시 자동 생성되는 컬럼
|
||||
created_by: writerValue,
|
||||
updated_by: writerValue,
|
||||
writer: dataToSave.writer || writerValue, // ✅ 입력값 우선, 없으면 userId
|
||||
created_by: writerValue, // created_by는 항상 로그인한 사람
|
||||
updated_by: writerValue, // updated_by는 항상 로그인한 사람
|
||||
company_code: dataToSave.company_code || companyCodeValue, // ✅ 입력값 우선, 없으면 user.companyCode
|
||||
};
|
||||
|
||||
// 테이블명 결정
|
||||
|
|
@ -277,6 +290,9 @@ export const SaveModal: React.FC<SaveModalProps> = ({
|
|||
}}
|
||||
screenId={screenId}
|
||||
tableName={screenData.tableName}
|
||||
userId={user?.userId} // ✅ 사용자 ID 전달
|
||||
userName={user?.userName} // ✅ 사용자 이름 전달
|
||||
companyCode={user?.companyCode} // ✅ 회사 코드 전달
|
||||
formData={formData}
|
||||
originalData={originalData}
|
||||
onFormDataChange={(fieldName, value) => {
|
||||
|
|
|
|||
|
|
@ -284,7 +284,7 @@ export const TableListComponent: React.FC<TableListComponentProps> = ({
|
|||
// 컬럼 라벨 가져오기
|
||||
// ========================================
|
||||
|
||||
const fetchColumnLabels = async () => {
|
||||
const fetchColumnLabels = useCallback(async () => {
|
||||
if (!tableConfig.selectedTable) return;
|
||||
|
||||
try {
|
||||
|
|
@ -339,13 +339,13 @@ export const TableListComponent: React.FC<TableListComponentProps> = ({
|
|||
} catch (error) {
|
||||
console.error("컬럼 라벨 가져오기 실패:", error);
|
||||
}
|
||||
};
|
||||
}, [tableConfig.selectedTable]);
|
||||
|
||||
// ========================================
|
||||
// 테이블 라벨 가져오기
|
||||
// ========================================
|
||||
|
||||
const fetchTableLabel = async () => {
|
||||
const fetchTableLabel = useCallback(async () => {
|
||||
if (!tableConfig.selectedTable) return;
|
||||
|
||||
try {
|
||||
|
|
@ -374,7 +374,7 @@ export const TableListComponent: React.FC<TableListComponentProps> = ({
|
|||
} catch (error) {
|
||||
console.error("테이블 라벨 가져오기 실패:", error);
|
||||
}
|
||||
};
|
||||
}, [tableConfig.selectedTable]);
|
||||
|
||||
// ========================================
|
||||
// 데이터 가져오기
|
||||
|
|
@ -930,7 +930,7 @@ export const TableListComponent: React.FC<TableListComponentProps> = ({
|
|||
useEffect(() => {
|
||||
fetchColumnLabels();
|
||||
fetchTableLabel();
|
||||
}, [tableConfig.selectedTable]);
|
||||
}, [tableConfig.selectedTable, fetchColumnLabels, fetchTableLabel]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isDesignMode && tableConfig.selectedTable) {
|
||||
|
|
@ -945,6 +945,7 @@ export const TableListComponent: React.FC<TableListComponentProps> = ({
|
|||
searchTerm,
|
||||
refreshKey,
|
||||
isDesignMode,
|
||||
fetchTableDataDebounced,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
|||
|
|
@ -203,15 +203,29 @@ export class ButtonActionExecutor {
|
|||
// INSERT 처리
|
||||
|
||||
// 🆕 자동으로 작성자 정보 추가
|
||||
const writerValue = context.userId || context.userName || "unknown";
|
||||
if (!context.userId) {
|
||||
throw new Error("사용자 정보를 불러올 수 없습니다. 다시 로그인해주세요.");
|
||||
}
|
||||
|
||||
const writerValue = context.userId;
|
||||
const companyCodeValue = context.companyCode || "";
|
||||
|
||||
console.log("👤 [buttonActions] 사용자 정보:", {
|
||||
userId: context.userId,
|
||||
userName: context.userName,
|
||||
companyCode: context.companyCode, // ✅ 회사 코드
|
||||
formDataWriter: formData.writer, // ✅ 폼에서 입력한 writer 값
|
||||
formDataCompanyCode: formData.company_code, // ✅ 폼에서 입력한 company_code 값
|
||||
defaultWriterValue: writerValue,
|
||||
companyCodeValue, // ✅ 최종 회사 코드 값
|
||||
});
|
||||
|
||||
const dataWithUserInfo = {
|
||||
...formData,
|
||||
writer: writerValue,
|
||||
created_by: writerValue,
|
||||
updated_by: writerValue,
|
||||
company_code: companyCodeValue,
|
||||
writer: formData.writer || writerValue, // ✅ 입력값 우선, 없으면 userId
|
||||
created_by: writerValue, // created_by는 항상 로그인한 사람
|
||||
updated_by: writerValue, // updated_by는 항상 로그인한 사람
|
||||
company_code: formData.company_code || companyCodeValue, // ✅ 입력값 우선, 없으면 user.companyCode
|
||||
};
|
||||
|
||||
saveResult = await DynamicFormApi.saveFormData({
|
||||
|
|
|
|||
Loading…
Reference in New Issue