61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
|
|
import { Controller, Get, Put, Post, Delete, Param, Body, Req } from '@nestjs/common';
|
||
|
|
import { UserAiService } from './user-ai.service';
|
||
|
|
import { SaveLearningProfileDto, UpdateAiSettingsDto, CreateCredentialDto, UpdateCredentialDto } from './user-ai.dto';
|
||
|
|
|
||
|
|
@Controller('ai')
|
||
|
|
export class UserAiController {
|
||
|
|
constructor(private readonly service: UserAiService) {}
|
||
|
|
|
||
|
|
// ── Profile ──
|
||
|
|
|
||
|
|
@Get('profile')
|
||
|
|
async getProfile(@Req() req: any) {
|
||
|
|
return this.service.getProfile(req.user.id) ?? {};
|
||
|
|
}
|
||
|
|
|
||
|
|
@Put('profile')
|
||
|
|
async saveProfile(@Req() req: any, @Body() dto: SaveLearningProfileDto) {
|
||
|
|
return this.service.saveProfile(req.user.id, dto);
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Settings ──
|
||
|
|
|
||
|
|
@Get('settings')
|
||
|
|
async getSettings(@Req() req: any) {
|
||
|
|
return this.service.getSettings(req.user.id);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Put('settings')
|
||
|
|
async updateSettings(@Req() req: any, @Body() dto: UpdateAiSettingsDto) {
|
||
|
|
return this.service.updateSettings(req.user.id, dto);
|
||
|
|
}
|
||
|
|
|
||
|
|
// ── Model Credentials ──
|
||
|
|
|
||
|
|
@Get('model-credentials')
|
||
|
|
async listCredentials(@Req() req: any) {
|
||
|
|
return this.service.listCredentials(req.user.id);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Post('model-credentials')
|
||
|
|
async createCredential(@Req() req: any, @Body() dto: CreateCredentialDto) {
|
||
|
|
return this.service.createCredential(req.user.id, dto);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Put('model-credentials/:id')
|
||
|
|
async updateCredential(@Req() req: any, @Param('id') id: string, @Body() dto: UpdateCredentialDto) {
|
||
|
|
return this.service.updateCredential(req.user.id, id, dto);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Delete('model-credentials/:id')
|
||
|
|
async deleteCredential(@Req() req: any, @Param('id') id: string) {
|
||
|
|
await this.service.deleteCredential(req.user.id, id);
|
||
|
|
return { ok: true };
|
||
|
|
}
|
||
|
|
|
||
|
|
@Post('model-credentials/:id/test')
|
||
|
|
async testCredential(@Req() req: any, @Param('id') id: string) {
|
||
|
|
return this.service.testCredential(req.user.id, id);
|
||
|
|
}
|
||
|
|
}
|