docs: 지붕재적합성 hooks description 추가

This commit is contained in:
Daseul Kim 2025-06-10 11:34:02 +09:00
parent 32329b1cb7
commit e3e6f10893

View File

@ -20,6 +20,16 @@ export function useSuitable() {
clearSelectedItems,
} = useSuitableStore()
/**
* @description . API를
*
* @param {Object} param
* @param {number} [param.pageNumber] (기본값: 1)
* @param {string} [param.category]
* @param {string} [param.keyword]
*
* @returns {Promise<Suitable[]>}
*/
const getSuitables = async ({
pageNumber,
category,
@ -40,11 +50,16 @@ export function useSuitable() {
const response = await axiosInstance(null).get<Suitable[]>('/api/suitable/list', { params })
return response.data
} catch (error) {
console.error('지붕재 데이터 로드 실패:', error)
console.error(`지붕재 적합성 데이터 조회 실패: ${error}`)
return []
}
}
/**
* @description . API를 main_id, detail_id를
*
* @returns {Promise<SuitableIds[]>}
*/
const getSuitableIds = async (): Promise<SuitableIds[]> => {
try {
const params: Record<string, string> = {}
@ -53,11 +68,19 @@ export function useSuitable() {
const response = await axiosInstance(null).get<SuitableIds[]>('/api/suitable/pick', { params })
return response.data
} catch (error) {
console.error('지붕재 아이디 로드 실패:', error)
console.error(`지붕재 적합성 데이터 아이디 조회 실패: ${error}`)
return []
}
}
/**
* @description . API를
*
* @param {string} ids main_id ( )
* @param {string} [detailIds] detail_id ( )
*
* @returns {Promise<Suitable[]>}
*/
const getSuitableDetails = async (ids: string, detailIds?: string): Promise<Suitable[]> => {
try {
const params: Record<string, string> = { ids: ids }
@ -65,12 +88,17 @@ export function useSuitable() {
const response = await axiosInstance(null).post<Suitable[]>('/api/suitable', params)
return response.data
} catch (error) {
console.error('지붕재 상세 데이터 로드 실패:', error)
console.error(`지붕재 적합성 상세 데이터 조회 실패: ${error}`)
return []
}
}
const getSuitableCommCode = () => {
/**
* @description . API를
*
* @returns {void}
*/
const getSuitableCommCode = (): void => {
const headCodes = Object.values(SUITABLE_HEAD_CODE) as SUITABLE_HEAD_CODE[]
for (const code of headCodes) {
getCommCode(code).then((res) => {
@ -79,11 +107,26 @@ export function useSuitable() {
}
}
/**
* @description JP
*
* @param {string} headCode head_code
* @param {string} code code
*
* @returns {string} JP
*/
const toCodeName = (headCode: string, code: string): string => {
const commCode = suitableCommCode.get(headCode)
return commCode?.find((item) => item.code === code)?.codeJp || ''
}
/**
* @description detail string
*
* @param {string} suitableDetailString detail string
*
* @returns {SuitableDetail[]} detail
*/
const toSuitableDetail = (suitableDetailString: string): SuitableDetail[] => {
if (!suitableDetailString) return []
try {
@ -93,20 +136,32 @@ export function useSuitable() {
}
return suitableDetailArray
} catch (error) {
console.error('지붕재 데이터 파싱 실패:', error)
console.error(`지붕재 적합성 detail 데이터 파싱 실패: ${error}`)
return []
}
}
/**
* @description . detail id Set
*
* @param {string} suitableDetailString detail
*
* @returns {Set<number>} detail id
*/
const toSuitableDetailIds = (suitableDetailString: string): Set<number> => {
try {
return new Set<number>(JSON.parse(suitableDetailString).map(({ id }: { id: number }) => id))
} catch (error) {
console.error('지붕재 데이터 파싱 실패:', error)
console.error(`지붕재 적합성 detail 데이터 파싱 실패: ${error}`)
return new Set()
}
}
/**
* @description
*
* @returns {Object}
*/
const {
data: suitables,
fetchNextPage,
@ -135,12 +190,29 @@ export function useSuitable() {
enabled: searchCategory !== '' || searchKeyword !== '',
})
/**
* @description . , ,
*
* @param {Object} param
* @param {boolean} [param.items]
* @param {boolean} [param.category]
* @param {boolean} [param.keyword]
*
* @returns {void}
*/
const clearSuitableStore = ({ items = false, category = false, keyword = false }: { items?: boolean; category?: boolean; keyword?: boolean }) => {
if (items) clearSelectedItems()
if (category) clearSearchCategory()
if (keyword) clearSearchKeyword()
}
/**
* @description
*
* @param {string} value
*
* @returns {string}
*/
// TODO: 추후 지붕재 적합성 데이터 CUD 구현 시 ×, -, ー 데이터 관리 필요
const suitableCheckIcon = (value: string): string => {
const iconMap: Record<string, string> = {
@ -152,6 +224,13 @@ export function useSuitable() {
return iconMap[value] || iconMap.default
}
/**
* @description
*
* @param {string} value
*
* @returns {string}
*/
// TODO: 추후 지붕재 적합성 데이터 CUD 구현 시 ○, ×, -, ー 데이터 관리 필요
const suitableCheckMemo = (value: string): string => {
if (value === '○') return '設置可'
@ -160,6 +239,13 @@ export function useSuitable() {
return `${value}で設置可`
}
/**
* @description main_id, detail_id를 .
*
* @returns {Object} main_id, detail_id
* @returns {string} main_id ( )
* @returns {string} detail_id ( )
*/
const serializeSelectedItems = (): { ids: string; detailIds: string } => {
const ids: string[] = []
const detailIds: string[] = []
@ -170,11 +256,21 @@ export function useSuitable() {
return { ids: ids.join(','), detailIds: detailIds.length > 0 ? detailIds.join(',') : '' }
}
/**
* @description . API를
*
* @returns {Promise<Suitable[]>}
*/
const getSelectedSuitables = async (): Promise<Suitable[]> => {
const { ids, detailIds } = serializeSelectedItems()
return await getSuitableDetails(ids, detailIds)
}
/**
* @description pdf . form API를 pdf
*
* @returns {Promise<void>} pdf
*/
const downloadSuitablePdf = async (): Promise<void> => {
try {
const { ids, detailIds } = serializeSelectedItems()
@ -210,7 +306,7 @@ export function useSuitable() {
form.submit()
document.body.removeChild(form)
} catch (error) {
console.error('지붕재 상세 데이터 pdf 다운로드 실패:', error)
console.error(`지붕재 적합성 상세 데이터 pdf 다운로드 실패: ${error}`)
}
}