init studio launcher backend
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { NoticesService } from './notices.service';
|
||||
|
||||
@Controller('api/notices')
|
||||
export class NoticesController {
|
||||
constructor(private readonly noticesService: NoticesService) {}
|
||||
|
||||
@Get('login')
|
||||
getLoginNotice() {
|
||||
return this.noticesService.getLoginNotice();
|
||||
}
|
||||
|
||||
@Get('apps/:appKey')
|
||||
getAppNotices(@Param('appKey') appKey: string) {
|
||||
return this.noticesService.getAppNotices(appKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PrismaModule } from '../prisma/prisma.module';
|
||||
import { NoticesController } from './notices.controller';
|
||||
import { NoticesService } from './notices.service';
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [NoticesController],
|
||||
providers: [NoticesService],
|
||||
})
|
||||
export class NoticesModule {}
|
||||
@@ -0,0 +1,73 @@
|
||||
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}`;
|
||||
}
|
||||
Reference in New Issue
Block a user