Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update config #12

Merged
merged 5 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"dependencies": {
"@nestjs/common": "10.0.0",
"@nestjs/config": "3.1.1",
"@nestjs/core": "10.0.0",
"@nestjs/platform-express": "10.0.0",
"@nestjs/swagger": "7.1.8",
Expand All @@ -36,6 +37,7 @@
"class-transformer": "0.5.1",
"class-validator": "0.14.0",
"email-templates": "file:src/modules/mail/templates/",
"helmet": "7.0.0",
"reflect-metadata": "0.1.13",
"resend": "1.0.0",
"rxjs": "7.8.1"
Expand Down
6 changes: 3 additions & 3 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Module } from '@nestjs/common';
import { PrismaModule } from './prisma/prisma.module';
import { AccountModule, MailModule } from './modules';

import { AccountModule } from './modules';

@Module({
imports: [PrismaModule, MailModule, AccountModule],
imports: [AccountModule],
})
export class AppModule {}
2 changes: 1 addition & 1 deletion src/globals/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const appLicense = process.env.npm_package_license;

export const fullnameRegExp = /^[a-zÀ-ÿ ]+$/i;
export const recoveryTokenRegExp = /^[a-zA-Z0-9_-]+$/;
export const dataExampleISO8601 = 'YYYY-MM-DDTHH:mm:ss.sssZ';
export const childrenBirthDateExample = '2009-02-28';

export const isDevelopmentEnv = () => process.env.NODE_ENV === 'development';
export const isHomologationEnv = () => process.env.NODE_ENV === 'homologation';
Expand Down
9 changes: 9 additions & 0 deletions src/globals/cors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';

const whitelist = [];

export const corsOptionsConfig: CorsOptions = {
origin: whitelist,
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type, Authorization'],
};
4 changes: 2 additions & 2 deletions src/globals/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from '@nestjs/common';
import { Prisma } from '@prisma/client';
import type { ValidationErrorMessagesProps } from './entity';
import { dataExampleISO8601, isDevelopmentEnv } from './constants';
import { isDevelopmentEnv } from './constants';

export const validationErrorMessages: ValidationErrorMessagesProps = {
emptyField: (args) => {
Expand Down Expand Up @@ -32,7 +32,7 @@ export const validationErrorMessages: ValidationErrorMessagesProps = {
return 'A senha deve conter no mínimo uma letra maiúscula, uma letra minúscula, um número, um símbolo e no mínimo 8 caracteres.';
},
birthDatePattern: () => {
return `A data de nascimento informada deve ter um formato ISO8601 e ser do tipo texto. ex: ${dataExampleISO8601}`;
return `A data de nascimento informada deve ser do tipo texto e ser neste formato: YYYY-MM-DD`;
},
genderPattern: (args) => {
return `O sexo deve ser [${args.constraints[1]}].`;
Expand Down
4 changes: 4 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { SwaggerModule } from '@nestjs/swagger';
import helmet from 'helmet';

import { swaggerDocumentConfig } from './globals/swagger';
import { corsOptionsConfig } from './globals/cors';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);

app.use(helmet());
app.enableCors(corsOptionsConfig);
app.useGlobalPipes(new ValidationPipe());

const document = SwaggerModule.createDocument(app, swaggerDocumentConfig);
Expand Down
9 changes: 6 additions & 3 deletions src/modules/account/account.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Genders } from '@prisma/client';
import {
fullnameRegExp,
recoveryTokenRegExp,
dataExampleISO8601,
childrenBirthDateExample,
} from 'src/globals/constants';
import { validationErrorMessages } from 'src/globals/errors';

Expand Down Expand Up @@ -48,9 +48,12 @@ export class CreateAccountDto {
@Matches(fullnameRegExp, { message: validationErrorMessages.fullnameField })
readonly childrenName: string;

@ApiProperty({ example: dataExampleISO8601 })
@ApiProperty({ example: childrenBirthDateExample })
@IsNotEmpty({ message: validationErrorMessages.emptyField })
@IsDateString({}, { message: validationErrorMessages.birthDatePattern })
@IsDateString(
{ strict: true },
{ message: validationErrorMessages.birthDatePattern },
)
readonly childrenBirthDate: Date;

@ApiProperty({ enum: Genders })
Expand Down
3 changes: 2 additions & 1 deletion src/modules/account/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class AccountService {
const hashedEmail = await this.hashData(input.email);
const encryptedPassword = await this.encryptPassword(input.password);
const now = new Date();
const childrenBirthDate = new Date(input.childrenBirthDate);

await this.accountRepository.saveCredentialParentAndChildrenProps({
credential: {
Expand All @@ -108,7 +109,7 @@ export class AccountService {
childrenProfile: {
fullname: input.childrenName,
gender: input.childrenGender,
birthdate: input.childrenBirthDate,
birthdate: childrenBirthDate,
},
});

Expand Down
24 changes: 22 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,16 @@
iterare "1.2.1"
tslib "2.5.3"

"@nestjs/[email protected]":
version "3.1.1"
resolved "https://registry.yarnpkg.com/@nestjs/config/-/config-3.1.1.tgz#51e23ed84debd08afb86acf7b92bc4bf341797da"
integrity sha512-qu5QlNiJdqQtOsnB6lx4JCXPQ96jkKUsOGd+JXfXwqJqZcOSAq6heNFg0opW4pq4J/VZoNwoo87TNnx9wthnqQ==
dependencies:
dotenv "16.3.1"
dotenv-expand "10.0.0"
lodash "4.17.21"
uuid "9.0.0"

"@nestjs/[email protected]":
version "10.0.0"
resolved "https://registry.yarnpkg.com/@nestjs/core/-/core-10.0.0.tgz#265147262c01ebec3f95cbaed7f9e5504e8a4faa"
Expand Down Expand Up @@ -2834,12 +2844,12 @@ [email protected]:
dotenv-expand "^10.0.0"
minimist "^1.2.6"

dotenv-expand@^10.0.0:
dotenv-expand@10.0.0, dotenv-expand@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37"
integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==

dotenv@^16.3.0:
dotenv@16.3.1, dotenv@^16.3.0:
version "16.3.1"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e"
integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==
Expand Down Expand Up @@ -3660,6 +3670,11 @@ has@^1.0.3:
dependencies:
function-bind "^1.1.1"

[email protected]:
version "7.0.0"
resolved "https://registry.yarnpkg.com/helmet/-/helmet-7.0.0.tgz#ac3011ba82fa2467f58075afa58a49427ba6212d"
integrity sha512-MsIgYmdBh460ZZ8cJC81q4XJknjG567wzEmv46WOBblDb6TUd3z8/GhgmsM9pn8g2B80tAJ4m5/d3Bi1KrSUBQ==

hexoid@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/hexoid/-/hexoid-1.0.0.tgz#ad10c6573fb907de23d9ec63a711267d9dc9bc18"
Expand Down Expand Up @@ -6416,6 +6431,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==

[email protected]:
version "9.0.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"
integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==

v8-compile-cache-lib@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"
Expand Down
Loading