-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from RoutinelyOrganization/develop
Sync
- Loading branch information
Showing
19 changed files
with
287 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,7 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { PrismaModule } from './prisma/prisma.module'; | ||
import { | ||
AccountModule, | ||
SessionModule, | ||
PasswordTokenModule, | ||
MailingModule, | ||
TaskModule, | ||
GoalModule, | ||
} from './modules'; | ||
import { AccountModule, TaskModule, GoalModule } from './modules'; | ||
|
||
@Module({ | ||
imports: [ | ||
PrismaModule, | ||
AccountModule, | ||
SessionModule, | ||
PasswordTokenModule, | ||
MailingModule, | ||
TaskModule, | ||
GoalModule, | ||
], | ||
imports: [AccountModule, TaskModule, GoalModule], | ||
}) | ||
export class AppModule {} |
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,84 @@ | ||
import { HttpException } from '@nestjs/common'; | ||
|
||
type iCustomException = { | ||
property?: string | undefined; | ||
message?: string | undefined; | ||
}; | ||
|
||
export class CustomException extends HttpException { | ||
constructor(message: string, status = 500, property?: string) { | ||
super( | ||
{ | ||
errors: [ | ||
{ | ||
property, | ||
message, | ||
}, | ||
], | ||
}, | ||
status | ||
); | ||
} | ||
} | ||
|
||
// 400 | ||
export class DataValidationError extends CustomException { | ||
constructor(props: iCustomException) { | ||
super(props.message || 'Erro em um dado', 400, props.property); | ||
} | ||
} | ||
|
||
// 401 | ||
export class AuthorizationError extends CustomException { | ||
constructor(props: iCustomException) { | ||
super(props.message || 'Credenciais inválidas', 401, props.property); | ||
} | ||
} | ||
|
||
// 403 | ||
export class PermissionError extends CustomException { | ||
constructor(props: iCustomException) { | ||
super( | ||
props.message || 'Você não tem permissão para executar esta ação', | ||
403, | ||
props.property | ||
); | ||
} | ||
} | ||
|
||
// 404 | ||
export class NotFoundError extends CustomException { | ||
constructor(props: iCustomException) { | ||
super(props.message || 'Informação não encontrada', 404, props.property); | ||
} | ||
} | ||
|
||
// 422 | ||
export class UnprocessableEntityError extends CustomException { | ||
constructor(props: iCustomException) { | ||
super( | ||
props.message || 'Você não tem permissão alterar esta informação', | ||
422, | ||
props.property | ||
); | ||
} | ||
} | ||
|
||
// 429 | ||
export class RatelimitError extends CustomException { | ||
constructor(props: iCustomException) { | ||
super( | ||
props.message || | ||
'Muitas requisições em um curto período, aguarde e tente novamente mais tarde', | ||
429, | ||
props.property | ||
); | ||
} | ||
} | ||
|
||
// 500 | ||
export class InternalServerError extends CustomException { | ||
constructor(props: iCustomException) { | ||
super(props.message || 'Erro desconhecido', 500); | ||
} | ||
} |
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,44 @@ | ||
import type { iValidationResponses } from './types'; | ||
|
||
export const responses: iValidationResponses = { | ||
notEmpty: 'Não pode estar vazio', | ||
boolean: 'Deve ser verdadeiro ou falso (true | false)', | ||
string: 'Deve ser um texto', | ||
arrayOfString: 'Deve ser uma lista de textos', | ||
number: 'Deve ser um número', | ||
integer: 'Deve ser um número inteiro', | ||
enum(validationArguments) { | ||
const enums = validationArguments.constraints[1]; | ||
return `Deve ser um texto entre essas opções: ${enums}`; | ||
}, | ||
arrayMinSize(validationArguments) { | ||
const min = validationArguments.constraints[0]; | ||
return `Deve ter no mínimo ${min} item(ns)`; | ||
}, | ||
arrayMaxSize(validationArguments) { | ||
const max = validationArguments.constraints[0]; | ||
return `Deve ter no máximo ${max} item(ns)`; | ||
}, | ||
minLength(validationArguments) { | ||
const min = validationArguments.constraints[0]; | ||
return `Deve ter no mínimo ${min} caracteres`; | ||
}, | ||
maxLength(validationArguments) { | ||
const max = validationArguments.constraints[0]; | ||
return `Deve ter no máximo ${max} caracteres`; | ||
}, | ||
minValue(validationArguments) { | ||
const min = validationArguments.constraints[0]; | ||
return `O valor mínimo deve ser ${min}`; | ||
}, | ||
maxValue(validationArguments) { | ||
const max = validationArguments.constraints[0]; | ||
return `O valor máximo deve ser ${max}`; | ||
}, | ||
email: 'O e-mail deve ter um formato válido', | ||
strongPassword: | ||
'Deve conter no mínimo 6 caracteres com uma letra maiúscula, uma letra minúscula, um número e um símbolo', | ||
fullname: 'Deve conter apenas letras e espaço em branco entre palavras', | ||
datePattern: 'Deve ser um texto nesse padrão, YYYY-MM-DD', | ||
dateRange: 'O mês e o dia devem ser válidos', | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ValidationOptions } from 'class-validator'; | ||
|
||
type iValidator = ValidationOptions['message'] | string; | ||
|
||
export type iValidationResponses = { | ||
notEmpty: iValidator; | ||
boolean: iValidator; | ||
string: iValidator; | ||
arrayOfString: iValidator; | ||
number: iValidator; | ||
integer: iValidator; | ||
enum: iValidator; | ||
arrayMinSize: iValidator; | ||
arrayMaxSize: iValidator; | ||
minLength: iValidator; | ||
maxLength: iValidator; | ||
minValue: iValidator; | ||
maxValue: iValidator; | ||
email: iValidator; | ||
strongPassword: iValidator; | ||
fullname: iValidator; | ||
datePattern: iValidator; | ||
dateRange: iValidator; | ||
}; |
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,18 @@ | ||
import { | ||
BadRequestException, | ||
ValidationPipe, | ||
ValidationPipeOptions, | ||
} from '@nestjs/common'; | ||
|
||
const config: ValidationPipeOptions = { | ||
exceptionFactory(errors) { | ||
const formated = errors.map((error) => ({ | ||
property: error.property, | ||
message: error.constraints[Object.keys(error.constraints)[0]], | ||
})); | ||
|
||
return new BadRequestException({ errors: formated }); | ||
}, | ||
}; | ||
|
||
export default new ValidationPipe(config); |
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,13 +1,13 @@ | ||
export class AccountNotFoundError extends Error { | ||
constructor() { | ||
super('Account does not exists'); | ||
super('A conta não existe'); | ||
this.name = 'AccountNotFoundError'; | ||
} | ||
} | ||
|
||
export class InvalidCodeError extends Error { | ||
constructor() { | ||
super('Invalid code'); | ||
super('Código inválido'); | ||
this.name = 'InvalidCodeError'; | ||
} | ||
} |
Oops, something went wrong.