implement redis cache for context

This commit is contained in:
2024-10-29 00:56:23 +07:00
parent ae1aa64b41
commit 34cea2ccd3
18 changed files with 477 additions and 55 deletions

View File

@@ -129,7 +129,7 @@ export class UserSchema extends PothosSchema {
me: t.prismaField({
description: 'Retrieve the current user by token.',
type: this.user(),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args, ctx) => {
// get session id from X-Session-Id
const sessionId = ctx.req.headers['x-session-id'];
if (!sessionId)
@@ -155,7 +155,7 @@ export class UserSchema extends PothosSchema {
'Retrieve a list of users with optional filtering, ordering, and pagination.',
type: [this.user()],
args: this.builder.generator.findManyArgs('User'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.user.findMany({
...query,
take: args.take ?? undefined,
@@ -170,7 +170,7 @@ export class UserSchema extends PothosSchema {
description: 'Retrieve a single user by their unique identifier.',
type: this.user(),
args: this.builder.generator.findUniqueArgs('User'),
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.user.findUniqueOrThrow({
...query,
where: args.where,
@@ -183,7 +183,7 @@ export class UserSchema extends PothosSchema {
args: {
sessionId: t.arg({ type: 'String', required: true }),
},
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
// check if the token is valid
const session = await clerkClient.sessions.getSession(args.sessionId);
Logger.log(session, 'Session');
@@ -212,7 +212,7 @@ export class UserSchema extends PothosSchema {
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
resolve: async (query, root, args) => {
return await this.prisma.user.update({
...query,
where: args.where,
@@ -221,29 +221,14 @@ export class UserSchema extends PothosSchema {
},
}),
// banUser: t.prismaField({
// description: 'Ban a user.',
// type: this.user(),
// args: {
// userId: t.arg({ type: 'String', required: true }),
// },
// resolve: async (query, root, args, ctx, info) => {
// return await this.prisma.user.update({
// ...query,
// where: { id: args.userId },
// data: { banned: true },
// });
// },
// }),
sendEmailTest: t.field({
type: 'String',
args: {
to: t.arg({ type: 'String', required: true }),
},
resolve: async (_parent, args, _context, _info) => {
resolve: async (_parent, args) => {
await this.mailService.sendTemplateEmail(
args.to,
[args.to],
'Bạn đã được mời làm việc tại Trung tâm băng đĩa lậu hải ngoại',
'MentorInvitation',
{