This commit is contained in:
2025-08-26 16:28:05 +03:00
parent 7fd2a6e55f
commit d4c3f51348
21 changed files with 93 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 445 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

View File

@@ -0,0 +1,8 @@
-- CreateTable
CREATE TABLE "public"."Stats" (
"id" INTEGER NOT NULL DEFAULT 1,
"totalVisits" INTEGER NOT NULL DEFAULT 0,
"totalClicks" INTEGER NOT NULL DEFAULT 0,
CONSTRAINT "Stats_pkey" PRIMARY KEY ("id")
);

View File

@@ -26,3 +26,9 @@ model Candidate {
profileImage String?
createdAt DateTime @default(now())
}
model Stats {
id Int @id @default(1)
totalVisits Int @default(0)
totalClicks Int @default(0)
}

View File

@@ -1,4 +1,4 @@
import { BadRequestException, Body, Controller, Get, NotFoundException, Param, ParseIntPipe, Post, Put, UploadedFile, UseInterceptors } from '@nestjs/common';
import { BadRequestException, Body, Controller, Delete, Get, NotFoundException, Param, ParseIntPipe, Post, Put, UploadedFile, UseInterceptors } from '@nestjs/common';
import { RegisterDto } from './dto/register.dto';
import { ApiTags } from '@nestjs/swagger';
import { PrismaService } from './services/prisma.service';
@@ -31,6 +31,7 @@ export class AppController {
return this.prisma.candidate.findFirst({ where: { id: id } });
}
@Post('register')
@UseInterceptors(FileInterceptor('profileImage', {
storage: diskStorage({
@@ -95,4 +96,17 @@ export class AppController {
return;
}
@Delete('candidate/:id')
async deleteCandidate(@Param('id', ParseIntPipe) id: number) {
const candidate = await this.prisma.candidate.findFirst({ where: { id } });
if (!candidate) throw new NotFoundException(`Candidate with id ${id} not found`);
await this.prisma.candidate.delete({ where: { id } });
this.socketService.onDeleteCandidate(id);
return candidate;
}
}

View File

@@ -23,4 +23,8 @@ export class AppGetaway implements OnGatewayDisconnect, OnGatewayConnection {
onUpdateCandidate(updatedData: any) {
this.server.emit('candidateUpdated', updatedData);
}
onDeleteCandidate(deletedId: number) {
this.server.emit('candidateDeleted', deletedId);
}
}

View File

@@ -4,6 +4,8 @@ import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
import { PrismaService } from './services/prisma.service';
import { AppGetaway } from './app.getaway';
import { StatsController } from './stats.controller';
import { StatsService } from './services/stats.service';
@Module({
imports: [
@@ -17,7 +19,7 @@ import { AppGetaway } from './app.getaway';
serveRoot: '/uploads',
}),
],
controllers: [AppController],
providers: [PrismaService, AppGetaway],
controllers: [AppController, StatsController],
providers: [PrismaService, StatsService, AppGetaway],
})
export class AppModule { }

View File

@@ -0,0 +1,34 @@
import { Injectable } from "@nestjs/common";
import { PrismaService } from "./prisma.service";
import { AppGetaway } from "src/app.getaway";
@Injectable()
export class StatsService {
constructor(
private prisma: PrismaService,
private socketService: AppGetaway
) { }
async incrementVisits() {
const stats = await this.prisma.stats.update({
where: { id: 1 },
data: { totalVisits: { increment: 1 } },
});
this.socketService.server.emit('statsUpdated', stats);
return stats;
}
async incrementClicks() {
const stats = await this.prisma.stats.update({
where: { id: 1 },
data: { totalClicks: { increment: 1 } },
});
this.socketService.server.emit('statsUpdated', stats);
return stats;
}
async getStats() {
return this.prisma.stats.findUnique({ where: { id: 1 } });
}
}

22
src/stats.controller.ts Normal file
View File

@@ -0,0 +1,22 @@
import { Controller, Get, Post } from '@nestjs/common';
import { StatsService } from './services/stats.service';
@Controller('stats')
export class StatsController {
constructor(private readonly statsService: StatsService) { }
@Get()
getStats() {
return this.statsService.getStats();
}
@Post('visit')
incrementVisit() {
return this.statsService.incrementVisits();
}
@Post('click')
incrementClick() {
return this.statsService.incrementClicks();
}
}