|
1 | | -import { DeleteObjectCommand } from '@aws-sdk/client-s3'; |
2 | 1 | import { z } from 'zod'; |
3 | 2 |
|
4 | | -import { s3client } from '@/lib/s3'; |
5 | | - |
6 | | -import { envServer } from '@/env/server'; |
7 | 3 | import { zFormFieldsOnboarding } from '@/features/auth/schema'; |
8 | 4 | import { zUser } from '@/features/user/schema'; |
9 | 5 | import { protectedProcedure } from '@/server/orpc'; |
@@ -50,42 +46,11 @@ export default { |
50 | 46 | .handler(async ({ context, input }) => { |
51 | 47 | context.logger.info('Update user'); |
52 | 48 |
|
53 | | - // If profilePictureId is defined, check to delete the old one |
54 | | - if (input.avatarFileId) { |
55 | | - // Remove old file if there was one |
56 | | - const deleteCommand = new DeleteObjectCommand({ |
57 | | - Bucket: envServer.S3_BUCKET_NAME, |
58 | | - Key: context.user.avatarFileId, |
59 | | - }); |
60 | | - try { |
61 | | - await s3client.send(deleteCommand); |
62 | | - } catch (error) { |
63 | | - context.logger.warn('Fail to delete user profile picture', { |
64 | | - profilePictureId: context.user.avatarFileId, |
65 | | - error, |
66 | | - }); |
67 | | - } |
68 | | - |
69 | | - try { |
70 | | - await context.db.user.update({ |
71 | | - where: { id: context.user.id }, |
72 | | - data: { |
73 | | - avatarFileId: input.avatarFileId, |
74 | | - }, |
75 | | - }); |
76 | | - } catch (error) { |
77 | | - context.logger.warn('Fail to save user profile picture', { |
78 | | - profilePictureId: context.user.avatarFileId, |
79 | | - error, |
80 | | - }); |
81 | | - } |
82 | | - return; |
83 | | - } |
84 | | - |
85 | 49 | await context.db.user.update({ |
86 | 50 | where: { id: context.user.id }, |
87 | 51 | data: { |
88 | | - name: input.name ?? '', |
| 52 | + name: input.name ?? context.user.name, |
| 53 | + avatarFileId: input.avatarFileId ?? context.user.avatarFileId, |
89 | 54 | }, |
90 | 55 | }); |
91 | 56 | }), |
|
0 commit comments