From eb405d33cdaf4604e35b7966745e72403bb9a96f Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Thu, 28 Nov 2024 10:54:44 +0100 Subject: [PATCH] fix(api): :bug: Don't use null in Role properties --- classes/database/role.ts | 14 +++++++------- classes/database/user.ts | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/classes/database/role.ts b/classes/database/role.ts index 0bcddcf0..3ab7bc51 100644 --- a/classes/database/role.ts +++ b/classes/database/role.ts @@ -24,11 +24,11 @@ export class Role extends BaseInterface { public static schema = z.object({ id: z.string().uuid(), name: z.string().min(1).max(128), - permissions: z.array(z.nativeEnum(RolePermission)), - priority: z.number().int(), - description: z.string().min(0).max(1024).nullable(), - visible: z.boolean(), - icon: z.string().url().nullable(), + permissions: z.array(z.nativeEnum(RolePermission)).default([]), + priority: z.number().int().default(0), + description: z.string().min(0).max(1024).optional(), + visible: z.boolean().default(true), + icon: z.string().url().optional(), }); public static $type: RoleType; @@ -225,9 +225,9 @@ export class Role extends BaseInterface { name: this.data.name, permissions: this.data.permissions as unknown as RolePermission[], priority: this.data.priority, - description: this.data.description, + description: this.data.description ?? undefined, visible: this.data.visible, - icon: proxyUrl(this.data.icon), + icon: proxyUrl(this.data.icon) ?? undefined, }; } } diff --git a/classes/database/user.ts b/classes/database/user.ts index b6239605..85c28c27 100644 --- a/classes/database/user.ts +++ b/classes/database/user.ts @@ -78,6 +78,7 @@ type UserWithRelations = UserWithInstance & { * Gives helpers to fetch users from database in a nice format */ export class User extends BaseInterface { + // @ts-expect-error Roles are weird public static schema: z.ZodType = z.object({ id: z.string(), username: z.string(),