fix time geneate logic and replace default datetime by luxon
This commit is contained in:
@@ -214,6 +214,113 @@ export class UserSchema extends PothosSchema {
|
||||
},
|
||||
}),
|
||||
|
||||
updateMe: t.field({
|
||||
type: this.user(),
|
||||
description: 'Update the current user in context.',
|
||||
args: {
|
||||
input: t.arg({
|
||||
type: this.builder.generator.getUpdateInput('User', [
|
||||
'id',
|
||||
'adminNote',
|
||||
'center',
|
||||
'customerChatRoom',
|
||||
'avatarUrl',
|
||||
// 'bankAccountNumber',
|
||||
// 'bankBin',
|
||||
'email',
|
||||
'name',
|
||||
'phoneNumber',
|
||||
'role',
|
||||
'createdAt',
|
||||
'updatedAt',
|
||||
'files',
|
||||
'orders',
|
||||
'sendingMessage',
|
||||
'mentor',
|
||||
'mentorChatRoom',
|
||||
'resume',
|
||||
'service',
|
||||
'serviceFeedbacks',
|
||||
'workshopSubscription',
|
||||
]),
|
||||
required: false,
|
||||
}),
|
||||
imageBlob: t.arg({
|
||||
type: 'Upload',
|
||||
required: false,
|
||||
}),
|
||||
firstName: t.arg({
|
||||
type: 'String',
|
||||
required: false,
|
||||
}),
|
||||
lastName: t.arg({
|
||||
type: 'String',
|
||||
required: false,
|
||||
}),
|
||||
},
|
||||
resolve: async (_query, args, ctx, _info) => {
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Not allowed')
|
||||
}
|
||||
const id = ctx.http.me.id
|
||||
if (args.imageBlob) {
|
||||
const { mimetype, createReadStream } = await args.imageBlob
|
||||
if (mimetype && createReadStream) {
|
||||
const stream = createReadStream()
|
||||
const chunks: Uint8Array[] = []
|
||||
|
||||
for await (const chunk of stream) {
|
||||
chunks.push(chunk)
|
||||
}
|
||||
|
||||
const buffer = Buffer.concat(chunks)
|
||||
await clerkClient.users.updateUserProfileImage(id, {
|
||||
file: new Blob([buffer]),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// update info to clerk
|
||||
const clerkUser = await clerkClient.users.updateUser(id, {
|
||||
firstName: args.firstName as string,
|
||||
lastName: args.lastName as string,
|
||||
})
|
||||
Logger.log(clerkUser, 'Clerk User')
|
||||
// update bank account number and bank bin to database
|
||||
if (args.input?.bankAccountNumber) {
|
||||
await this.prisma.user.update({
|
||||
where: { id: clerkUser.id },
|
||||
data: {
|
||||
bankAccountNumber: args.input.bankAccountNumber,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if (args.input?.bankBin) {
|
||||
await this.prisma.user.update({
|
||||
where: { id: clerkUser.id },
|
||||
data: {
|
||||
bankBin: args.input.bankBin,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if (args.firstName || args.lastName) {
|
||||
await this.prisma.user.update({
|
||||
where: { id: clerkUser.id },
|
||||
data: {
|
||||
name: `${args.firstName || ''} ${args.lastName || ''}`.trim(),
|
||||
},
|
||||
})
|
||||
}
|
||||
// invalidate cache
|
||||
await ctx.http.invalidateCache()
|
||||
return await this.prisma.user.findUniqueOrThrow({
|
||||
where: { id: clerkUser.id },
|
||||
})
|
||||
},
|
||||
}),
|
||||
|
||||
inviteModerator: t.field({
|
||||
type: 'String',
|
||||
args: {
|
||||
|
||||
Reference in New Issue
Block a user