Skip to content

Commit 4f19a02

Browse files
committed
fix: handle user validation as nullable in song service methods
1 parent 34228b8 commit 4f19a02

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

server/src/song/song.controller.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export class SongController {
8080
@Param('id') id: string,
8181
@GetRequestToken() user: UserDocument | null,
8282
): Promise<SongViewDto> {
83-
user = validateUser(user);
8483
return await this.songService.getSong(id, user);
8584
}
8685

@@ -130,7 +129,6 @@ export class SongController {
130129
'Access-Control-Expose-Headers': 'Content-Disposition',
131130
});
132131

133-
user = validateUser(user);
134132
const url = await this.songService.getSongDownloadUrl(id, user, src, false);
135133
res.redirect(HttpStatus.FOUND, url);
136134
}
@@ -142,8 +140,6 @@ export class SongController {
142140
@GetRequestToken() user: UserDocument | null,
143141
@Headers('src') src: string,
144142
): Promise<string> {
145-
user = validateUser(user);
146-
147143
if (src != 'downloadButton') {
148144
throw new UnauthorizedException('Invalid source');
149145
}

server/src/song/song.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export class SongService {
241241

242242
public async getSong(
243243
publicId: string,
244-
user: UserDocument,
244+
user: UserDocument | null,
245245
): Promise<SongViewDto> {
246246
const foundSong = await this.songModel
247247
.findOne({ publicId: publicId })
@@ -272,7 +272,7 @@ export class SongService {
272272
// TODO: service should not handle HTTP -> https://www.reddit.com/r/node/comments/uoicw1/should_i_return_status_code_from_service_layer/
273273
public async getSongDownloadUrl(
274274
publicId: string,
275-
user: UserDocument,
275+
user: UserDocument | null,
276276
src?: string,
277277
packed: boolean = false,
278278
): Promise<string> {

0 commit comments

Comments
 (0)