Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { UserMetadataItem } from 'src/types';
export type AuthUser = {
id: string;
isAdmin: boolean;
name: string;
name: string | null;
email: string;
quotaUsageInBytes: number;
quotaSizeInBytes: number | null;
Expand Down Expand Up @@ -125,7 +125,7 @@ export type Asset = {

export type User = {
id: string;
name: string;
name: string | null;
email: string;
avatarColor: UserAvatarColor | null;
profileImagePath: string;
Expand Down
4 changes: 2 additions & 2 deletions server/src/dtos/auth.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const LoginResponseSchema = z
accessToken: z.string().describe('Access token'),
userId: z.uuidv4().describe('User ID'),
userEmail: toEmail.describe('User email'),
name: z.string().describe('User name'),
name: z.string().nullable().describe('User name'),
profileImagePath: z.string().describe('Profile image path'),
isAdmin: z.boolean().describe('Is admin user'),
shouldChangePassword: z.boolean().describe('Should change password'),
Expand Down Expand Up @@ -64,7 +64,7 @@ const LogoutResponseSchema = z
.meta({ id: 'LogoutResponseDto' });

const SignUpSchema = LoginCredentialSchema.extend({
name: z.string().describe('User name').meta({ example: 'Admin' }),
name: z.string().transform(v => v === '' ? null : v).describe('User name').meta({ example: 'Admin' }),
}).meta({ id: 'SignUpDto' });

const ChangePasswordSchema = z
Expand Down
2 changes: 1 addition & 1 deletion server/src/dtos/sync.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import z from 'zod';
const SyncUserV1Schema = z
.object({
id: z.uuidv4().describe('User ID'),
name: z.string().describe('User name'),
name: z.string().nullable().describe('User name'),
email: z.string().describe('User email'),
avatarColor: UserAvatarColorSchema.nullish(),
deletedAt: isoDatetimeToDate.nullable().describe('User deleted at'),
Expand Down
8 changes: 4 additions & 4 deletions server/src/dtos/user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const UserUpdateMeSchema = z
.optional()
.describe('User password (deprecated, use change password endpoint)')
.meta({ deprecated: true }),
name: z.string().optional().describe('User name'),
name: z.string().nullish().transform(v => v === '' ? null : v),
avatarColor: UserAvatarColorSchema.nullish(),
})
.meta({ id: 'UserUpdateMeDto' });
Expand All @@ -25,7 +25,7 @@ export class UserUpdateMeDto extends createZodDto(UserUpdateMeSchema) {}
export const UserResponseSchema = z
.object({
id: z.uuidv4().describe('User ID'),
name: z.string().describe('User name'),
name: z.string().nullable().describe('User name'),
email: toEmail.describe('User email'),
profileImagePath: z.string().describe('Profile image path'),
avatarColor: UserAvatarColorSchema,
Expand Down Expand Up @@ -78,7 +78,7 @@ export const UserAdminCreateSchema = z
.object({
email: toEmail.describe('User email'),
password: z.string().describe('User password'),
name: z.string().describe('User name'),
name: z.string().transform(v => v === '' ? null : v).describe('User name'),
avatarColor: UserAvatarColorSchema.nullish(),
pinCode: z.string().regex(pinCodeRegex).nullable().optional().describe('PIN code').meta({ example: '123456' }),
storageLabel: z.string().pipe(sanitizeFilename).nullish().describe('Storage label'),
Expand All @@ -96,7 +96,7 @@ const UserAdminUpdateSchema = z
email: toEmail.optional().describe('User email'),
password: z.string().optional().describe('User password'),
pinCode: z.string().regex(pinCodeRegex).nullable().optional().describe('PIN code').meta({ example: '123456' }),
name: z.string().optional().describe('User name'),
name: z.string().nullish().transform(v => v === '' ? null : v),
avatarColor: UserAvatarColorSchema.nullish(),
storageLabel: z.string().pipe(sanitizeFilename).nullish().describe('Storage label'),
shouldChangePassword: z.boolean().optional().describe('Require password change on next login'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Kysely, sql } from 'kysely';

export async function up(db: Kysely<any>): Promise<void> {
await sql`ALTER TABLE "user" ALTER COLUMN "name" DROP NOT NULL;`.execute(db);
await sql`ALTER TABLE "user" ALTER COLUMN "name" SET DEFAULT NULL;`.execute(db);
await sql`UPDATE "user" SET "name" = NULL WHERE "name" = '';`.execute(db);
}

export async function down(db: Kysely<any>): Promise<void> {
await sql`UPDATE "user" SET "name" = '' WHERE "name" IS NULL;`.execute(db);
await sql`ALTER TABLE "user" ALTER COLUMN "name" SET DEFAULT '';`.execute(db);
await sql`ALTER TABLE "user" ALTER COLUMN "name" SET NOT NULL;`.execute(db);
}
5 changes: 2 additions & 3 deletions server/src/schema/tables/user.table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ export class UserTable {
@Column({ unique: true, nullable: true, default: null })
storageLabel!: string | null;

// TODO remove default, make nullable, and convert empty spaces to null
@Column({ default: '' })
name!: string;
@Column({ nullable: true, default: null })
name!: string | null;

@Column({ type: 'bigint', nullable: true })
quotaSizeInBytes!: ColumnType<number> | null;
Expand Down
Loading