ci: attempt to fix ci scripts by not importing prisma as type

This commit is contained in:
Amruth Pillai
2023-11-24 01:48:14 +01:00
parent 12b52af121
commit a4843cf7e6
6 changed files with 28 additions and 7 deletions

View File

@ -8,7 +8,7 @@ import {
import { ConfigService } from "@nestjs/config"; import { ConfigService } from "@nestjs/config";
import { JwtService } from "@nestjs/jwt"; import { JwtService } from "@nestjs/jwt";
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library"; import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library";
import { AuthProvidersDto, LoginDto, RegisterDto } from "@reactive-resume/dto"; import { AuthProvidersDto, LoginDto, RegisterDto, UserWithSecrets } from "@reactive-resume/dto";
import { ErrorMessage } from "@reactive-resume/utils"; import { ErrorMessage } from "@reactive-resume/utils";
import * as bcryptjs from "bcryptjs"; import * as bcryptjs from "bcryptjs";
import { randomBytes } from "crypto"; import { randomBytes } from "crypto";
@ -110,7 +110,7 @@ export class AuthService {
// Do not `await` this function, otherwise the user will have to wait for the email to be sent before the response is returned // Do not `await` this function, otherwise the user will have to wait for the email to be sent before the response is returned
this.sendVerificationEmail(user.email); this.sendVerificationEmail(user.email);
return user; return user as UserWithSecrets;
} catch (error) { } catch (error) {
if (error instanceof PrismaClientKnownRequestError && error.code === "P2002") { if (error instanceof PrismaClientKnownRequestError && error.code === "P2002") {
throw new BadRequestException(ErrorMessage.UserAlreadyExists); throw new BadRequestException(ErrorMessage.UserAlreadyExists);
@ -341,6 +341,6 @@ export class AuthService {
secrets: { update: { twoFactorBackupCodes: backupCodes } }, secrets: { update: { twoFactorBackupCodes: backupCodes } },
}); });
return user; return user as UserWithSecrets;
} }
} }

View File

@ -12,7 +12,6 @@
"@swc/helpers": "~0.5.2", "@swc/helpers": "~0.5.2",
"nestjs-zod": "^3.0.0", "nestjs-zod": "^3.0.0",
"@reactive-resume/utils": "*", "@reactive-resume/utils": "*",
"@reactive-resume/schema": "*", "@reactive-resume/schema": "*"
"@prisma/client": "^5.4.2"
} }
} }

View File

@ -1,5 +1,6 @@
export * from "./auth"; export * from "./auth";
export * from "./contributors"; export * from "./contributors";
export * from "./resume"; export * from "./resume";
export * from "./secrets";
export * from "./statistics"; export * from "./statistics";
export * from "./user"; export * from "./user";

View File

@ -0,0 +1 @@
export * from "./secrets";

View File

@ -0,0 +1,17 @@
import { idSchema } from "@reactive-resume/schema";
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";
export const secretsSchema = z.object({
id: idSchema,
password: z.string().nullable(),
lastSignedIn: z.date().nullable(),
verificationToken: z.string().nullable(),
twoFactorSecret: z.string().nullable(),
twoFactorBackupCodes: z.array(z.string()).default([]),
refreshToken: z.string().nullable(),
resetToken: z.string().nullable(),
userId: idSchema,
});
export class SecretsDto extends createZodDto(secretsSchema) {}

View File

@ -1,8 +1,9 @@
import type { Prisma } from "@prisma/client";
import { idSchema } from "@reactive-resume/schema"; import { idSchema } from "@reactive-resume/schema";
import { createZodDto } from "nestjs-zod/dto"; import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z"; import { z } from "nestjs-zod/z";
import { secretsSchema } from "../secrets";
export const usernameSchema = z export const usernameSchema = z
.string() .string()
.min(3) .min(3)
@ -28,4 +29,6 @@ export const userSchema = z.object({
export class UserDto extends createZodDto(userSchema) {} export class UserDto extends createZodDto(userSchema) {}
export type UserWithSecrets = Prisma.UserGetPayload<{ include: { secrets: true } }>; export const userWithSecretsSchema = userSchema.merge(z.object({ secrets: secretsSchema }));
export class UserWithSecrets extends createZodDto(userWithSecretsSchema) {}