build prod swagger types

This commit is contained in:
unurled 2025-02-14 17:14:07 +01:00
parent c09518de53
commit b73477e082
Signed by: unurled
GPG key ID: EFC5F5E709B47DDD
7 changed files with 68 additions and 51 deletions

View file

@ -24,8 +24,9 @@ import KeyvRedis from '@keyv/redis';
ScheduleModule.forRoot(),
CacheModule.registerAsync({
isGlobal: true,
// this Promise<any> is really nasty i don't like it at all
// eslint-disable-next-line @typescript-eslint/require-await
useFactory: async () => {
useFactory: async (): Promise<any> => {
return {
stores: [
process.env.REDIS_URL

View file

@ -15,6 +15,7 @@ import { ConsoleLogger, Logger } from '@nestjs/common';
import * as process from 'process';
import { FastifyReply } from 'fastify/types/reply';
import { FastifyRequest } from 'fastify/types/request';
import metadata from './metadata';
const logger: Logger = new Logger('App');
@ -74,7 +75,7 @@ async function loadServer(server: NestFastifyApplication) {
.setVersion(process.env.npm_package_version)
.addBearerAuth()
.build();
await SwaggerModule.loadPluginMetadata(metadata);
const document = SwaggerModule.createDocument(server, config);
const theme = new SwaggerTheme();
const customCss = theme.getBuffer(SwaggerThemeNameEnum.DARK);

9
src/metadata.ts Normal file
View file

@ -0,0 +1,9 @@
/* eslint-disable */
export default async () => {
const t = {
["./common/modules/auth/models/entities/user.entity"]: await import("./common/modules/auth/models/entities/user.entity"),
["./common/models/entities/version.entity"]: await import("./common/models/entities/version.entity"),
["./common/modules/auth/models/payloads/login.payload"]: await import("./common/modules/auth/models/payloads/login.payload")
};
return { "@nestjs/swagger": { "models": [[import("./common/models/entities/version.entity"), { "VersionEntity": { version: { required: true, type: () => String } } }], [import("./common/modules/auth/models/dto/register.dto"), { "RegisterDto": { email: { required: true, type: () => String }, username: { required: true, type: () => String }, password: { required: true, type: () => String } } }], [import("./common/modules/auth/models/entities/user.entity"), { "UserEntity": { id: { required: true, type: () => String }, email: { required: true, type: () => String }, username: { required: true, type: () => String }, createdAt: { required: true, type: () => Date }, updatedAt: { required: true, type: () => Date }, verified: { required: true, type: () => Boolean }, password: { required: true, type: () => String }, tokenId: { required: true, type: () => String } } }], [import("./common/modules/auth/models/payloads/login.payload"), { "LoginPayload": { user: { required: true, type: () => t["./common/modules/auth/models/entities/user.entity"].UserEntity }, token: { required: true, type: () => String } } }], [import("./common/modules/auth/models/dto/local-login.dto"), { "LocalLoginDto": { email: { required: true, type: () => String }, password: { required: true, type: () => String } } }], [import("./common/models/dto/pagination.dto"), { "PaginationDto": { take: { required: false, type: () => Number, minimum: 1 }, skip: { required: false, type: () => Number, minimum: 0 } } }], [import("./common/models/responses/pagination.response"), { "PaginationResponse": { data: { required: true }, total: { required: true, type: () => Number }, take: { required: true, type: () => Number }, skip: { required: true, type: () => Number } } }]], "controllers": [[import("./app.controller"), { "AppController": { "getVersion": { type: t["./common/models/entities/version.entity"].VersionEntity } } }], [import("./common/modules/auth/register.controller"), { "RegisterController": { "register": { status: 500, description: "Internal server error" } } }], [import("./common/modules/auth/login.controller"), { "LoginController": { "login": { status: 500, description: "Internal server error", type: t["./common/modules/auth/models/payloads/login.payload"].LoginPayload }, "loginCallback": { status: 500, description: "Internal server error", type: t["./common/modules/auth/models/payloads/login.payload"].LoginPayload } } }], [import("./common/modules/auth/auth.controller"), { "AuthController": { "logoutAll": {} } }], [import("./modules/users/users.controller"), { "UsersController": { "getMyself": { type: t["./common/modules/auth/models/entities/user.entity"].UserEntity } } }]] } };
};

View file

@ -11,16 +11,12 @@ export class UsersService {
where: {
id,
},
include: {
email_verifications: true,
},
});
if (!user) throw new NotFoundException('User not found');
return new UserEntity({
id: user.id,
username: user.username,
email: user.email,
verified: !user.email_verifications,
password: user.password,
tokenId: user.token_id,
createdAt: user.created_at,
@ -33,16 +29,12 @@ export class UsersService {
where: {
email,
},
include: {
email_verifications: true,
},
});
if (!user) throw new NotFoundException('User not found');
return new UserEntity({
id: user.id,
username: user.username,
email: user.email,
verified: !user.email_verifications,
password: user.password,
tokenId: user.token_id,
createdAt: user.created_at,