-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Artist controller: Access by slug or id
- Loading branch information
Showing
13 changed files
with
112 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { ArgumentMetadata } from "@nestjs/common"; | ||
import ParseResourceIdentifierPipe from "src/identifier/identifier.pipe"; | ||
import compilationAlbumArtistKeyword from "src/utils/compilation"; | ||
import type ArtistQueryParameters from "./models/artist.query-parameters"; | ||
|
||
class ParseArtistIdentifierPipe extends ParseResourceIdentifierPipe<ArtistQueryParameters.WhereInput> { | ||
transform<T extends { id: any; }>(value: T, _metadata: ArgumentMetadata): ArtistQueryParameters.WhereInput { | ||
const transformedIdentifier = super.transform(value, _metadata); | ||
if (transformedIdentifier.slug?.toString() == compilationAlbumArtistKeyword) { | ||
return { compilationArtist: true }; | ||
} | ||
return transformedIdentifier; | ||
} | ||
}; | ||
export default ParseArtistIdentifierPipe; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { InvalidRequestException } from "src/exceptions/meelo-exception"; | ||
|
||
export default class InvalidIdParsingInput extends InvalidRequestException { | ||
constructor(badInput: string) { | ||
super(`Parsing Resource's ID failed, expected a number, got '${badInput}'`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { PipeTransform, Injectable, ArgumentMetadata } from '@nestjs/common'; | ||
import InvalidIdParsingInput from './id.exceptions'; | ||
@Injectable() | ||
export class ParseIdPipe implements PipeTransform<string> { | ||
transform(value: string, _metadata: ArgumentMetadata): number { | ||
let parsedId: number = parseInt(value); | ||
if (isNaN(parsedId)) { | ||
throw new InvalidIdParsingInput(value); | ||
} | ||
return parsedId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { ArgumentMetadata, PipeTransform } from "@nestjs/common"; | ||
import { ParseIdPipe } from "src/identifier/id.pipe"; | ||
import Slug from "src/slug/slug"; | ||
|
||
export default class ParseResourceIdentifierPipe<W extends Partial<{ id: number, slug: Slug}>> implements PipeTransform { | ||
transform<T extends { id: any }>(value: T, _metadata: ArgumentMetadata): W { | ||
try { | ||
const id = new ParseIdPipe().transform(value.id, _metadata); | ||
return <W>{ id: id }; | ||
} catch { | ||
return <W>{ slug: new Slug(value.id) }; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,5 @@ | ||
import type { ArgumentMetadata, PipeTransform } from "@nestjs/common"; | ||
import { ParseIdPipe } from "src/id/id.pipe"; | ||
import Slug from "src/slug/slug"; | ||
import ParseResourceIdentifierPipe from "src/identifier/identifier.pipe"; | ||
import type LibraryQueryParameters from "./models/library.query-parameters"; | ||
|
||
export default class ParseLibraryIdentifierPipe<T extends { id: any }> implements PipeTransform<T> { | ||
transform(value: T, _metadata: ArgumentMetadata): LibraryQueryParameters.WhereInput { | ||
try { | ||
const id = new ParseIdPipe().transform(value.id, _metadata); | ||
return { id: id }; | ||
} catch { | ||
return { slug: new Slug(value.id) } | ||
} | ||
} | ||
|
||
} | ||
class ParseLibraryIdentifierPipe extends ParseResourceIdentifierPipe<LibraryQueryParameters.WhereInput> {}; | ||
export default ParseLibraryIdentifierPipe; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters