32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import type {ProductResponse, StatisticsRequest} from "@/types/lg";
|
|
|
|
const sortRecord = <T,>(obj?: Record<string, T> | null): Record<string, T> => {
|
|
if (!obj) return {};
|
|
return Object.fromEntries(
|
|
Object.keys(obj)
|
|
.sort()
|
|
.map((k) => [k, obj[k]])
|
|
);
|
|
};
|
|
|
|
const sortNumberArrayRecord = (obj?: Record<string, number[]> | null): Record<string, number[]> => {
|
|
if (!obj) return {};
|
|
return Object.fromEntries(
|
|
Object.keys(obj)
|
|
.sort()
|
|
.map((k) => [k, [...(obj[k] ?? [])].sort((a, b) => a - b)])
|
|
);
|
|
};
|
|
|
|
const normalizeReqForKey = (req: StatisticsRequest) => ({
|
|
variableIdMap: sortRecord(req.variableIdMap),
|
|
bannerIdList: [...(req.bannerIdList ?? [])].sort(),
|
|
filterCondition: sortNumberArrayRecord(req.filterCondition as any), // normalizeFilterCondition 결과면 Record<string, number[]>
|
|
option: req.option ?? null,
|
|
});
|
|
|
|
export const productStatisticsKey = (req: StatisticsRequest) =>
|
|
["statistics", "product", normalizeReqForKey(req)] as const;
|
|
|
|
export const bannerStatisticsKey = (req: StatisticsRequest) =>
|
|
["statistics", "banner", normalizeReqForKey(req)] as const; |