@@ -33,15 +33,7 @@ export class SongService {
33
33
} ) ;
34
34
}
35
35
36
- public async uploadSong ( {
37
- file,
38
- user,
39
- body,
40
- } : {
41
- body : UploadSongDto ;
42
- file : Express . Multer . File ;
43
- user : UserDocument ;
44
- } ) : Promise < UploadSongResponseDto > {
36
+ public async uploadSong ( { file, user, body, } : { body : UploadSongDto ; file : Express . Multer . File ; user : UserDocument ; } ) : Promise < UploadSongResponseDto > {
45
37
const song = await this . songUploadService . processUploadedSong ( {
46
38
file,
47
39
user,
@@ -69,10 +61,7 @@ export class SongService {
69
61
return UploadSongResponseDto . fromSongWithUserDocument ( populatedSong ) ;
70
62
}
71
63
72
- public async deleteSong (
73
- publicId : string ,
74
- user : UserDocument ,
75
- ) : Promise < UploadSongResponseDto > {
64
+ public async deleteSong ( publicId : string , user : UserDocument , ) : Promise < UploadSongResponseDto > {
76
65
const foundSong = await this . songModel
77
66
. findOne ( { publicId : publicId } )
78
67
. exec ( ) ;
@@ -99,11 +88,7 @@ export class SongService {
99
88
return UploadSongResponseDto . fromSongWithUserDocument ( populatedSong ) ;
100
89
}
101
90
102
- public async patchSong (
103
- publicId : string ,
104
- body : UploadSongDto ,
105
- user : UserDocument ,
106
- ) : Promise < UploadSongResponseDto > {
91
+ public async patchSong ( publicId : string , body : UploadSongDto , user : UserDocument , ) : Promise < UploadSongResponseDto > {
107
92
const foundSong = await this . songModel . findOne ( {
108
93
publicId : publicId ,
109
94
} ) ;
@@ -192,10 +177,7 @@ export class SongService {
192
177
return songs . map ( ( song ) => SongPreviewDto . fromSongDocumentWithUser ( song ) ) ;
193
178
}
194
179
195
- public async searchSongs (
196
- query : PageQueryDTO ,
197
- q : string ,
198
- ) : Promise < SongPreviewDto [ ] > {
180
+ public async searchSongs ( query : PageQueryDTO , q : string , ) : Promise < SongPreviewDto [ ] > {
199
181
const page = parseInt ( query . page ?. toString ( ) ?? '1' ) ;
200
182
const limit = parseInt ( query . limit ?. toString ( ) ?? '10' ) ;
201
183
const order = query . order ? query . order : false ;
@@ -234,10 +216,7 @@ export class SongService {
234
216
return songs . map ( ( song ) => SongPreviewDto . fromSongDocumentWithUser ( song ) ) ;
235
217
}
236
218
237
- public async getRecentSongs (
238
- page : number ,
239
- limit : number ,
240
- ) : Promise < SongPreviewDto [ ] > {
219
+ public async getRecentSongs ( page : number , limit : number , ) : Promise < SongPreviewDto [ ] > {
241
220
const queryObject : any = {
242
221
visibility : 'public' ,
243
222
} ;
@@ -269,9 +248,7 @@ export class SongService {
269
248
. exec ( ) ;
270
249
}
271
250
272
- public async getSongsBeforeTimespan (
273
- timespan : number ,
274
- ) : Promise < SongWithUser [ ] > {
251
+ public async getSongsBeforeTimespan ( timespan : number , ) : Promise < SongWithUser [ ] > {
275
252
return this . songModel
276
253
. find < SongWithUser > ( {
277
254
visibility : 'public' ,
@@ -285,10 +262,7 @@ export class SongService {
285
262
. exec ( ) ;
286
263
}
287
264
288
- public async getSong (
289
- publicId : string ,
290
- user : UserDocument | null ,
291
- ) : Promise < SongViewDto > {
265
+ public async getSong ( publicId : string , user : UserDocument | null , ) : Promise < SongViewDto > {
292
266
const foundSong = await this . songModel . findOne ( { publicId : publicId } ) ;
293
267
294
268
if ( ! foundSong ) {
@@ -318,12 +292,7 @@ export class SongService {
318
292
}
319
293
320
294
// TODO: service should not handle HTTP -> https://www.reddit.com/r/node/comments/uoicw1/should_i_return_status_code_from_service_layer/
321
- public async getSongDownloadUrl (
322
- publicId : string ,
323
- user : UserDocument | null ,
324
- src ?: string ,
325
- packed : boolean = false ,
326
- ) : Promise < string > {
295
+ public async getSongDownloadUrl ( publicId : string , user : UserDocument | null , src ?: string , packed : boolean = false , ) : Promise < string > {
327
296
const foundSong = await this . songModel . findOne ( { publicId : publicId } ) ;
328
297
329
298
if ( ! foundSong ) {
@@ -368,13 +337,7 @@ export class SongService {
368
337
}
369
338
}
370
339
371
- public async getMySongsPage ( {
372
- query,
373
- user,
374
- } : {
375
- query : PageQueryDTO ;
376
- user : UserDocument ;
377
- } ) : Promise < SongPageDto > {
340
+ public async getMySongsPage ( { query, user, } : { query : PageQueryDTO ; user : UserDocument ; } ) : Promise < SongPageDto > {
378
341
const page = parseInt ( query . page ?. toString ( ) ?? '1' ) ;
379
342
const limit = parseInt ( query . limit ?. toString ( ) ?? '10' ) ;
380
343
const order = query . order ? query . order : false ;
@@ -404,10 +367,7 @@ export class SongService {
404
367
} ;
405
368
}
406
369
407
- public async getSongEdit (
408
- publicId : string ,
409
- user : UserDocument ,
410
- ) : Promise < UploadSongDto > {
370
+ public async getSongEdit ( publicId : string , user : UserDocument , ) : Promise < UploadSongDto > {
411
371
const foundSong = await this . songModel
412
372
. findOne ( { publicId : publicId } )
413
373
. exec ( ) ;
@@ -455,11 +415,7 @@ export class SongService {
455
415
} , { } as Record < string , number > ) ;
456
416
}
457
417
458
- public async getSongsByCategory (
459
- category : string ,
460
- page : number ,
461
- limit : number ,
462
- ) : Promise < SongPreviewDto [ ] > {
418
+ public async getSongsByCategory ( category : string , page : number , limit : number , ) : Promise < SongPreviewDto [ ] > {
463
419
const songs = ( await this . songModel
464
420
. find ( {
465
421
category : category ,
@@ -474,10 +430,7 @@ export class SongService {
474
430
return songs . map ( ( song ) => SongPreviewDto . fromSongDocumentWithUser ( song ) ) ;
475
431
}
476
432
477
- public async getRandomSongs (
478
- count : number ,
479
- category : string ,
480
- ) : Promise < SongPreviewDto [ ] > {
433
+ public async getRandomSongs ( count : number , category : string , ) : Promise < SongPreviewDto [ ] > {
481
434
const songs = ( await this . songModel
482
435
. aggregate ( [
483
436
{
@@ -513,15 +466,8 @@ export class SongService {
513
466
year : new Date ( Date . now ( ) ) . setFullYear ( now . getFullYear ( ) - 1 ) ,
514
467
all : new Date ( 0 ) . getTime ( ) ,
515
468
} ;
516
-
517
- const songs : Record < TimespanType , SongWithUser [ ] > = {
518
- hour : [ ] ,
519
- day : [ ] ,
520
- week : [ ] ,
521
- month : [ ] ,
522
- year : [ ] ,
523
- all : [ ] ,
524
- } ;
469
+
470
+ const songs : Record < TimespanType , SongWithUser [ ] > = { hour : [ ] , day : [ ] , week : [ ] , month : [ ] , year : [ ] , all : [ ] , } ;
525
471
526
472
for ( const [ timespan , time ] of Object . entries ( times ) ) {
527
473
const songPage = await this . getSongsForTimespan ( time ) ;
@@ -547,29 +493,12 @@ export class SongService {
547
493
548
494
const featuredSongs = FeaturedSongsDto . create ( ) ;
549
495
550
- featuredSongs . hour = songs . hour . map ( ( song ) =>
551
- SongPreviewDto . fromSongDocumentWithUser ( song ) ,
552
- ) ;
553
-
554
- featuredSongs . day = songs . day . map ( ( song ) =>
555
- SongPreviewDto . fromSongDocumentWithUser ( song ) ,
556
- ) ;
557
-
558
- featuredSongs . week = songs . week . map ( ( song ) =>
559
- SongPreviewDto . fromSongDocumentWithUser ( song ) ,
560
- ) ;
561
-
562
- featuredSongs . month = songs . month . map ( ( song ) =>
563
- SongPreviewDto . fromSongDocumentWithUser ( song ) ,
564
- ) ;
565
-
566
- featuredSongs . year = songs . year . map ( ( song ) =>
567
- SongPreviewDto . fromSongDocumentWithUser ( song ) ,
568
- ) ;
569
-
570
- featuredSongs . all = songs . all . map ( ( song ) =>
571
- SongPreviewDto . fromSongDocumentWithUser ( song ) ,
572
- ) ;
496
+ featuredSongs . hour = songs . hour . map ( ( song ) => SongPreviewDto . fromSongDocumentWithUser ( song ) , ) ;
497
+ featuredSongs . day = songs . day . map ( ( song ) => SongPreviewDto . fromSongDocumentWithUser ( song ) , ) ;
498
+ featuredSongs . week = songs . week . map ( ( song ) => SongPreviewDto . fromSongDocumentWithUser ( song ) , ) ;
499
+ featuredSongs . month = songs . month . map ( ( song ) => SongPreviewDto . fromSongDocumentWithUser ( song ) , ) ;
500
+ featuredSongs . year = songs . year . map ( ( song ) => SongPreviewDto . fromSongDocumentWithUser ( song ) , ) ;
501
+ featuredSongs . all = songs . all . map ( ( song ) => SongPreviewDto . fromSongDocumentWithUser ( song ) , ) ;
573
502
574
503
return featuredSongs ;
575
504
}
0 commit comments