Skip to content
Snippets Groups Projects
Commit 193efb2f authored by Lee WooChang's avatar Lee WooChang
Browse files

feat: part 서비스 로직 추가

parent aec0f1c1
Branches
No related tags found
1 merge request!10Parts 추가
export const columnMapping = {
cpu: {
family_type: 'CPU 종류',
socket_type: '소켓 구분',
core_count: '코어 수',
thread_count: '스레드 수',
base_clock: '기본 클럭',
max_clock: '최대 클럭',
mem_type: '메모리 규격',
tdp: 'TDP',
},
gpu: {
chipset_manufacturer: '칩셋 제조사',
family_type: '제품 시리즈',
chipset: '칩셋',
vram_type: '메모리 종류',
vram_size: '메모리 용량',
interface: '인터페이스',
max_monitor_count: '모니터 지원',
power_consumption: '사용 전력',
},
ram: {
usage_type: '사용 장치',
form_factor: '메모리 규격',
size: '메모리 용량',
generation: '제품 분류',
base_clock: '동작 클럭(대역폭)',
package_count: '램 개수',
},
mb: {
board_type: '제품 분류',
cpu_socket: 'CPU 소켓',
cpu_chipset: '세부 칩셋',
power_phase: '전원부',
ram_type: '메모리 종류',
ram_speed: '메모리 속도',
ram_slot_count: '메모리 슬롯 수',
form_factor: '폼팩터',
},
ssd: {
interface: '인터페이스',
size: '용량',
form_factor: '폼팩터',
nand_type: '메모리 타입',
dram_type_size: 'DRAM (유형과 용량)',
protocol: '프로토콜',
},
hdd: {
usage_type: '제품 분류',
disk_standard_size: '디스크 크기',
disk_size: '디스크 용량',
interface: '인터페이스',
buffer_size: '버퍼 용량',
rpm: '회전 수',
max_speed: '전송 속도',
access_method: '기록방식',
},
};
import { columnMapping } from '../constants/columnMapping.js';
import { ReportableError } from '../errors.js';
import PartRepository from '../repositories/partRepository.js';
......@@ -24,6 +25,55 @@ const PartService = {
return this.cleanEntity(part);
},
async getFilters() {
const types = Object.keys(columnMapping);
const filters = {};
for (const type of types) {
const columns = await PartRepository.getColumnsByType(type);
filters[type.toUpperCase()] = {};
for (const column of columns) {
const koreanName = columnMapping[type]?.[column];
if (koreanName) {
const filterValues =
await PartRepository.getFilterDataByTypeAndColumn(type, column);
filters[type.toUpperCase()][koreanName] = {
column,
values: filterValues,
};
}
}
}
return filters;
},
async getParts(partType, filters) {
if (!partType) {
throw new Error('파트 타입이 필요합니다.');
}
let parsedFilters;
try {
parsedFilters = filters ? JSON.parse(filters) : {};
} catch {
throw new ReportableError(400, '잘못된 JSON 형태입니다.');
}
const whereClauses = Object.entries(parsedFilters)
.map(([key], index) => `${key} = $${index + 1}`)
.join(' AND ');
const queryValues = Object.values(parsedFilters);
const parts = await PartRepository.getPartsByFilters(
partType,
whereClauses,
queryValues
);
return parts;
},
};
export default PartService;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment