expose is active in service
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Global, MiddlewareConsumer, Module } from '@nestjs/common';
|
import { Global, Logger, MiddlewareConsumer, Module } from '@nestjs/common';
|
||||||
|
|
||||||
import { ApolloDriverConfig } from '@nestjs/apollo';
|
import { ApolloDriverConfig } from '@nestjs/apollo';
|
||||||
import { Builder } from './graphql.builder';
|
import { Builder } from './graphql.builder';
|
||||||
@@ -9,6 +9,7 @@ import { ChatroomModule } from '../ChatRoom/chatroom.module';
|
|||||||
import { CommonModule } from '../common/common.module';
|
import { CommonModule } from '../common/common.module';
|
||||||
import { GraphQLModule } from '@nestjs/graphql';
|
import { GraphQLModule } from '@nestjs/graphql';
|
||||||
import { GraphQLValidationMiddleware } from '../middlewares/graphql.middleware';
|
import { GraphQLValidationMiddleware } from '../middlewares/graphql.middleware';
|
||||||
|
import { GraphqlService } from './graphql.service';
|
||||||
import { ManagedServiceModule } from '../ManagedService/managedservice.module';
|
import { ManagedServiceModule } from '../ManagedService/managedservice.module';
|
||||||
import { MessageModule } from '../Message/message.module';
|
import { MessageModule } from '../Message/message.module';
|
||||||
import { MilestoneModule } from '../Milestone/milestone.module';
|
import { MilestoneModule } from '../Milestone/milestone.module';
|
||||||
@@ -20,6 +21,7 @@ import { PrismaCrudGenerator } from './graphql.generator';
|
|||||||
import { PrismaModule } from '../Prisma/prisma.module';
|
import { PrismaModule } from '../Prisma/prisma.module';
|
||||||
import { PrismaService } from '../Prisma/prisma.service';
|
import { PrismaService } from '../Prisma/prisma.service';
|
||||||
import { RefundTicketModule } from '../RefundTicket/refundticket.module';
|
import { RefundTicketModule } from '../RefundTicket/refundticket.module';
|
||||||
|
import { Request } from 'express';
|
||||||
import { ResumeModule } from '../Resume/resume.module';
|
import { ResumeModule } from '../Resume/resume.module';
|
||||||
import { ScheduleModule } from '../Schedule/schedule.module';
|
import { ScheduleModule } from '../Schedule/schedule.module';
|
||||||
import { ServiceAndCategoryModule } from '../ServiceAndCategory/serviceandcategory.module';
|
import { ServiceAndCategoryModule } from '../ServiceAndCategory/serviceandcategory.module';
|
||||||
@@ -77,12 +79,18 @@ import { initContextCache } from '@pothos/core';
|
|||||||
subscriptions: {
|
subscriptions: {
|
||||||
'graphql-ws': true,
|
'graphql-ws': true,
|
||||||
},
|
},
|
||||||
context: async () => ({
|
context: async (req: Request) => ({
|
||||||
...initContextCache(),
|
...initContextCache(),
|
||||||
|
me: await new GraphqlService(new PrismaService()).acquireContext(req),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
|
{
|
||||||
|
provide: GraphqlService,
|
||||||
|
useFactory: (prisma: PrismaService) => new GraphqlService(prisma),
|
||||||
|
inject: [PrismaService],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
provide: Builder,
|
provide: Builder,
|
||||||
useFactory: (prisma: PrismaService) => new Builder(prisma),
|
useFactory: (prisma: PrismaService) => new Builder(prisma),
|
||||||
|
|||||||
@@ -1,4 +1,41 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||||
|
|
||||||
|
import { PrismaService } from '../Prisma/prisma.service';
|
||||||
|
import { Request } from 'express';
|
||||||
|
import { clerkClient } from '@clerk/express';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GraphqlService {}
|
export class GraphqlService {
|
||||||
|
constructor(private readonly prisma: PrismaService) {}
|
||||||
|
|
||||||
|
async acquireContext(req: Request) {
|
||||||
|
// development flag
|
||||||
|
const isDevelopment = process.env.NODE_ENV === 'development';
|
||||||
|
if (isDevelopment) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// get x-session-id from headers
|
||||||
|
let sessionId;
|
||||||
|
try {
|
||||||
|
sessionId = req.headers['x-session-id'];
|
||||||
|
//eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
} catch (error) {
|
||||||
|
throw new UnauthorizedException('Must provide a session ID');
|
||||||
|
}
|
||||||
|
if (!sessionId) {
|
||||||
|
throw new UnauthorizedException('Session ID is required');
|
||||||
|
}
|
||||||
|
// check if the token is valid
|
||||||
|
const session = await clerkClient.sessions.getSession(sessionId as string);
|
||||||
|
if (!session) {
|
||||||
|
throw new UnauthorizedException('Invalid session');
|
||||||
|
}
|
||||||
|
const user = await this.prisma.user.findUnique({
|
||||||
|
where: { id: session.userId },
|
||||||
|
});
|
||||||
|
if (!user) {
|
||||||
|
throw new UnauthorizedException('User not found');
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common';
|
|||||||
|
|
||||||
import { MailerService } from '@nestjs-modules/mailer';
|
import { MailerService } from '@nestjs-modules/mailer';
|
||||||
import { OpenaiService } from '../OpenAI/openai.service';
|
import { OpenaiService } from '../OpenAI/openai.service';
|
||||||
|
import { User } from '@prisma/client';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MailService {
|
export class MailService {
|
||||||
@@ -34,7 +35,7 @@ export class MailService {
|
|||||||
to: string,
|
to: string,
|
||||||
subject: string,
|
subject: string,
|
||||||
template: string,
|
template: string,
|
||||||
context: any,
|
context: User,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const result = await this.mailerService.sendMail({
|
const result = await this.mailerService.sendMail({
|
||||||
|
|||||||
@@ -60,6 +60,9 @@ export class ServiceSchema extends PothosSchema {
|
|||||||
type: ServiceStatus,
|
type: ServiceStatus,
|
||||||
description: 'The status of the service.',
|
description: 'The status of the service.',
|
||||||
}),
|
}),
|
||||||
|
isActive: t.exposeBoolean('isActive', {
|
||||||
|
description: 'Whether the service is active.',
|
||||||
|
}),
|
||||||
createdAt: t.expose('createdAt', {
|
createdAt: t.expose('createdAt', {
|
||||||
type: 'DateTime',
|
type: 'DateTime',
|
||||||
description: 'The date and time the service was created.',
|
description: 'The date and time the service was created.',
|
||||||
|
|||||||
Reference in New Issue
Block a user