mirror of
https://github.com/hexastack/hexabot
synced 2025-01-22 18:45:57 +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',
|
first_name: 'test',
|
||||||
last_name: 'test',
|
last_name: 'test',
|
||||||
roles: [role!.id],
|
roles: [role!.id],
|
||||||
|
avatar: null,
|
||||||
};
|
};
|
||||||
await invitationService.create(baseUser);
|
await invitationService.create(baseUser);
|
||||||
});
|
});
|
||||||
@ -157,6 +158,7 @@ describe('AuthController', () => {
|
|||||||
email: 'test@test.test',
|
email: 'test@test.test',
|
||||||
password: 'test',
|
password: 'test',
|
||||||
roles: ['invalid role value'],
|
roles: ['invalid role value'],
|
||||||
|
avatar: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
await expect(authController.signup(userCreateDto)).rejects.toThrow(
|
await expect(authController.signup(userCreateDto)).rejects.toThrow(
|
||||||
@ -174,6 +176,7 @@ describe('AuthController', () => {
|
|||||||
email: 'test@test.test',
|
email: 'test@test.test',
|
||||||
password: 'test',
|
password: 'test',
|
||||||
roles: ['659564cb4aa383c0d0dbc688'],
|
roles: ['659564cb4aa383c0d0dbc688'],
|
||||||
|
avatar: null,
|
||||||
};
|
};
|
||||||
const result = await authController.signup(userCreateDto);
|
const result = await authController.signup(userCreateDto);
|
||||||
expect(userService.create).toHaveBeenCalledWith(userCreateDto);
|
expect(userService.create).toHaveBeenCalledWith(userCreateDto);
|
||||||
|
@ -210,6 +210,7 @@ describe('UserController', () => {
|
|||||||
email: 'test@test.test',
|
email: 'test@test.test',
|
||||||
password: 'test',
|
password: 'test',
|
||||||
roles: [role!.id],
|
roles: [role!.id],
|
||||||
|
avatar: null,
|
||||||
};
|
};
|
||||||
const result = await userController.create(userDto);
|
const result = await userController.create(userDto);
|
||||||
expect(userService.create).toHaveBeenCalledWith(userDto);
|
expect(userService.create).toHaveBeenCalledWith(userDto);
|
||||||
|
@ -250,7 +250,7 @@ export class ReadWriteUserController extends ReadOnlyUserController {
|
|||||||
.map((role) => role.id),
|
.map((role) => role.id),
|
||||||
avatar: user.avatar
|
avatar: user.avatar
|
||||||
? (await this.attachmentService.findOne(user.avatar))?.id
|
? (await this.attachmentService.findOne(user.avatar))?.id
|
||||||
: undefined,
|
: null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return await this.userService.create(user);
|
return await this.userService.create(user);
|
||||||
|
@ -60,7 +60,7 @@ export class UserCreateDto {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsObjectId({ message: 'Avatar must be a valid ObjectId' })
|
@IsObjectId({ message: 'Avatar must be a valid ObjectId' })
|
||||||
avatar?: string;
|
avatar: string | null = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UserEditProfileDto extends OmitType(PartialType(UserCreateDto), [
|
export class UserEditProfileDto extends OmitType(PartialType(UserCreateDto), [
|
||||||
|
@ -35,6 +35,6 @@ export class AuthSerializer extends PassportSerializer {
|
|||||||
done: (err: Error | null, user: SessionUser | null) => void,
|
done: (err: Error | null, user: SessionUser | null) => void,
|
||||||
) {
|
) {
|
||||||
const user = payload.id ? await this.userService.findOne(payload.id) : null;
|
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',
|
ref: 'Attachment',
|
||||||
default: null,
|
default: null,
|
||||||
})
|
})
|
||||||
avatar?: unknown;
|
avatar: unknown;
|
||||||
|
|
||||||
@Prop({
|
@Prop({
|
||||||
type: String,
|
type: String,
|
||||||
@ -112,7 +112,7 @@ export class User extends UserStub {
|
|||||||
roles: string[];
|
roles: string[];
|
||||||
|
|
||||||
@Transform(({ obj }) => obj.avatar?.toString() || null)
|
@Transform(({ obj }) => obj.avatar?.toString() || null)
|
||||||
avatar?: string | null;
|
avatar: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Schema({ timestamps: true })
|
@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 mongoose from 'mongoose';
|
||||||
|
|
||||||
import { UserCreateDto } from '@/user/dto/user.dto';
|
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 { hash } from '@/user/utilities/bcryptjs';
|
||||||
|
|
||||||
import { getFixturesWithDefaultValues } from '../defaultValues';
|
import { getFixturesWithDefaultValues } from '../defaultValues';
|
||||||
@ -25,6 +25,7 @@ export const users: UserCreateDto[] = [
|
|||||||
email: 'admin@admin.admin',
|
email: 'admin@admin.admin',
|
||||||
password: 'adminadmin',
|
password: 'adminadmin',
|
||||||
roles: ['0', '1'],
|
roles: ['0', '1'],
|
||||||
|
avatar: null,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -34,7 +35,6 @@ export const userDefaultValues: TFixturesDefaultValues<User> = {
|
|||||||
timezone: 'Europe/Berlin',
|
timezone: 'Europe/Berlin',
|
||||||
sendEmail: false,
|
sendEmail: false,
|
||||||
resetCount: 0,
|
resetCount: 0,
|
||||||
avatar: null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getUserFixtures = (users: UserCreateDto[]) =>
|
export const getUserFixtures = (users: UserCreateDto[]) =>
|
||||||
|
Loading…
Reference in New Issue
Block a user