feat: support remove user & workspace avatar (#4302)

This commit is contained in:
Qi
2023-09-14 22:35:05 +08:00
committed by GitHub
parent e1a330a0a6
commit 465098cc9a
40 changed files with 504 additions and 808 deletions

View File

@@ -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> {

View File

@@ -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!

View File

@@ -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<{