- Introduced `dbSchema` configuration option in GatewayApiConfig and GatewayOrchestratorConfig. - Implemented schema resolution logic in environment configuration functions. - Updated context and orchestrator factory to use GatewayPrismaClient instead of PrismaClient. - Refactored orchestrator server and profile repository to accommodate new database schema handling. - Created separate Prisma schemas for game and gateway in the infra package. - Enhanced Postgres connector to support schema overrides in database URLs. - Updated documentation to reflect changes in database schema handling. - Added new Prisma generation and database push scripts for game and gateway schemas.
117 lines
2.8 KiB
TypeScript
117 lines
2.8 KiB
TypeScript
import { LogCategory, LogScope, type GamePrisma, type GamePrismaClient } from './gamePrisma.js';
|
|
|
|
export interface LogQueryOptions {
|
|
limit?: number;
|
|
beforeId?: number;
|
|
}
|
|
|
|
export interface LogEntryView {
|
|
id: number;
|
|
scope: LogScope;
|
|
category: LogCategory;
|
|
subType: string | null;
|
|
text: string;
|
|
year: number;
|
|
month: number;
|
|
createdAt: Date;
|
|
generalId: number | null;
|
|
nationId: number | null;
|
|
userId: number | null;
|
|
}
|
|
|
|
const buildPaginationWhere = (
|
|
base: GamePrisma.LogEntryWhereInput,
|
|
options: LogQueryOptions
|
|
): GamePrisma.LogEntryWhereInput => {
|
|
if (options.beforeId) {
|
|
return {
|
|
...base,
|
|
id: { lt: options.beforeId },
|
|
};
|
|
}
|
|
return base;
|
|
};
|
|
|
|
const buildFindArgs = (
|
|
where: GamePrisma.LogEntryWhereInput,
|
|
options: LogQueryOptions
|
|
): GamePrisma.LogEntryFindManyArgs => ({
|
|
where: buildPaginationWhere(where, options),
|
|
orderBy: { id: 'desc' },
|
|
take: options.limit ?? 50,
|
|
});
|
|
|
|
export class LogRepository {
|
|
constructor(private readonly prisma: GamePrismaClient) {}
|
|
|
|
// 전역(시스템) 로그 조회
|
|
async listSystemLogs(
|
|
category: LogCategory,
|
|
options: LogQueryOptions = {}
|
|
): Promise<LogEntryView[]> {
|
|
return this.prisma.logEntry.findMany(
|
|
buildFindArgs(
|
|
{
|
|
scope: LogScope.SYSTEM,
|
|
category,
|
|
},
|
|
options
|
|
)
|
|
);
|
|
}
|
|
|
|
// 국가 로그 조회
|
|
async listNationLogs(
|
|
nationId: number,
|
|
category: LogCategory,
|
|
options: LogQueryOptions = {}
|
|
): Promise<LogEntryView[]> {
|
|
return this.prisma.logEntry.findMany(
|
|
buildFindArgs(
|
|
{
|
|
scope: LogScope.NATION,
|
|
category,
|
|
nationId,
|
|
},
|
|
options
|
|
)
|
|
);
|
|
}
|
|
|
|
// 장수 로그 조회
|
|
async listGeneralLogs(
|
|
generalId: number,
|
|
category: LogCategory,
|
|
options: LogQueryOptions = {}
|
|
): Promise<LogEntryView[]> {
|
|
return this.prisma.logEntry.findMany(
|
|
buildFindArgs(
|
|
{
|
|
scope: LogScope.GENERAL,
|
|
category,
|
|
generalId,
|
|
},
|
|
options
|
|
)
|
|
);
|
|
}
|
|
|
|
// 유저 로그 조회
|
|
async listUserLogs(
|
|
userId: number,
|
|
options: LogQueryOptions & { subType?: string } = {}
|
|
): Promise<LogEntryView[]> {
|
|
return this.prisma.logEntry.findMany(
|
|
buildFindArgs(
|
|
{
|
|
scope: LogScope.USER,
|
|
category: LogCategory.USER,
|
|
userId,
|
|
subType: options.subType,
|
|
},
|
|
options
|
|
)
|
|
);
|
|
}
|
|
}
|