refactor source code

This commit is contained in:
2024-10-29 17:42:54 +07:00
parent 3b23d9e0b7
commit 152bb50da8
83 changed files with 8473 additions and 7577 deletions

View File

@@ -1,5 +1,5 @@
import { Module } from '@nestjs/common';
import { UserSchema } from './user.schema';
import { Module } from '@nestjs/common'
import { UserSchema } from './user.schema'
@Module({
providers: [UserSchema],
exports: [UserSchema],

View File

@@ -1,15 +1,15 @@
import { Inject, Injectable, Logger } from '@nestjs/common';
import { Inject, Injectable, Logger } from '@nestjs/common'
import {
Pothos,
PothosRef,
PothosSchema,
SchemaBuilderToken,
} from '@smatch-corp/nestjs-pothos';
import { Builder } from '../Graphql/graphql.builder';
import { PrismaService } from '../Prisma/prisma.service';
import { clerkClient } from '@clerk/express';
import { UnauthorizedException } from '@nestjs/common';
import { MailService } from '../Mail/mail.service';
} from '@smatch-corp/nestjs-pothos'
import { Builder } from '../Graphql/graphql.builder'
import { PrismaService } from '../Prisma/prisma.service'
import { clerkClient } from '@clerk/express'
import { UnauthorizedException } from '@nestjs/common'
import { MailService } from '../Mail/mail.service'
@Injectable()
export class UserSchema extends PothosSchema {
constructor(
@@ -17,7 +17,7 @@ export class UserSchema extends PothosSchema {
private readonly prisma: PrismaService,
private readonly mailService: MailService,
) {
super();
super()
}
// Types section
@@ -99,7 +99,7 @@ export class UserSchema extends PothosSchema {
description: 'The admin note of the user.',
}),
}),
});
})
}
// Query section
@@ -112,8 +112,8 @@ export class UserSchema extends PothosSchema {
sessionId: t.arg({ type: 'String', required: true }),
},
resolve: async (_, { sessionId }) => {
const session = await clerkClient.sessions.getSession(sessionId);
return JSON.parse(JSON.stringify(session));
const session = await clerkClient.sessions.getSession(sessionId)
return JSON.parse(JSON.stringify(session))
},
}),
newSession: t.field({
@@ -128,8 +128,8 @@ export class UserSchema extends PothosSchema {
const session = await clerkClient.signInTokens.createSignInToken({
userId,
expiresInSeconds: 60 * 60 * 24,
});
return session.id;
})
return session.id
},
}),
me: t.prismaField({
@@ -137,9 +137,9 @@ export class UserSchema extends PothosSchema {
type: this.user(),
resolve: async (query, root, args, ctx) => {
if (ctx.isSubscription) {
throw new Error('Not allowed');
throw new Error('Not allowed')
}
return ctx.http.me;
return ctx.http.me
},
}),
@@ -155,7 +155,7 @@ export class UserSchema extends PothosSchema {
skip: args.skip ?? undefined,
orderBy: args.orderBy ?? undefined,
where: args.filter ?? undefined,
});
})
},
}),
@@ -167,7 +167,7 @@ export class UserSchema extends PothosSchema {
return await this.prisma.user.findUniqueOrThrow({
...query,
where: args.where,
});
})
},
}),
userBySession: t.prismaField({
@@ -178,17 +178,17 @@ export class UserSchema extends PothosSchema {
},
resolve: async (query, root, args) => {
// check if the token is valid
const session = await clerkClient.sessions.getSession(args.sessionId);
Logger.log(session, 'Session');
const session = await clerkClient.sessions.getSession(args.sessionId)
Logger.log(session, 'Session')
return await this.prisma.user.findFirstOrThrow({
...query,
where: {
id: session.userId,
},
});
})
},
}),
}));
}))
// Mutation section
this.builder.mutationFields((t) => ({
@@ -210,7 +210,7 @@ export class UserSchema extends PothosSchema {
...query,
where: args.where,
data: args.input,
});
})
},
}),
@@ -228,10 +228,10 @@ export class UserSchema extends PothosSchema {
center_name: 'băng đĩa lậu hải ngoại',
invite_url: 'https://epess.org',
},
);
return 'Email sent';
)
return 'Email sent'
},
}),
}));
}))
}
}