Skip to content

Commit

Permalink
Merge branch 'main' into unitytest
Browse files Browse the repository at this point in the history
  • Loading branch information
Matheusafonsouza committed Jan 10, 2025
2 parents 8af45fe + fca369f commit d0fe4cb
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 19 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.eslintrc.js
src/database/migrations/
38 changes: 38 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CD
on:
push:
branches:
- main
jobs:
migrate:
runs-on: ubuntu-latest
env:
DB_PORT: ${{ secrets.LIVRO_LIVRE_DB_PORT }}
DB_HOST: ${{ secrets.LIVRO_LIVRE_DB_HOST }}
DB_USER: ${{ secrets.LIVRO_LIVRE_DB_USER }}
DB_PASSWORD: ${{ secrets.LIVRO_LIVRE_DB_PASSWORD }}
DB_NAME: ${{ secrets.LIVRO_LIVRE_DB_NAME }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install dependencies
run: |
npm install
- name: Run migrations
run: |
npm run migration:run
build:
needs: migrate
runs-on: ubuntu-latest # Setup an environment to run the action
steps:
- uses: actions/checkout@v2 # This actions copy the repository on the environment
- name: Install Heroku CLI
run: |
curl https://cli-assets.heroku.com/install.sh | sh
- uses: akhileshns/[email protected] # This action deploys the content on Heroku
with:
heroku_api_key: ${{secrets.LIVRO_LIVRE_HEROKU_API_KEY}} #The Heroku api key we stored on our repo secret
heroku_app_name: "livro-livre-users" #The name of your heroku app - Must be unique in Heroku
heroku_email: "[email protected]" #Your heroku yuser name
usedocker: true
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
sonarcloud:
name: Lint
run:
name: CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install dependencies
run: npm install
- name: Test and coverage
- name: Run lint
run: npm run lint
- name: Run tests
run: npm run test
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY . .
RUN npm run build

# Expose the port the app will listen on
EXPOSE 80
EXPOSE 3000

# Define the command to start the app
Expand Down
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

3 changes: 3 additions & 0 deletions heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
docker:
web: Dockerfile
2 changes: 1 addition & 1 deletion src/auth/roles.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SetMetadata } from '@nestjs/common';
import { UserRoles } from 'src/database/entities/user.entity';
import { UserRoles } from '../database/entities/user.entity';

export const Roles = (...roles: UserRoles[]) => SetMetadata('roles', roles);
7 changes: 5 additions & 2 deletions src/auth/roles.guard.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { UserRoles } from 'src/database/entities/user.entity';
import { UserRoles } from '../database/entities/user.entity';

@Injectable()
export class RolesGuard implements CanActivate {
constructor(private reflector: Reflector) {}

canActivate(context: ExecutionContext): boolean {
const requiredRoles = this.reflector.get<UserRoles[]>('roles', context.getHandler());
const requiredRoles = this.reflector.get<UserRoles[]>(
'roles',
context.getHandler(),
);
if (!requiredRoles) {
return true;
}
Expand Down
19 changes: 10 additions & 9 deletions src/database/migrations/1736291880582-create-users.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { MigrationInterface, QueryRunner } from 'typeorm';

export class CreateUsers1736291880582 implements MigrationInterface {
name = 'CreateUsers1736291880582'
name = 'CreateUsers1736291880582';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "user" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "firstName" character varying NOT NULL, "lastName" character varying NOT NULL, "password" character varying NOT NULL, "email" character varying NOT NULL, "phone" character varying NOT NULL, "role" character varying NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "user"`);
}
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "user" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "firstName" character varying NOT NULL, "lastName" character varying NOT NULL, "password" character varying NOT NULL, "email" character varying NOT NULL, "phone" character varying NOT NULL, "role" character varying NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "user"`);
}
}
6 changes: 3 additions & 3 deletions src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
} from '@nestjs/common';
import { UpdateUserDto } from './dtos/updateUser.dto';
import { AuthGuard } from '../auth/auth.guard';
import { Roles } from 'src/auth/roles.decorator';
import { UserRoles } from 'src/database/entities/user.entity';
import { RolesGuard } from 'src/auth/roles.guard';
import { Roles } from '../auth/roles.decorator';
import { UserRoles } from '../database/entities/user.entity';
import { RolesGuard } from '../auth/roles.guard';

@Controller('users')
export class UsersController {
Expand Down

0 comments on commit d0fe4cb

Please sign in to comment.