Skip to content

Commit

Permalink
chore(back): remove /maps/{mapID}/info PATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
tsa96 committed Aug 31, 2023
1 parent 868fcf1 commit 3b1bbb2
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 165 deletions.
108 changes: 0 additions & 108 deletions apps/backend-e2e/src/maps.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
27 changes: 0 additions & 27 deletions apps/backend/src/app/modules/maps/maps.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
return this.mapsService.updateInfo(mapID, updateDto, userID);
}

//#endregion

//#region Zones
Expand Down
30 changes: 0 additions & 30 deletions apps/backend/src/app/modules/maps/maps.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
BadRequestException,
ForbiddenException,
forwardRef,
Inject,
Expand All @@ -26,7 +25,6 @@ import {
MapTrackDto,
PagedResponseDto,
UpdateMapDto,
UpdateMapInfoDto,
MapsGetAllSubmissionAdminQueryDto
} from '@momentum/backend/dto';
import {
Expand Down Expand Up @@ -553,34 +551,6 @@ export class MapsService {
return DtoFactory(MapInfoDto, map.info);
}

async updateInfo(
mapID: number,
mapInfo: UpdateMapInfoDto,
userID: number
): Promise<void> {
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
Expand Down

0 comments on commit 3b1bbb2

Please sign in to comment.