-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: adjusted endpoint users * refactor: reverting the last commit in validation errors * feat: remove space * refactor: test and implemented repo findByEmail
- Loading branch information
Showing
9 changed files
with
114 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
import { z } from 'zod'; | ||
|
||
const regex = /^(?=.*[A-Z])(?=.*[!#$&*@])(?=.*[\dA-Za-z]).{8,}$/; | ||
const passwordMessage = | ||
'Password must contain at least 1 uppercase letter, 1 special character, and be at least 8 characters long.'; | ||
|
||
export const userCreateBodySchema = z.object({ | ||
email: z.string().email(), | ||
name: z.string().min(3), | ||
password: z | ||
.string() | ||
.regex( | ||
/^(?=.*[A-Z])(?=.*[!#$&*@])(?=.*[\dA-Za-z]).{8,}$/, | ||
'Password must contain at least 1 uppercase letter, 1 special character, and be at least 8 characters long.' | ||
), | ||
password: z.string().regex(regex, passwordMessage), | ||
|
||
repeatPassword: z | ||
.string() | ||
.regex( | ||
/^(?=.*[A-Z])(?=.*[!#$&*@])(?=.*[\dA-Za-z]).{8,}$/, | ||
'Password must contain at least 1 uppercase letter, 1 special character, and be at least 8 characters long.' | ||
), | ||
repeatPassword: z.string().regex(regex, passwordMessage), | ||
username: z.string().min(3), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library'; | ||
import type { PrismaClientKnownRequestError } from '@prisma/client/runtime/library'; | ||
import type { NextFunction, Response } from 'express'; | ||
|
||
import { ConflictError } from '@/shared/errors/conflict-error'; | ||
import { HttpStatusCode } from '../protocols/http-client'; | ||
|
||
export function prismaErrorHandler(error: unknown) { | ||
if (error instanceof PrismaClientKnownRequestError) { | ||
switch (error.code) { | ||
case 'P2002': { | ||
throw new ConflictError( | ||
'There is already a user with this email or username' | ||
); | ||
} | ||
export function prismaErrorHandler( | ||
error: PrismaClientKnownRequestError, | ||
res: Response, | ||
_: NextFunction | ||
) { | ||
switch (error.code) { | ||
case 'P2002': { | ||
res.status(HttpStatusCode.badRequest).send({ | ||
message: 'There is already a user with this email or username', | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { vi } from 'vitest'; | ||
|
||
export const bcryptAdapteMock = { | ||
compare: vi.fn(), | ||
encrypt: vi.fn(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters