Skip to content

Commit

Permalink
Merge pull request #48 from GoLembrar/feat-add-husky
Browse files Browse the repository at this point in the history
Husky, Migrations
  • Loading branch information
Rip4568 committed Jun 25, 2024
2 parents a5a9e1c + fd1a3ef commit b4300df
Show file tree
Hide file tree
Showing 25 changed files with 79 additions and 215 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ lerna-debug.log*
!.vscode/launch.json
!.vscode/extensions.json

.docker
.docker
.vercel
3 changes: 3 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
npm run lint
npm run format
git add
42 changes: 0 additions & 42 deletions .netlify/netlify.toml

This file was deleted.

20 changes: 0 additions & 20 deletions .netlify/state.json

This file was deleted.

1 change: 0 additions & 1 deletion http/user-requests.http
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Content-Type: application/json

{
"email" : "[email protected]",
"phone" : "19987851009",
"name" : "jhone",
"password" : "senhaForte"
}
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
"postinstall": "prisma generate && prisma db push",
"prisma-dev": "prisma generate && prisma db push",
"prisma-studio": "prisma studio",
"prisma-migrate": "prisma migrate dev",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:worker": "ts-node ./consumer-queue-email/worker.ts",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"start:prod": "node dist/src/main.js",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "vitest run",
"test:watch": "vitest",
Expand All @@ -25,7 +26,8 @@
"test:html": "vitest run --reporter=html --outputFile=vitest/output/html/index.html",
"test:json": "vitest run --reporter=json",
"test:junit": "vitest run --reporter=junit",
"test:ui": "vite preview --outDir vitest/output/html --host"
"test:ui": "vite preview --outDir vitest/output/html --host",
"prepare": "husky"
},
"dependencies": {
"@nestjs-modules/mailer": "^2.0.2",
Expand Down Expand Up @@ -76,6 +78,7 @@
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"husky": "^9.0.11",
"prettier": "^3.0.0",
"prisma": "^5.12.1",
"source-map-support": "^0.5.21",
Expand Down
11 changes: 11 additions & 0 deletions prisma/migrations/20240625163930_remove_phone/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Warnings:
- You are about to drop the column `phone` on the `Users` table. All the data in the column will be lost.
*/
-- DropIndex
DROP INDEX "Users_phone_key";

-- AlterTable
ALTER TABLE "Users" DROP COLUMN "phone";
1 change: 0 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ model Users {
id String @id @default(uuid())
email String @unique @db.VarChar(128)
password String @db.VarChar(128)
phone String @unique @db.VarChar(64)
name String? @db.VarChar(255)
reminder Reminders[]
usersToReminder UsersToReminder[]
Expand Down
22 changes: 0 additions & 22 deletions src/app.controller.spec.ts

This file was deleted.

10 changes: 4 additions & 6 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { Controller, Get, Res } from '@nestjs/common';
import { Response } from 'express';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
getHello(): string {
return this.appService.getHello();
redirectToDocs(@Res() response: Response) {
response.redirect('/docs');
}
}
25 changes: 12 additions & 13 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { CacheModule } from '@nestjs/cache-manager';
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { PrismaService } from './prisma/prisma.service';
import { AuthModule } from './auth/auth.module';
import { ConfigModule } from '@nestjs/config';
import { ReminderModule } from './reminder/reminder.module';
import { CategoryModule } from './category/category.module';
import { ScheduleModule } from '@nestjs/schedule';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
import { RabbitmqModule } from './rabbitmq/rabbitmq.module';
import { EmailModule } from '../consumer-queue-email/email/email.module';
import { AppController } from './app.controller';
import { AuthModule } from './auth/auth.module';
import { CacheService } from './cache/cache.service';
import { CategoryModule } from './category/category.module';
import { ContactModule } from './contact/contact.module';
import { ScheduleModule } from '@nestjs/schedule';
import { TasksService } from './tasks/tasks.service';
import { EmailScheduledModule } from './email/email.module';
import { PrismaService } from './prisma/prisma.service';
import { RabbitmqModule } from './rabbitmq/rabbitmq.module';
import { ReminderModule } from './reminder/reminder.module';
import { TasksModule } from './tasks/tasks.module';
import { CacheModule } from '@nestjs/cache-manager';
import { CacheService } from './cache/cache.service';
import { TasksService } from './tasks/tasks.service';
import { UserModule } from './user/user.module';

@Module({
imports: [
Expand All @@ -41,6 +40,6 @@ import { CacheService } from './cache/cache.service';
}),
],
controllers: [AppController],
providers: [AppService, PrismaService, TasksService, CacheService],
providers: [PrismaService, TasksService, CacheService],
})
export class AppModule {}
8 changes: 0 additions & 8 deletions src/app.service.ts

This file was deleted.

9 changes: 4 additions & 5 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { CredentialsDto } from './dto/credentials.dto';
import { PrismaService } from '../prisma/prisma.service';
import { HashUtil } from '../common/utils/hashUtil';
import { Users } from '@prisma/client';
import { JwtService } from '@nestjs/jwt';
import { Users } from '@prisma/client';
import { HashUtil } from '../common/utils/hashUtil';
import { PrismaService } from '../prisma/prisma.service';
import { CredentialsDto } from './dto/credentials.dto';
import { JwtPayload } from './interfaces/jwt-payload.interface';

@Injectable()
Expand Down Expand Up @@ -34,7 +34,6 @@ export class AuthService {
id: foundUser.id,
email: foundUser.email,
name: foundUser.name,
phone: foundUser.phone,
};

const token = this.jwt.sign(jwtPayloadData);
Expand Down
1 change: 0 additions & 1 deletion src/auth/interfaces/jwt-payload.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export interface JwtPayload {
id: string;
email: string;
name: string;
phone: string;
}
54 changes: 10 additions & 44 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import { Logger, ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app.module';
import { Logger, ValidationPipe } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { createWriteStream } from 'fs';
import { get } from 'https';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors({
origin: '*',
methods: ['GET', 'HEAD', 'POST', 'PATCH', 'DELETE'],
});

const config = new DocumentBuilder()
.addBearerAuth()
.setTitle('Go lembrar API')
.setDescription('GO Lembrar é uma aplicação para gerenciar lembretes.')
.setVersion('1.0')
.setTitle('Go Lembrar API')
.setDescription('O APP de lembretes que você recebe no seu WhatsApp.')
.setVersion('0.1')
.build();

const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('docs', app, document);
SwaggerModule.setup('docs', app, document, {
customSiteTitle: 'Go Lembrar',
});

app.useGlobalPipes(new ValidationPipe());

Expand All @@ -28,42 +30,6 @@ async function bootstrap() {
const logger = new Logger(bootstrap.name);
logger.log('Server listening on ' + port);
});

const serverUrl = 'https://api-golembrar.vercel.app';

// write swagger ui files
get(`${serverUrl}/swagger/swagger-ui-bundle.js`, function (response) {
response.pipe(createWriteStream('swagger-static/swagger-ui-bundle.js'));
console.log(
`Swagger UI bundle file written to: '/swagger-static/swagger-ui-bundle.js'`,
);
});

get(`${serverUrl}/swagger/swagger-ui-init.js`, function (response) {
response.pipe(createWriteStream('swagger-static/swagger-ui-init.js'));
console.log(
`Swagger UI init file written to: '/swagger-static/swagger-ui-init.js'`,
);
});

get(
`${serverUrl}/swagger/swagger-ui-standalone-preset.js`,
function (response) {
response.pipe(
createWriteStream('swagger-static/swagger-ui-standalone-preset.js'),
);
console.log(
`Swagger UI standalone preset file written to: '/swagger-static/swagger-ui-standalone-preset.js'`,
);
},
);

get(`${serverUrl}/swagger/swagger-ui.css`, function (response) {
response.pipe(createWriteStream('swagger-static/swagger-ui.css'));
console.log(
`Swagger UI css file written to: '/swagger-static/swagger-ui.css'`,
);
});
}

bootstrap();
7 changes: 0 additions & 7 deletions src/user/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import {
IsEmail,
IsMobilePhone,
IsNotEmpty,
IsString,
IsStrongPassword,
Expand All @@ -21,12 +20,6 @@ export class CreateUserDto {
@ApiProperty({ example: '[email protected]' })
email: string;

@IsNotEmpty()
@IsString()
@IsMobilePhone('pt-BR')
@ApiProperty({ example: '999999999' })
phone: string;

@IsNotEmpty()
name: string;
}
3 changes: 0 additions & 3 deletions src/user/swagger/okResponseModel.swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ export class okResponseModel {
@ApiProperty()
email: string;

@ApiProperty()
phone: string;

@ApiProperty()
createdAt: string;

Expand Down
Loading

0 comments on commit b4300df

Please sign in to comment.