2024-12-06 00:15:40 +00:00
|
|
|
import {
|
|
|
|
ClassSerializerInterceptor,
|
|
|
|
HttpStatus,
|
|
|
|
ValidationPipe,
|
|
|
|
} from "@nestjs/common";
|
2024-12-03 16:35:11 +00:00
|
|
|
import { HttpAdapterHost, NestFactory, Reflector } from "@nestjs/core";
|
2024-12-02 14:25:36 +00:00
|
|
|
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
|
2024-12-03 16:35:11 +00:00
|
|
|
import { PrismaClientExceptionFilter } from "nestjs-prisma";
|
2024-11-23 00:37:22 +00:00
|
|
|
import { AppModule } from "./app.module";
|
|
|
|
|
|
|
|
async function bootstrap() {
|
2024-11-28 14:25:01 +00:00
|
|
|
const app = await NestFactory.create(AppModule);
|
2024-11-25 21:55:25 +00:00
|
|
|
|
2024-11-24 01:34:20 +00:00
|
|
|
app.enableCors({
|
2024-11-25 21:55:25 +00:00
|
|
|
origin: "*",
|
2024-11-24 01:34:20 +00:00
|
|
|
});
|
2024-11-25 21:55:25 +00:00
|
|
|
|
2024-12-03 16:35:11 +00:00
|
|
|
const { httpAdapter } = app.get(HttpAdapterHost);
|
|
|
|
app.useGlobalFilters(
|
|
|
|
new PrismaClientExceptionFilter(httpAdapter, {
|
|
|
|
P2000: {
|
|
|
|
errorMessage: "A required field is missing",
|
2024-12-06 00:15:40 +00:00
|
|
|
statusCode: HttpStatus.BAD_REQUEST,
|
2024-12-03 16:35:11 +00:00
|
|
|
},
|
|
|
|
P2002: {
|
2024-12-06 00:15:40 +00:00
|
|
|
errorMessage:
|
|
|
|
"A ressource with the same unique fields already exists",
|
|
|
|
statusCode: HttpStatus.CONFLICT,
|
2024-12-03 16:35:11 +00:00
|
|
|
},
|
|
|
|
P2025: {
|
|
|
|
errorMessage: "The requested ressource does not exist",
|
2024-12-06 00:15:40 +00:00
|
|
|
statusCode: HttpStatus.NOT_FOUND,
|
|
|
|
},
|
2024-12-03 16:35:11 +00:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
2024-11-28 14:53:38 +00:00
|
|
|
app.useGlobalPipes(new ValidationPipe());
|
|
|
|
|
2024-12-02 14:25:36 +00:00
|
|
|
app.useGlobalInterceptors(
|
|
|
|
new ClassSerializerInterceptor(app.get(Reflector), {
|
|
|
|
excludeExtraneousValues: true,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
const config = new DocumentBuilder()
|
|
|
|
.setTitle("Toogether API")
|
|
|
|
.addBearerAuth()
|
|
|
|
.build();
|
|
|
|
const documentFactory = () => SwaggerModule.createDocument(app, config);
|
|
|
|
SwaggerModule.setup("documentation", app, documentFactory, {
|
|
|
|
swaggerOptions: {
|
|
|
|
tryItOutEnabled: true,
|
|
|
|
persistAuthorization: true,
|
2024-12-02 15:55:44 +00:00
|
|
|
},
|
2024-12-02 14:25:36 +00:00
|
|
|
});
|
2024-12-02 12:57:47 +00:00
|
|
|
|
2024-11-25 21:55:25 +00:00
|
|
|
await app.listen(process.env.PORT ?? 3000, "0.0.0.0");
|
2024-11-23 00:37:22 +00:00
|
|
|
}
|
|
|
|
bootstrap();
|