update handle session

This commit is contained in:
2024-10-25 15:19:20 +07:00
parent 7e25e8d96b
commit 2b6d3869f9
4 changed files with 28 additions and 6 deletions

View File

@@ -8,7 +8,6 @@ import {
import { Builder } from '../Graphql/graphql.builder';
import { PrismaService } from '../Prisma/prisma.service';
import { clerkClient } from '@clerk/express';
import type { Session } from '@clerk/express';
import { UnauthorizedException } from '@nestjs/common';
@Injectable()
@@ -48,6 +47,10 @@ export class UserSchema extends PothosSchema {
nullable: true,
description: 'The role of the user.',
}),
avatarUrl: t.exposeString('avatarUrl', {
nullable: true,
description: 'The avatar URL of the user.',
}),
createdAt: t.expose('createdAt', {
type: 'DateTime',
nullable: true,
@@ -160,7 +163,7 @@ export class UserSchema extends PothosSchema {
type: this.user(),
args: this.builder.generator.findUniqueArgs('User'),
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.user.findUnique({
return await this.prisma.user.findUniqueOrThrow({
...query,
where: args.where,
});
@@ -176,7 +179,7 @@ export class UserSchema extends PothosSchema {
// check if the token is valid
const session = await clerkClient.sessions.getSession(args.sessionId);
Logger.log(session, 'Session');
return await this.prisma.user.findFirst({
return await this.prisma.user.findFirstOrThrow({
...query,
where: {
id: session.userId,