mirror of
https://github.com/hexastack/hexabot
synced 2025-01-22 10:35:37 +00:00
fix: make user avatar field required
This commit is contained in:
parent
3c1f115a7c
commit
8ab2f16c56
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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), [
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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 })
|
||||
|
4
api/src/utils/test/fixtures/user.ts
vendored
4
api/src/utils/test/fixtures/user.ts
vendored
@ -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<User> = {
|
||||
timezone: 'Europe/Berlin',
|
||||
sendEmail: false,
|
||||
resetCount: 0,
|
||||
avatar: null,
|
||||
};
|
||||
|
||||
export const getUserFixtures = (users: UserCreateDto[]) =>
|
||||
|
Loading…
Reference in New Issue
Block a user