refac: sammoAPI 정의 방식 일부 변경

- defs/index.ts로 분리
- API/Nation/GeneralList 호출 재정의
This commit is contained in:
2022-04-07 03:03:38 +09:00
parent 3b4cbf68ca
commit 988ba015b8
3 changed files with 123 additions and 29 deletions
+20
View File
@@ -0,0 +1,20 @@
import type { ValuesOf } from "@/defs";
import { zip } from "lodash";
export function merge2DArrToObjectArr<T extends Record<string, unknown>>(column: (keyof T)[], list: ValuesOf<T>[][]): T[]{
const result: T[] = [];
for(const rawItem of list){
const item: Record<string, unknown> = {};
if(column.length != item.length){
throw `column과 item의 길이가 같지 않습니다: ${column.length} != ${list.length}, ${JSON.stringify(item)}`;
}
for(const [key, value] of zip(column, rawItem)){
item[key as string] = value;
}
result.push(item as T);
}
return result;
}