마에스트로 상세 화면의 처리 로그 표에 페이지네이션 추가
This commit is contained in:
+80
-28
@@ -75,7 +75,6 @@ export type MaestroDetail = {
|
||||
players: number;
|
||||
extensionRequests: number;
|
||||
upgradeRequests: number;
|
||||
logs: number;
|
||||
};
|
||||
players: Array<{
|
||||
playerID: number;
|
||||
@@ -97,12 +96,6 @@ export type MaestroDetail = {
|
||||
requestedDateTime: string;
|
||||
status: number;
|
||||
}>;
|
||||
logs: Array<{
|
||||
maestroLogID: number;
|
||||
type: string;
|
||||
logDateTime: string;
|
||||
remark: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
const activateStatusValues = [
|
||||
@@ -262,6 +255,86 @@ export async function updateMaestro(
|
||||
return { changed: true };
|
||||
}
|
||||
|
||||
const logPageSizeOptions = [10, 20, 50] as const;
|
||||
type LogPageSize = (typeof logPageSizeOptions)[number];
|
||||
|
||||
const logSearchSchema = z.object({
|
||||
page: z.coerce.number().int().min(1).catch(1),
|
||||
pageSize: z.coerce
|
||||
.number()
|
||||
.int()
|
||||
.refine((v) => logPageSizeOptions.includes(v as LogPageSize))
|
||||
.catch(10),
|
||||
});
|
||||
|
||||
export type MaestroLogsResult = {
|
||||
items: Array<{
|
||||
maestroLogID: number;
|
||||
type: string;
|
||||
logDateTime: string;
|
||||
remark: string;
|
||||
}>;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
totalCount: number;
|
||||
totalPages: number;
|
||||
};
|
||||
|
||||
export async function getMaestroLogs(
|
||||
maestroID: number,
|
||||
rawSearchParams: RawSearchParams = {}
|
||||
): Promise<MaestroLogsResult | null> {
|
||||
const t0 = Date.now();
|
||||
|
||||
const maestroExists = await db.maestro.findUnique({
|
||||
where: { MaestroID: maestroID },
|
||||
select: { MaestroID: true },
|
||||
});
|
||||
|
||||
if (!maestroExists) return null;
|
||||
|
||||
const params = logSearchSchema.parse(searchParamsToRecord(rawSearchParams));
|
||||
const skip = (params.page - 1) * params.pageSize;
|
||||
|
||||
const [totalCount, logs] = await Promise.all([
|
||||
db.maestro_log.count({ where: { MaestroID: maestroID } }),
|
||||
db.maestro_log.findMany({
|
||||
where: { MaestroID: maestroID },
|
||||
orderBy: { MaestroLogID: "desc" },
|
||||
skip,
|
||||
take: params.pageSize,
|
||||
select: {
|
||||
MaestroLogID: true,
|
||||
Type: true,
|
||||
LogDateTime: true,
|
||||
Remark: true,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
const totalPages = Math.max(1, Math.ceil(totalCount / params.pageSize));
|
||||
|
||||
logger.debug("maestros/[id]/logs", "fetched", {
|
||||
id: maestroID,
|
||||
page: params.page,
|
||||
totalCount,
|
||||
duration: Date.now() - t0,
|
||||
});
|
||||
|
||||
return {
|
||||
items: logs.map((log) => ({
|
||||
maestroLogID: log.MaestroLogID,
|
||||
type: log.Type.trim(),
|
||||
logDateTime: log.LogDateTime.toISOString(),
|
||||
remark: log.Remark.trim(),
|
||||
})),
|
||||
page: params.page,
|
||||
pageSize: params.pageSize,
|
||||
totalCount,
|
||||
totalPages,
|
||||
};
|
||||
}
|
||||
|
||||
const studentPageSizeOptions = [10, 20, 50] as const;
|
||||
type StudentPageSize = (typeof studentPageSizeOptions)[number];
|
||||
|
||||
@@ -430,16 +503,13 @@ export async function getMaestroDetail(
|
||||
playersCount,
|
||||
extensionRequestsCount,
|
||||
upgradeRequestsCount,
|
||||
logsCount,
|
||||
players,
|
||||
extensionRequests,
|
||||
upgradeRequests,
|
||||
logs,
|
||||
] = await Promise.all([
|
||||
db.player.count({ where: { MaestroID: maestroID } }),
|
||||
db.maestro_extension.count({ where: { MaestroID: maestroID } }),
|
||||
db.maestro_upgrade.count({ where: { MaestroID: maestroID } }),
|
||||
db.maestro_log.count({ where: { MaestroID: maestroID } }),
|
||||
db.player.findMany({
|
||||
where: { MaestroID: maestroID },
|
||||
orderBy: { PlayerID: "desc" },
|
||||
@@ -475,17 +545,6 @@ export async function getMaestroDetail(
|
||||
Status: true,
|
||||
},
|
||||
}),
|
||||
db.maestro_log.findMany({
|
||||
where: { MaestroID: maestroID },
|
||||
orderBy: { MaestroLogID: "desc" },
|
||||
take: 30,
|
||||
select: {
|
||||
MaestroLogID: true,
|
||||
Type: true,
|
||||
LogDateTime: true,
|
||||
Remark: true,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
logger.info("maestros/[id]", "fetched", {
|
||||
@@ -503,7 +562,6 @@ export async function getMaestroDetail(
|
||||
players: playersCount,
|
||||
extensionRequests: extensionRequestsCount,
|
||||
upgradeRequests: upgradeRequestsCount,
|
||||
logs: logsCount,
|
||||
},
|
||||
players: players.map((player) => ({
|
||||
playerID: player.PlayerID,
|
||||
@@ -525,12 +583,6 @@ export async function getMaestroDetail(
|
||||
requestedDateTime: request.RequestedDateTime.toISOString(),
|
||||
status: request.Status,
|
||||
})),
|
||||
logs: logs.map((log) => ({
|
||||
maestroLogID: log.MaestroLogID,
|
||||
type: log.Type.trim(),
|
||||
logDateTime: log.LogDateTime.toISOString(),
|
||||
remark: log.Remark.trim(),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user