final fix
This commit is contained in:
43
package-lock.json
generated
43
package-lock.json
generated
@@ -10,6 +10,7 @@
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^11.0.1",
|
||||
"@nestjs/config": "^4.0.2",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/platform-express": "^11.1.6",
|
||||
"@nestjs/platform-socket.io": "^11.1.6",
|
||||
@@ -2347,6 +2348,33 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/config": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/config/-/config-4.0.2.tgz",
|
||||
"integrity": "sha512-McMW6EXtpc8+CwTUwFdg6h7dYcBUpH5iUILCclAsa+MbCEvC9ZKu4dCHRlJqALuhjLw97pbQu62l4+wRwGeZqA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dotenv": "16.4.7",
|
||||
"dotenv-expand": "12.0.1",
|
||||
"lodash": "4.17.21"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
||||
"rxjs": "^7.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/config/node_modules/dotenv": {
|
||||
"version": "16.4.7",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz",
|
||||
"integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==",
|
||||
"license": "BSD-2-Clause",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://dotenvx.com"
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/core": {
|
||||
"version": "11.1.6",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/core/-/core-11.1.6.tgz",
|
||||
@@ -5164,6 +5192,21 @@
|
||||
"url": "https://dotenvx.com"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv-expand": {
|
||||
"version": "12.0.1",
|
||||
"resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-12.0.1.tgz",
|
||||
"integrity": "sha512-LaKRbou8gt0RNID/9RoI+J2rvXsBRPMV7p+ElHlPhcSARbCPDYcYG2s1TIzAfWv4YSgyY5taidWzzs31lNV3yQ==",
|
||||
"license": "BSD-2-Clause",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.4.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://dotenvx.com"
|
||||
}
|
||||
},
|
||||
"node_modules/dunder-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^11.0.1",
|
||||
"@nestjs/config": "^4.0.2",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/platform-express": "^11.1.6",
|
||||
"@nestjs/platform-socket.io": "^11.1.6",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user