Skip to content

Commit

Permalink
ci: attempt to fix ci scripts by not importing prisma as type
Browse files Browse the repository at this point in the history
  • Loading branch information
AmruthPillai committed Nov 24, 2023
1 parent 12b52af commit a4843cf
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
6 changes: 3 additions & 3 deletions apps/server/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { ConfigService } from "@nestjs/config";
import { JwtService } from "@nestjs/jwt";
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 * as bcryptjs from "bcryptjs";
import { randomBytes } from "crypto";
Expand Down Expand Up @@ -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
this.sendVerificationEmail(user.email);

return user;
return user as UserWithSecrets;
} catch (error) {
if (error instanceof PrismaClientKnownRequestError && error.code === "P2002") {
throw new BadRequestException(ErrorMessage.UserAlreadyExists);
Expand Down Expand Up @@ -341,6 +341,6 @@ export class AuthService {
secrets: { update: { twoFactorBackupCodes: backupCodes } },
});

return user;
return user as UserWithSecrets;
}
}
3 changes: 1 addition & 2 deletions libs/dto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"@swc/helpers": "~0.5.2",
"nestjs-zod": "^3.0.0",
"@reactive-resume/utils": "*",
"@reactive-resume/schema": "*",
"@prisma/client": "^5.4.2"
"@reactive-resume/schema": "*"
}
}
1 change: 1 addition & 0 deletions libs/dto/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./auth";
export * from "./contributors";
export * from "./resume";
export * from "./secrets";
export * from "./statistics";
export * from "./user";
1 change: 1 addition & 0 deletions libs/dto/src/secrets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./secrets";
17 changes: 17 additions & 0 deletions libs/dto/src/secrets/secrets.ts
Original file line number Diff line number Diff line change
@@ -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) {}
7 changes: 5 additions & 2 deletions libs/dto/src/user/user.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Prisma } from "@prisma/client";
import { idSchema } from "@reactive-resume/schema";
import { createZodDto } from "nestjs-zod/dto";
import { z } from "nestjs-zod/z";

import { secretsSchema } from "../secrets";

export const usernameSchema = z
.string()
.min(3)
Expand All @@ -28,4 +29,6 @@ export const userSchema = z.object({

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) {}

0 comments on commit a4843cf

Please sign in to comment.