cptadmin / packages /backend /src /modules /dashboard /dashboard.controller.ts
BG5's picture
Upload 253 files
db242f8
import { Controller, Delete, Get, Post, Put, Query } from '@nestjs/common';
import { ConfigService } from '@/common/config/config.service';
import { Public, Role, Roles } from '@/common/guards/auth.guard';
import { JoiValidationPipe } from '@/common/pipes/joi';
import { PagerQuery, PagerQuerySchema } from '@/shared';
import { DashboardService } from './dashboard.service';
@Roles(Role.Admin)
@Controller('dashboard')
export class DashboardController {
constructor(
private readonly dashboardService: DashboardService,
private readonly configService: ConfigService,
) {}
@Get('analytics')
async getAnalytics() {
return {
success: true,
data: await this.dashboardService.getAnalytics(),
};
}
@Get('openai/keys')
async listOpenaiKeys() {
return this.dashboardService.listOpenaiKeys();
}
@Post('openai/keys')
async addOpenaiKey() {}
@Delete('openai/keys/:id')
async deleteOpenaiKey() {}
/* ๆŸฅ็œ‹็”จๆˆทๆ‰€ๆœ‰ๅฏน่ฏ */
@Get('chat/sessions')
async getAllChatSessions(
@Query(new JoiValidationPipe(PagerQuerySchema))
paginator: PagerQuery,
) {
const [data, meta] =
await this.dashboardService.getAllChatSession(paginator);
return {
success: true,
data,
meta,
};
}
/* ๆŸฅ็œ‹็”จๆˆทๆ‰€ๆœ‰ๆถˆๆฏ */
@Get('chat/messages')
async getAllMessages(
@Query(new JoiValidationPipe(PagerQuerySchema))
paginator: PagerQuery,
) {
const [data, meta] = await this.dashboardService.getAllMessages(paginator);
return {
success: true,
data,
meta,
};
}
/* ๆŸฅ็œ‹ๆ‰€ๆœ‰่ฎขๅ• */
@Get('orders')
async getAllOrders(
@Query(new JoiValidationPipe(PagerQuerySchema))
paginator: PagerQuery,
) {
const [data, meta] = await this.dashboardService.getAllOrders(paginator);
return {
success: true,
data,
meta,
};
}
/* ๆŸฅ็œ‹ๆ‰€ๆœ‰็”จๆˆท */
@Get('users')
async getAllUsers(
@Query(new JoiValidationPipe(PagerQuerySchema))
paginator: PagerQuery,
) {
const [data, meta] = await this.dashboardService.getAllUsers(paginator);
return {
success: true,
data,
meta,
};
}
@Public()
@Get('install')
install() {
return {
success: true,
data: {
schema: this.configService.getConfigSchema(true),
value: this.configService.getDefaultValue(),
},
};
}
@Get('config')
getAllConfig() {
return {
success: true,
data: {
schema: this.configService.getConfigSchema(),
value: this.configService.getAll(),
},
};
}
@Put('config')
updateConfig() {
// this.configService.updateConfig({ '1': '2' });
return {};
}
}