import { Injectable } from '@nestjs/common'; import { PrismaService } from '../prisma/prisma.service'; @Injectable() export class NoticesService { constructor(private readonly prisma: PrismaService) {} async getLoginNotice() { const now = new Date(); const notice = await this.prisma.launcherNotice.findFirst({ where: { appKey: 'Launcher', isActive: true, OR: [ { startsAt: null, endsAt: null }, { startsAt: { lte: now }, endsAt: null }, { startsAt: null, endsAt: { gte: now } }, { startsAt: { lte: now }, endsAt: { gte: now } }, ], }, orderBy: [{ priority: 'desc' }, { createdAt: 'desc' }], select: { id: true, title: true, body: true, linkUrl: true, }, }); return { notice }; } async getAppNotices(appKey: string) { const now = new Date(); const notices = await this.prisma.launcherNotice.findMany({ where: { appKey, isActive: true, OR: [ { startsAt: null, endsAt: null }, { startsAt: { lte: now }, endsAt: null }, { startsAt: null, endsAt: { gte: now } }, { startsAt: { lte: now }, endsAt: { gte: now } }, ], }, orderBy: [{ priority: 'desc' }, { createdAt: 'desc' }], select: { id: true, title: true, body: true, linkUrl: true, createdAt: true, }, }); return { notices: notices.map((notice) => ({ ...notice, date: formatNoticeDate(notice.createdAt), })), }; } } function formatNoticeDate(date: Date): string { const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); return `${year}.${month}.${day}`; }