refactor(validators): frontend to new schema
This commit is contained in:
@ -1,14 +1,15 @@
|
||||
import {
|
||||
type InferOutput,
|
||||
null as Null,
|
||||
array,
|
||||
nullable,
|
||||
object,
|
||||
parse,
|
||||
pipe,
|
||||
string,
|
||||
undefinedable,
|
||||
null_,
|
||||
uuid,
|
||||
literal,
|
||||
variant,
|
||||
} from "valibot";
|
||||
|
||||
type BaseRequestParams = Partial<{
|
||||
@ -56,60 +57,26 @@ const locationValidator = object({
|
||||
Description: nullable(string()),
|
||||
});
|
||||
|
||||
const getUserImagesResponseValidator = array(
|
||||
object({
|
||||
ID: pipe(string(), uuid()),
|
||||
Image: object({
|
||||
ID: pipe(string(), uuid()),
|
||||
ImageName: string(),
|
||||
Image: Null(),
|
||||
}),
|
||||
Tags: nullable(
|
||||
array(
|
||||
object({
|
||||
ID: pipe(string(), uuid()),
|
||||
TagID: pipe(string(), uuid()),
|
||||
ImageID: pipe(string(), uuid()),
|
||||
|
||||
Tag: object({
|
||||
ID: pipe(string(), uuid()),
|
||||
Tag: string(),
|
||||
UserID: pipe(string(), uuid()),
|
||||
}),
|
||||
}),
|
||||
),
|
||||
),
|
||||
Links: nullable(
|
||||
array(
|
||||
object({
|
||||
ID: pipe(string(), uuid()),
|
||||
Link: string(),
|
||||
ImageID: pipe(string(), uuid()),
|
||||
}),
|
||||
),
|
||||
),
|
||||
Text: nullable(
|
||||
array(
|
||||
object({
|
||||
ID: pipe(string(), uuid()),
|
||||
ImageText: string(),
|
||||
ImageID: pipe(string(), uuid()),
|
||||
}),
|
||||
),
|
||||
),
|
||||
Locations: nullable(array(locationValidator)),
|
||||
Events: nullable(
|
||||
array(
|
||||
object({
|
||||
const eventValidator = object({
|
||||
ID: pipe(string(), uuid()),
|
||||
Name: string(),
|
||||
Description: nullable(string()),
|
||||
Location: nullable(locationValidator),
|
||||
}),
|
||||
),
|
||||
),
|
||||
}),
|
||||
);
|
||||
LocationID: nullable(pipe(string(), uuid())),
|
||||
Location: null_(),
|
||||
});
|
||||
|
||||
const locationDataType = object({
|
||||
type: literal("location"),
|
||||
data: locationValidator,
|
||||
});
|
||||
|
||||
const eventDataType = object({
|
||||
type: literal("event"),
|
||||
data: eventValidator,
|
||||
});
|
||||
|
||||
const dataTypeValidator = variant("type", [locationDataType, eventDataType]);
|
||||
const getUserImagesResponseValidator = array(dataTypeValidator);
|
||||
|
||||
export const getUserImages = async (): Promise<
|
||||
InferOutput<typeof getUserImagesResponseValidator>
|
||||
|
Reference in New Issue
Block a user