Skip to content

Commit

Permalink
✨ Add api schema
Browse files Browse the repository at this point in the history
  • Loading branch information
SnowSuno committed Dec 17, 2023
1 parent d6ab299 commit 736321a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/schema/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type Language = "jp" | "kr";

export type Instrument =
| "guitar"
| "bass"
| "drum"
| "keyboard"
| "vocal"
| "other";

export type Status = "public" | "private";
10 changes: 10 additions & 0 deletions src/schema/filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Instrument, Language } from "@/schema/enums";

export interface Filter {
query: string;
language: Language | null;
instrument: Instrument | null;
password: boolean | null;
}

export type FilterType = keyof Filter;
9 changes: 6 additions & 3 deletions src/schema/icon.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { z } from "zod";

export const iconSchema = z.object({
preset: z.coerce.number(),
type: z.enum(["preset", "url"]),
url: z.string().url(),
preset: z.coerce.number().default(0),
type: z.enum(["preset", "url"]).default("preset"),
url: z
.string()
.transform(url => url.replace("http://", "https://"))
.default(""),
});

export type Icon = z.infer<typeof iconSchema>;
5 changes: 5 additions & 0 deletions src/schema/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from "./enums";
export * from "./filter";
export * from "./icon";
export * from "./member";
export * from "./room";
4 changes: 2 additions & 2 deletions src/schema/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ export const memberSchema = z.object({
userId: z.string(),
nickname: z.string(),
nsgmMemberId: z.coerce.number(),
iconInfo: iconSchema,
iconInfo: iconSchema.default({ preset: 0, type: "preset", url: "" }),
favorite: z.boolean(),
});

export type Member = z.infer<typeof memberSchema>;

export const creatorSchema = memberSchema.extend({
idProvider: z.enum(["ymid-jp", "ymid-kr"]),
idProvider: z.enum(["ymid-jp", "ymid-kr", ""]),
});

export type Creator = z.infer<typeof creatorSchema>;

0 comments on commit 736321a

Please sign in to comment.