-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Guild, Role, RoleGroup schemas (#1567)
* feat: Guild, Role, RoleGroup schemas * fix: use `.nullish()` * fix: use `.nonnegative()` for memberCount and roleCount * fix: change `groupId`'s type to UUID
- Loading branch information
1 parent
c4333d6
commit d6bab0a
Showing
4 changed files
with
67 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { z } from "zod"; | ||
|
||
export const NameSchema = z | ||
.string() | ||
.max(255, "Maximum name length is 255 characters"); | ||
|
||
export const ImageUrlSchema = z.string().url().max(255); | ||
|
||
export const LogicSchema = z.enum(["AND", "OR", "ANY_OF"]); | ||
|
||
export const DateLike = z.date().or(z.string().datetime()); |
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,19 +1,22 @@ | ||
import { z } from "zod"; | ||
import { DateLike, ImageUrlSchema, NameSchema } from "./common"; | ||
|
||
export const CreateGuildSchema = z.object({ | ||
name: z | ||
.string() | ||
.min(1, "You must specify a name for your guild") | ||
.max(255, "Maximum name length is 255 characters"), | ||
name: NameSchema.min(1, "You must specify a name for your guild"), | ||
urlName: z.string().max(255).optional(), | ||
imageUrl: z.string().max(255).optional(), | ||
imageUrl: ImageUrlSchema.optional(), | ||
description: z.string().optional(), | ||
contact: z.string().email(), | ||
}); | ||
|
||
export type CreateGuildForm = z.infer<typeof CreateGuildSchema>; | ||
|
||
const GuildSchema = CreateGuildSchema.extend({ | ||
id: z.string().uuid(), | ||
createdAt: DateLike, | ||
updatedAt: DateLike, | ||
roleCount: z.number().nonnegative(), | ||
memberCount: z.number().nonnegative(), | ||
}); | ||
|
||
export type Guild = z.infer<typeof GuildSchema>; |
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,30 @@ | ||
import { z } from "zod"; | ||
import { DateLike, ImageUrlSchema, LogicSchema, NameSchema } from "./common"; | ||
|
||
export const CreateRoleSchema = z.object({ | ||
name: NameSchema.min(1, "You must specify a name for the role"), | ||
description: z.string().nullish(), | ||
imageUrl: ImageUrlSchema.nullish(), | ||
settings: z | ||
.object({ | ||
logic: LogicSchema, | ||
position: z.number().positive().nullish(), | ||
anyOfNum: z.number().positive().optional(), | ||
}) | ||
.default({ | ||
logic: "AND", | ||
anyOfNum: 1, | ||
}), | ||
groupId: z.string().uuid(), | ||
}); | ||
|
||
export type CreateRoleForm = z.infer<typeof CreateRoleSchema>; | ||
|
||
const RoleSchema = CreateRoleSchema.extend({ | ||
id: z.string().uuid(), | ||
createdAt: DateLike, | ||
updatedAt: DateLike, | ||
memberCount: z.number().nonnegative(), | ||
}); | ||
|
||
export type Role = z.infer<typeof RoleSchema>; |
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,18 @@ | ||
import { z } from "zod"; | ||
import { DateLike, ImageUrlSchema, NameSchema } from "./common"; | ||
|
||
const CreateRoleGroupSchema = z.object({ | ||
name: NameSchema.min(1, "You must specify a name for the role group"), | ||
description: z.string().nullish(), | ||
imageUrl: ImageUrlSchema.nullish(), | ||
}); | ||
|
||
export type CreateRoleGroupForm = z.infer<typeof CreateRoleGroupSchema>; | ||
|
||
const RoleGroupSchema = CreateRoleGroupSchema.extend({ | ||
id: z.string().uuid(), | ||
createdAt: DateLike, | ||
updatedAt: DateLike, | ||
}); | ||
|
||
export type RoleGroup = z.infer<typeof RoleGroupSchema>; |