From 31704805fb15b6ff63f6f51b7a88a7b2fa7f1ac8 Mon Sep 17 00:00:00 2001 From: Jef LeCompte Date: Thu, 12 Dec 2024 13:32:34 -0800 Subject: [PATCH] feat(back): check if map exists --- .../src/app/modules/maps/maps.service.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/apps/backend/src/app/modules/maps/maps.service.ts b/apps/backend/src/app/modules/maps/maps.service.ts index 141e98188..fabaf27c1 100644 --- a/apps/backend/src/app/modules/maps/maps.service.ts +++ b/apps/backend/src/app/modules/maps/maps.service.ts @@ -552,6 +552,15 @@ export class MapsService { const hasVmf = vmfFiles?.length > 0; const bspHash = FileStoreService.getHashForBuffer(bspFile.buffer); + // Check for duplicate map hash + const existingMap = await this.db.mMap.exists({ + where: { versions: { some: { bspHash } } } + }); + + if (existingMap) { + throw new ConflictException('Map with this file hash already exists'); + } + let map: Awaited>; const tasks: Promise[] = [ @@ -661,6 +670,15 @@ export class MapsService { const hasVmf = vmfFiles?.length > 0; const bspHash = FileStoreService.getHashForBuffer(bspFile.buffer); + // Check for duplicate map hash + const existingMap = await this.db.mMap.exists({ + where: { versions: { some: { bspHash } } } + }); + + if (existingMap) { + throw new ConflictException('Map with this file hash already exists'); + } + let zonesStr: string; let zones: MapZones; if (dto.zones) {