feat: admin knowledge base list with Prisma
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 17s
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 17s
This commit is contained in:
parent
644d62681e
commit
0e85231712
@ -15,6 +15,7 @@ import { AuthModule } from './modules/auth/auth.module';
|
||||
import { AdminAuthModule } from './modules/admin-auth/admin-auth.module';
|
||||
import { AdminDashboardModule } from './modules/admin-dashboard/admin-dashboard.module';
|
||||
import { AdminUsersModule } from './modules/admin-users/admin-users.module';
|
||||
import { AdminKnowledgeModule } from './modules/admin-knowledge/admin-knowledge.module';
|
||||
import { AdminCostsModule } from './modules/admin-costs/admin-costs.module';
|
||||
import { AdminBillingModule } from './modules/admin-billing/admin-billing.module';
|
||||
import { AdminServersModule } from './modules/admin-servers/admin-servers.module';
|
||||
@ -92,6 +93,7 @@ import appleConfig from './config/apple.config';
|
||||
AdminAuthModule,
|
||||
AdminDashboardModule,
|
||||
AdminUsersModule,
|
||||
AdminKnowledgeModule,
|
||||
AdminCostsModule,
|
||||
AdminBillingModule,
|
||||
AdminServersModule,
|
||||
|
||||
50
src/modules/admin-knowledge/admin-knowledge.controller.ts
Normal file
50
src/modules/admin-knowledge/admin-knowledge.controller.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { Controller, Get, Param, Delete, Query, UseGuards } from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||
import { PrismaService } from '../../infrastructure/database/prisma.service';
|
||||
import { AdminAuthGuard } from '../../common/guards/admin-auth.guard';
|
||||
import { AdminRolesGuard } from '../../common/guards/admin-roles.guard';
|
||||
|
||||
@ApiTags('admin-knowledge')
|
||||
@Controller('admin-api/knowledge-bases')
|
||||
@UseGuards(AdminAuthGuard, AdminRolesGuard)
|
||||
@ApiBearerAuth()
|
||||
export class AdminKnowledgeController {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: '知识库列表(管理员)' })
|
||||
async list(@Query('page') page = '1', @Query('limit') limit = '20') {
|
||||
const p = parseInt(page), l = parseInt(limit);
|
||||
const [items, total] = await Promise.all([
|
||||
this.prisma.knowledgeBase.findMany({
|
||||
where: { deletedAt: null },
|
||||
orderBy: { updatedAt: 'desc' },
|
||||
skip: (p - 1) * l, take: l,
|
||||
include: { user: { select: { nickname: true, email: true } } },
|
||||
}),
|
||||
this.prisma.knowledgeBase.count({ where: { deletedAt: null } }),
|
||||
]);
|
||||
return { items, total, page: p, limit: l, totalPages: Math.ceil(total / l) };
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: '知识库详情' })
|
||||
async detail(@Param('id') id: string) {
|
||||
const kb = await this.prisma.knowledgeBase.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
user: { select: { nickname: true, email: true } },
|
||||
sources: { where: { deletedAt: null }, take: 20 },
|
||||
_count: { select: { knowledgeItems: true } },
|
||||
},
|
||||
});
|
||||
return kb;
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: '删除知识库' })
|
||||
async remove(@Param('id') id: string) {
|
||||
await this.prisma.knowledgeBase.update({ where: { id }, data: { deletedAt: new Date() } });
|
||||
return { success: true };
|
||||
}
|
||||
}
|
||||
11
src/modules/admin-knowledge/admin-knowledge.module.ts
Normal file
11
src/modules/admin-knowledge/admin-knowledge.module.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AdminKnowledgeController } from './admin-knowledge.controller';
|
||||
import { PrismaService } from '../../infrastructure/database/prisma.service';
|
||||
import { AdminAuthGuard } from '../../common/guards/admin-auth.guard';
|
||||
import { AdminRolesGuard } from '../../common/guards/admin-roles.guard';
|
||||
|
||||
@Module({
|
||||
controllers: [AdminKnowledgeController],
|
||||
providers: [PrismaService, AdminAuthGuard, AdminRolesGuard],
|
||||
})
|
||||
export class AdminKnowledgeModule {}
|
||||
Loading…
x
Reference in New Issue
Block a user