final fix

This commit is contained in:
2025-08-27 21:03:45 +03:00
parent 400d97f1ff
commit beb033bb6f
4 changed files with 71 additions and 5 deletions

View File

@@ -4,8 +4,9 @@ import { ApiTags } from '@nestjs/swagger';
import { PrismaService } from './services/prisma.service';
import { FileInterceptor } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { extname } from 'path';
import { extname, join } from 'path';
import { AppGetaway } from './app.getaway';
import { unlink } from 'fs';
@ApiTags('App')
@Controller('app')
@@ -14,8 +15,8 @@ export class AppController {
@Get('candidates')
getCandidateList() {
return this.prisma.candidate.findMany({
async getCandidateList() {
const data = await this.prisma.candidate.findMany({
select: {
id: true,
fullName: true,
@@ -24,11 +25,21 @@ export class AppController {
profileImage: true,
}
})
data.forEach((candidate) => {
candidate.profileImage = `${process.env.HOST_URL as string}/uploads/${candidate.profileImage}`;
})
return data;
}
@Get('candidate/:id')
getCandidateDetails(@Param('id', ParseIntPipe) id: number) {
return this.prisma.candidate.findFirst({ where: { id: id } });
async getCandidateDetails(@Param('id', ParseIntPipe) id: number) {
const data = await this.prisma.candidate.findFirst({ where: { id: id } });
if (!data) {
throw new NotFoundException();
}
data.profileImage = `${process.env.HOST_URL as string}/uploads/${data.profileImage}`;
return data;
}
@@ -105,6 +116,15 @@ export class AppController {
await this.prisma.candidate.delete({ where: { id } });
if (candidate.profileImage) {
const filePath = join(process.cwd(), 'assets', 'uploads', candidate.profileImage);
unlink(filePath, (err) => {
if (err) {
console.error('Failed to delete file:', err);
}
});
}
this.socketService.onDeleteCandidate(id);
return candidate;

View File

@@ -6,9 +6,11 @@ import { PrismaService } from './services/prisma.service';
import { AppGetaway } from './app.getaway';
import { StatsController } from './stats.controller';
import { StatsService } from './services/stats.service';
import { ConfigModule } from '@nestjs/config';
@Module({
imports: [
ConfigModule.forRoot(),
ServeStaticModule.forRoot(
{
rootPath: join(__dirname, 'assets/client'),