diff --git a/api/src/user/controllers/auth.controller.spec.ts b/api/src/user/controllers/auth.controller.spec.ts index b35a5db7..15858d6e 100644 --- a/api/src/user/controllers/auth.controller.spec.ts +++ b/api/src/user/controllers/auth.controller.spec.ts @@ -137,6 +137,7 @@ describe('AuthController', () => { first_name: 'test', last_name: 'test', roles: [role!.id], + avatar: null, }; await invitationService.create(baseUser); }); @@ -157,6 +158,7 @@ describe('AuthController', () => { email: 'test@test.test', password: 'test', roles: ['invalid role value'], + avatar: null, }; await expect(authController.signup(userCreateDto)).rejects.toThrow( @@ -174,6 +176,7 @@ describe('AuthController', () => { email: 'test@test.test', password: 'test', roles: ['659564cb4aa383c0d0dbc688'], + avatar: null, }; const result = await authController.signup(userCreateDto); expect(userService.create).toHaveBeenCalledWith(userCreateDto); diff --git a/api/src/user/controllers/user.controller.spec.ts b/api/src/user/controllers/user.controller.spec.ts index b4c82fb3..c7f5d889 100644 --- a/api/src/user/controllers/user.controller.spec.ts +++ b/api/src/user/controllers/user.controller.spec.ts @@ -210,6 +210,7 @@ describe('UserController', () => { email: 'test@test.test', password: 'test', roles: [role!.id], + avatar: null, }; const result = await userController.create(userDto); expect(userService.create).toHaveBeenCalledWith(userDto); diff --git a/api/src/user/controllers/user.controller.ts b/api/src/user/controllers/user.controller.ts index f765b58e..5f8ff25d 100644 --- a/api/src/user/controllers/user.controller.ts +++ b/api/src/user/controllers/user.controller.ts @@ -250,7 +250,7 @@ export class ReadWriteUserController extends ReadOnlyUserController { .map((role) => role.id), avatar: user.avatar ? (await this.attachmentService.findOne(user.avatar))?.id - : undefined, + : null, }, }); return await this.userService.create(user); diff --git a/api/src/user/dto/user.dto.ts b/api/src/user/dto/user.dto.ts index 56d298ac..2b082b6e 100644 --- a/api/src/user/dto/user.dto.ts +++ b/api/src/user/dto/user.dto.ts @@ -60,7 +60,7 @@ export class UserCreateDto { @IsOptional() @IsString() @IsObjectId({ message: 'Avatar must be a valid ObjectId' }) - avatar?: string; + avatar: string | null = null; } export class UserEditProfileDto extends OmitType(PartialType(UserCreateDto), [ diff --git a/api/src/user/passport/session.serializer.ts b/api/src/user/passport/session.serializer.ts index 3480cf0e..9db750b4 100644 --- a/api/src/user/passport/session.serializer.ts +++ b/api/src/user/passport/session.serializer.ts @@ -35,6 +35,6 @@ export class AuthSerializer extends PassportSerializer { done: (err: Error | null, user: SessionUser | null) => void, ) { const user = payload.id ? await this.userService.findOne(payload.id) : null; - user ? done(null, user) : done(null, null); + done(null, user); } } diff --git a/api/src/user/schemas/user.schema.ts b/api/src/user/schemas/user.schema.ts index 502036b1..a97d2057 100644 --- a/api/src/user/schemas/user.schema.ts +++ b/api/src/user/schemas/user.schema.ts @@ -91,7 +91,7 @@ export class UserStub extends BaseSchema { ref: 'Attachment', default: null, }) - avatar?: unknown; + avatar: unknown; @Prop({ type: String, @@ -112,7 +112,7 @@ export class User extends UserStub { roles: string[]; @Transform(({ obj }) => obj.avatar?.toString() || null) - avatar?: string | null; + avatar: string | null; } @Schema({ timestamps: true }) diff --git a/api/src/utils/test/fixtures/user.ts b/api/src/utils/test/fixtures/user.ts index c5f9d5d9..55a1aaff 100644 --- a/api/src/utils/test/fixtures/user.ts +++ b/api/src/utils/test/fixtures/user.ts @@ -9,7 +9,7 @@ import mongoose from 'mongoose'; import { UserCreateDto } from '@/user/dto/user.dto'; -import { UserModel, User } from '@/user/schemas/user.schema'; +import { User, UserModel } from '@/user/schemas/user.schema'; import { hash } from '@/user/utilities/bcryptjs'; import { getFixturesWithDefaultValues } from '../defaultValues'; @@ -25,6 +25,7 @@ export const users: UserCreateDto[] = [ email: 'admin@admin.admin', password: 'adminadmin', roles: ['0', '1'], + avatar: null, }, ]; @@ -34,7 +35,6 @@ export const userDefaultValues: TFixturesDefaultValues = { timezone: 'Europe/Berlin', sendEmail: false, resetCount: 0, - avatar: null, }; export const getUserFixtures = (users: UserCreateDto[]) =>