Front: Fix cirular dependecy between validators
This commit is contained in:
committed by
Clément Le Bihan
parent
7a6dc8b0c9
commit
99da77f23e
@@ -6,12 +6,12 @@ import ResponseHandler from './ResponseHandler';
|
||||
import API from '../API';
|
||||
import { AlbumValidator } from './Album';
|
||||
import { GenreValidator } from './Genre';
|
||||
import { SongHistoryItem, SongHistoryItemValidator } from './SongHistory';
|
||||
import { SongHistoryItemWithoutSongValidator } from './SongHistory';
|
||||
|
||||
export type SongInclude = 'artist' | 'album' | 'genre' | 'SongHistory' | 'likedByUsers';
|
||||
|
||||
export const SongValidator = yup
|
||||
.object({
|
||||
.object().shape({
|
||||
name: yup.string().required(),
|
||||
midiPath: yup.string().required(),
|
||||
musicXmlPath: yup.string().required(),
|
||||
@@ -22,7 +22,7 @@ export const SongValidator = yup
|
||||
details: SongDetailsValidator.required(),
|
||||
cover: yup.string().required(),
|
||||
SongHistory: yup
|
||||
.lazy(() => yup.array(SongHistoryItemValidator.default(undefined)))
|
||||
.lazy(() => yup.array(SongHistoryItemWithoutSongValidator.default(undefined)))
|
||||
.optional(),
|
||||
bestScore: yup.number().optional().nullable(),
|
||||
lastScore: yup.number().optional().nullable(),
|
||||
@@ -31,7 +31,7 @@ export const SongValidator = yup
|
||||
genre: yup.lazy(() => GenreValidator.default(undefined)).optional(),
|
||||
})
|
||||
.concat(ModelValidator)
|
||||
.transform((song: Song & { SongHistory: SongHistoryItem[] }) => ({
|
||||
.transform((song: Song) => ({
|
||||
...song,
|
||||
cover: `${API.baseUrl}/song/${song.id}/illustration`,
|
||||
details: song.difficulties,
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import * as yup from 'yup';
|
||||
import ResponseHandler from './ResponseHandler';
|
||||
import { ModelValidator } from './Model';
|
||||
import { SongValidator } from './Song';
|
||||
|
||||
export const SongHistoryItemValidator = yup
|
||||
export const SongHistoryItemWithoutSongValidator = yup
|
||||
.object({
|
||||
songID: yup.number().required(),
|
||||
userID: yup.number().required(),
|
||||
@@ -25,6 +26,12 @@ export const SongHistoryItemValidator = yup
|
||||
difficulties: yup.mixed().required(),
|
||||
})
|
||||
.concat(ModelValidator);
|
||||
|
||||
export const SongHistoryItemValidator = SongHistoryItemWithoutSongValidator
|
||||
.concat(yup.object({
|
||||
song: yup.lazy(() => SongValidator.default(undefined)).optional(),
|
||||
}));
|
||||
|
||||
export type SongHistoryItem = yup.InferType<typeof SongHistoryItemValidator>;
|
||||
|
||||
export const SongHistoryItemHandler: ResponseHandler<SongHistoryItem> = {
|
||||
|
||||
Reference in New Issue
Block a user