mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
feat: support remove user & workspace avatar (#4302)
This commit is contained in:
@@ -63,6 +63,11 @@ export class DeleteAccount {
|
||||
@Field()
|
||||
success!: boolean;
|
||||
}
|
||||
@ObjectType()
|
||||
export class RemoveAvatar {
|
||||
@Field()
|
||||
success!: boolean;
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
export class AddToNewFeaturesWaitingList {
|
||||
@@ -151,6 +156,22 @@ export class UserResolver {
|
||||
});
|
||||
}
|
||||
|
||||
@Throttle(10, 60)
|
||||
@Mutation(() => RemoveAvatar, {
|
||||
name: 'removeAvatar',
|
||||
description: 'Remove user avatar',
|
||||
})
|
||||
async removeAvatar(@CurrentUser() user: UserType) {
|
||||
if (!user) {
|
||||
throw new BadRequestException(`User not found`);
|
||||
}
|
||||
await this.prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: { avatarUrl: null },
|
||||
});
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
@Throttle(10, 60)
|
||||
@Mutation(() => DeleteAccount)
|
||||
async deleteAccount(@CurrentUser() user: UserType): Promise<DeleteAccount> {
|
||||
|
||||
@@ -34,6 +34,10 @@ type DeleteAccount {
|
||||
success: Boolean!
|
||||
}
|
||||
|
||||
type RemoveAvatar {
|
||||
success: Boolean!
|
||||
}
|
||||
|
||||
type AddToNewFeaturesWaitingList {
|
||||
email: String!
|
||||
|
||||
@@ -187,6 +191,9 @@ type Mutation {
|
||||
|
||||
"""Upload user avatar"""
|
||||
uploadAvatar(id: String!, avatar: Upload!): UserType!
|
||||
|
||||
"""Remove user avatar"""
|
||||
removeAvatar: RemoveAvatar!
|
||||
deleteAccount: DeleteAccount!
|
||||
addToNewFeaturesWaitingList(type: NewFeaturesKind!, email: String!): AddToNewFeaturesWaitingList!
|
||||
signUp(name: String!, email: String!, password: String!): UserType!
|
||||
|
||||
@@ -124,7 +124,7 @@ test('should find default user', async t => {
|
||||
});
|
||||
});
|
||||
|
||||
test('should be able to upload avatar', async t => {
|
||||
test('should be able to upload avatar and remove it', async t => {
|
||||
const { token, id } = await createToken(t.context.app);
|
||||
const png = await Transformer.fromRgbaPixels(
|
||||
Buffer.alloc(400 * 400 * 4).fill(255),
|
||||
@@ -157,6 +157,27 @@ test('should be able to upload avatar', async t => {
|
||||
.expect(res => {
|
||||
t.is(res.body.data.uploadAvatar.id, id);
|
||||
});
|
||||
|
||||
await request(t.context.app.getHttpServer())
|
||||
.post(gql)
|
||||
.auth(token, { type: 'bearer' })
|
||||
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
|
||||
.send({
|
||||
query: `
|
||||
mutation removeAvatar {
|
||||
removeAvatar {
|
||||
id
|
||||
name
|
||||
avatarUrl
|
||||
email
|
||||
}
|
||||
}
|
||||
`,
|
||||
})
|
||||
.expect(200)
|
||||
.expect(res => {
|
||||
t.is(res.body.data.removeAvatar.avatarUrl, '');
|
||||
});
|
||||
});
|
||||
|
||||
async function createToken(app: INestApplication<Express>): Promise<{
|
||||
|
||||
Reference in New Issue
Block a user