diff --git a/apps/backend-e2e/src/maps.e2e-spec.ts b/apps/backend-e2e/src/maps.e2e-spec.ts index 158bec7a4..2ea2d36f7 100644 --- a/apps/backend-e2e/src/maps.e2e-spec.ts +++ b/apps/backend-e2e/src/maps.e2e-spec.ts @@ -2478,114 +2478,6 @@ describe('Maps', () => { it('should 401 when no access token is provided', () => req.unauthorizedTest('maps/1/info', 'get')); }); - - describe('PATCH', () => { - let user, token, map; - - beforeAll(async () => { - [user, token] = await db.createAndLoginUser({ - data: { roles: Role.MAPPER } - }); - map = await db.createMap({ - status: MapStatus.NEEDS_REVISION, - submitter: { connect: { id: user.id } } - }); - }); - - afterAll(() => db.cleanup('user', 'mMap')); - - const infoUpdate = { - description: 'This map is EXTREME', - youtubeID: '70vwJy1dQ0c', - creationDate: new Date('1999-02-06') - }; - - it('should allow the map submitter update the map info', async () => { - await req.patch({ - url: `maps/${map.id}/info`, - status: 204, - body: infoUpdate, - token: token - }); - - const updatedInfo = await prisma.mapInfo.findUnique({ - where: { mapID: map.id } - }); - - expect(updatedInfo).toMatchObject(infoUpdate); - }); - - it('should 400 if the date is invalid', () => - req.patch({ - url: `maps/${map.id}/info`, - status: 400, - body: { creationDate: 'its chewsday init' }, - token: token - })); - - it('should return 400 if the youtube ID is invalid', () => - req.patch({ - url: `maps/${map.id}/info`, - status: 400, - body: { youtubeID: 'https://www.myspace.com/watch?v=70vwJy1dQ0c' }, - token: token - })); - - it('should return 400 if no update data is provided', () => - req.patch({ url: `maps/${map.id}/info`, status: 400, token: token })); - - it('should return 404 if the map does not exist', () => - req.patch({ - url: `maps/${NULL_ID}/info`, - status: 404, - body: infoUpdate, - token: token - })); - - it('should return 403 if the map was not submitted by that user', async () => { - const [_, u2Token] = await db.createAndLoginUser({ - data: { roles: Role.MAPPER } - }); - - await req.patch({ - url: `maps/${map.id}/info`, - status: 403, - body: infoUpdate, - token: u2Token - }); - }); - - it('should return 403 if the map is not in NEEDS_REVISION state', async () => { - const map2 = await db.createMap({ - status: MapStatus.APPROVED, - submitter: { connect: { id: user.id } } - }); - - await req.patch({ - url: `maps/${map2.id}/info`, - status: 403, - body: infoUpdate, - token: token - }); - }); - - it('should return 403 if the user does not have the mapper role', async () => { - await prisma.user.update({ - where: { id: user.id }, - data: { roles: 0 } - }); - - await req.patch({ - url: `maps/${map.id}/info`, - status: 403, - body: infoUpdate, - token: token - }); - }); - - it('should 401 when no access token is provided', () => - req.unauthorizedTest('maps/1/info', 'patch')); - }); }); describe('maps/{mapID}/credits', () => { diff --git a/apps/backend/src/app/modules/maps/maps.controller.ts b/apps/backend/src/app/modules/maps/maps.controller.ts index 78079f002..4391e1b5b 100644 --- a/apps/backend/src/app/modules/maps/maps.controller.ts +++ b/apps/backend/src/app/modules/maps/maps.controller.ts @@ -417,33 +417,6 @@ export class MapsController { return this.mapsService.getInfo(mapID, userID); } - @Patch('/:mapID/info') - @Roles(Role.MAPPER, Role.MODERATOR, Role.ADMIN) - @HttpCode(HttpStatus.NO_CONTENT) - @ApiOperation({ summary: 'Update the map info' }) - @ApiBody({ - type: UpdateMapInfoDto, - description: 'Update map info data transfer object', - required: true - }) - @ApiNoContentResponse({ - description: 'The map info was successfully updated' - }) - @ApiBadRequestResponse({ description: 'Invalid update data' }) - @ApiForbiddenResponse({ description: 'Map is not in NEEDS_REVISION state' }) - @ApiForbiddenResponse({ description: 'User does not have the mapper role' }) - @ApiForbiddenResponse({ - description: 'User is not the submitter of this map' - }) - @ApiNotFoundResponse({ description: 'Map not found' }) - updateInfo( - @LoggedInUser('id') userID: number, - @Body() updateDto: UpdateMapInfoDto, - @Param('mapID', ParseIntSafePipe) mapID: number - ): Promise { - return this.mapsService.updateInfo(mapID, updateDto, userID); - } - //#endregion //#region Zones diff --git a/apps/backend/src/app/modules/maps/maps.service.ts b/apps/backend/src/app/modules/maps/maps.service.ts index 215ad755d..f3a463bb8 100644 --- a/apps/backend/src/app/modules/maps/maps.service.ts +++ b/apps/backend/src/app/modules/maps/maps.service.ts @@ -1,5 +1,4 @@ import { - BadRequestException, ForbiddenException, forwardRef, Inject, @@ -26,7 +25,6 @@ import { MapTrackDto, PagedResponseDto, UpdateMapDto, - UpdateMapInfoDto, MapsGetAllSubmissionAdminQueryDto } from '@momentum/backend/dto'; import { @@ -553,34 +551,6 @@ export class MapsService { return DtoFactory(MapInfoDto, map.info); } - async updateInfo( - mapID: number, - mapInfo: UpdateMapInfoDto, - userID: number - ): Promise { - if (!mapInfo.description && !mapInfo.youtubeID && !mapInfo.creationDate) - throw new BadRequestException('Request contains no valid update data'); - - const map = await this.db.mMap.findUnique({ where: { id: mapID } }); - - if (!map) throw new NotFoundException('Map not found'); - - if (map.submitterID !== userID) - throw new ForbiddenException('User is not the submitter of the map'); - - if (map.status !== MapStatus.NEEDS_REVISION) - throw new ForbiddenException('Map is not in NEEDS_REVISION state'); - - const data: Prisma.MapInfoUpdateInput = {}; - - if (mapInfo.description) data.description = mapInfo.description; - if (mapInfo.youtubeID) data.youtubeID = mapInfo.youtubeID; - if (mapInfo.creationDate) - data.creationDate = new Date(mapInfo.creationDate); - - await this.db.mapInfo.update({ where: { mapID }, data }); - } - //#endregion //#region Zones