refactor api
This commit is contained in:
@@ -10,13 +10,14 @@ services:
|
||||
volumes:
|
||||
- ./src:/app/src
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
- NODE_ENV=production
|
||||
- DATABASE_URL=postgresql://your_username:your_password@10.0.27.1:5432/epess
|
||||
- CLERK_PUBLISHABLE_KEY=pk_test_aW4tY2hpbXAtOTcuY2xlcmsuYWNjb3VudHMuZGV2JA
|
||||
- CLERK_SECRET_KEY=sk_test_sA5lsb1GHwUNXWQCp5ev70QkaoF5EmdAHNWiCGwZF6
|
||||
- CORS_ORIGIN=https://epess.org,https://admin.epess.org,https://center.epess.org,http://localhost:3000,http://localhost:3069,http://localhost:3001
|
||||
- LISTEN_PORT=3069
|
||||
- SWAGGER_PATH=/v1
|
||||
- SWAGGER_PATH=/swagger
|
||||
- API_PATH=/v1
|
||||
labels:
|
||||
- 'traefik.enable=true'
|
||||
- 'traefik.http.routers.api.rule=Host(`api.epess.org`)'
|
||||
|
||||
@@ -18,7 +18,7 @@ export class ClerkController {
|
||||
@Post('webhook')
|
||||
@ApiOperation({ summary: 'Clerk Webhook' })
|
||||
@ApiResponse({ status: 200, description: 'Webhook created successfully' })
|
||||
webhook(@Body() body: any) {
|
||||
webhook(@Headers() headers: any, @Body() body: any) {
|
||||
return this.clerkService.webhook(body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { PrismaService } from '../Prisma/prisma.service';
|
||||
export class ClerkService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
webhook(body: any) {
|
||||
|
||||
// get the event type
|
||||
const eventType = body.type;
|
||||
// dispatch the event
|
||||
@@ -51,7 +52,6 @@ export class ClerkService {
|
||||
}
|
||||
async eventUserCreated(data: any) {
|
||||
console.log(data);
|
||||
// create a user in the database
|
||||
const primary_email_address_id = data.primary_email_address_id;
|
||||
// get primary email address on email_addresses by querying email_addresses with primary_email_address_id
|
||||
let primary_email_address = data.email_addresses.find(
|
||||
@@ -82,8 +82,14 @@ export class ClerkService {
|
||||
});
|
||||
}
|
||||
|
||||
eventUserUpdated(data: any) {
|
||||
async eventUserUpdated(data: any) {
|
||||
console.log(data);
|
||||
const user_id = data.id;
|
||||
const name = `${data.first_name} ${data.last_name}`;
|
||||
await this.prisma.user.update({
|
||||
where: { id: user_id },
|
||||
data: { name: name },
|
||||
});
|
||||
}
|
||||
|
||||
eventSessionCreated(data: any) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ApolloDriverConfig } from '@nestjs/apollo';
|
||||
import { Global, MiddlewareConsumer, Module } from '@nestjs/common';
|
||||
import { GraphQLModule } from '@nestjs/graphql';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { PothosModule } from '@smatch-corp/nestjs-pothos';
|
||||
import { PothosApolloDriver } from '@smatch-corp/nestjs-pothos-apollo-driver';
|
||||
import { Builder } from './graphql.builder';
|
||||
@@ -31,6 +32,7 @@ import { UploadedDocumentModule } from '../UploadedDocument/uploadeddocument.mod
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
PrismaModule,
|
||||
UserModule,
|
||||
CenterModule,
|
||||
@@ -60,6 +62,9 @@ import { UploadedDocumentModule } from '../UploadedDocument/uploadeddocument.mod
|
||||
}),
|
||||
GraphQLModule.forRoot<ApolloDriverConfig>({
|
||||
driver: PothosApolloDriver,
|
||||
path: process.env.API_PATH + '/graphql',
|
||||
playground: true,
|
||||
introspection: true,
|
||||
}),
|
||||
],
|
||||
providers: [
|
||||
@@ -80,6 +85,6 @@ export class GraphqlModule {
|
||||
configure(consumer: MiddlewareConsumer) {
|
||||
consumer
|
||||
.apply(GraphQLValidationMiddleware) // Apply the custom middleware
|
||||
.forRoutes('graphql'); // Ensure it only applies to the /graphql endpoint
|
||||
.forRoutes(process.env.API_PATH + '/graphql'); // Ensure it only applies to the /graphql endpoint
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common';
|
||||
@Injectable()
|
||||
export class RestfulService {
|
||||
getAllItems() {
|
||||
throw new Error('Method not implemented.');
|
||||
return 'Hello World';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { GraphqlModule } from './Graphql/graphql.module';
|
||||
import { ClerkModule } from './Clerk/clerk.module';
|
||||
import { RestfulModule } from './Restful/restful.module';
|
||||
|
||||
@Module({
|
||||
imports: [GraphqlModule, ClerkModule, RestfulModule],
|
||||
imports: [ConfigModule.forRoot(), GraphqlModule, ClerkModule, RestfulModule],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
@@ -13,6 +13,9 @@ async function bootstrap() {
|
||||
credentials: true,
|
||||
});
|
||||
|
||||
// set base path for api
|
||||
app.setGlobalPrefix(process.env.API_PATH ?? '/v1');
|
||||
|
||||
const config = new DocumentBuilder()
|
||||
.setTitle('EPESS API')
|
||||
.setDescription('API documentation for EPESS application')
|
||||
@@ -22,9 +25,13 @@ async function bootstrap() {
|
||||
|
||||
const document = SwaggerModule.createDocument(app, config);
|
||||
SwaggerModule.setup(process.env.SWAGGER_PATH ?? 'v1', app, document);
|
||||
console.log(process.env.API_PATH);
|
||||
|
||||
|
||||
document.paths['/graphql'] = {
|
||||
|
||||
document.paths[process.env.API_PATH + '/graphql'] = {
|
||||
get: {
|
||||
tags: ['GraphQL'],
|
||||
summary: 'GraphQL Playground',
|
||||
description:
|
||||
'Access the GraphQL Playground to interact with the GraphQL API.',
|
||||
|
||||
Reference in New Issue
Block a user