Skip to content

Commit

Permalink
Release 0.0.1 (#94)
Browse files Browse the repository at this point in the history
Co-authored-by: Jhonatan David <82552187+jotahdavid@users.noreply.github.com>
Co-authored-by: MatheusDubin <matheusdsilveira@gmail.com>
Co-authored-by: Gustavo Clemente <gusclms@gmail.com>
Co-authored-by: kelvinsb <kelvinbr11@gmail.com>
Co-authored-by: Tatiane <coelhotatiane2@gmail.com>
Co-authored-by: Sombrio <sombrio@sombrasoft.dev>
Co-authored-by: AlbuquerqueRafael <AlbuquerqueRafael@users.noreply.github.com>
Co-authored-by: José Fagundes <fagundesjg@outlook.com>
Co-authored-by: Arthur <40851238+4rthuurr@users.noreply.github.com>
Co-authored-by: Giovanni Bassi <334958+giggio@users.noreply.github.com>
Co-authored-by: LeoFC97 <leonardo.fc2@outlook.com>
Co-authored-by: Rogério Piatek <74259272+RogerioPiatek@users.noreply.github.com>
Co-authored-by: Anderson Rocha <59173445+AndersonCRocha@users.noreply.github.com>
Co-authored-by: Pedro Perrone <psperrone@hotmail.com>
  • Loading branch information
15 people authored May 14, 2024
1 parent 375418e commit 2954d7a
Show file tree
Hide file tree
Showing 18 changed files with 366 additions and 114 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI

on:
pull_request:
branches:
- master
- develop

jobs:
build:
runs-on: ubuntu-latest

steps:
# Check out the source
- name: Checkout Source
uses: actions/checkout@v4
# Setup node.js and cache
- name: "Setup node.js"
uses: actions/setup-node@v4
with:
node-version: "18.x"
cache: 'npm'
cache-dependency-path: ./package-lock.json
# Install dependencies
- name: Install dependencies
run: npm ci
# Lint App
- name: Lint App
run: npm run lint:ci
# Build App
- name: Build App
run: npm run build
24 changes: 24 additions & 0 deletions .github/workflows/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### 🔨 Tenho uma nova PR para vocês revisarem

- 🤔 O que foi feito?
> Digite aqui...

### 📗 Checklist do desenvolvedor

- [ ] Foi testado localmente?
- [ ] Foi adicionado documentação necessária (swagger, testes e etc)?

### 👀 Checklist do revisor

#### Revisor 1️⃣

- [ ] Você entendeu o propósito desse PR?
- [ ] Você entendeu o fluxo de negócio?
- [ ] Você entendeu o que e como foi desenvolvido tecnicamente a solução?
- [ ] Você analisou se os testes estão cobrindo a maioria dos casos?


### 🔗 Referênia

[Issue XX](https://github.com/SOS-RS/backend/issues/XX)
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM node:18.18 as node
FROM node:18.18-alpine as node

WORKDIR /usr/app

COPY package.json package-lock.json ./

RUN npm install
COPY . .
COPY . .
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# 🌊 Backend para App de Ajuda em Enchentes 🌊

Este repositório contém o backend de um aplicativo projetado para ajudar na organização e distribuição de suprimentos, bem como na coordenação de voluntários durante enchentes no Rio Grande do Sul. Ele fornece APIs essenciais para a autenticação de usuários, gerenciamento de abrigos e suprimentos, e muito mais.
Este repositório contém o backend de um aplicativo projetado para ajudar na organização e distribuição de suprimentos,
bem como na coordenação de voluntários durante enchentes no Rio Grande do Sul. Ele fornece APIs essenciais para a
autenticação de usuários, gerenciamento de abrigos e suprimentos, e muito mais.

Se você quiser discutir ideias, problemas ou contribuições, sinta-se à vontade para se juntar ao nosso servidor do
Discord [aqui](https://discord.gg/vjZS6BQXvM).

## 🛠 Tecnologias Utilizadas

Expand All @@ -12,7 +17,8 @@ Este repositório contém o backend de um aplicativo projetado para ajudar na or

## 🗂 Dump do Banco de Dados

Para iniciar com dados de exemplo, utilize o dump do banco disponível em `prisma/migration/dev_dump.sql`. Este arquivo pode ser executado após as migrations estarem aplicadas.
Para iniciar com dados de exemplo, utilize o dump do banco disponível em `prisma/migration/dev_dump.sql`. Este arquivo
pode ser executado após as migrations estarem aplicadas.

Se estiver usando Docker, os comandos para carregar o dump são:

Expand Down Expand Up @@ -96,6 +102,7 @@ ports:

## 🤝 Contribuição

Contribuições são muito bem-vindas! Se deseja ajudar, faça um fork do repositório, crie uma branch com suas modificações, e envie um pull request.
Contribuições são muito bem-vindas! Se deseja ajudar, faça um fork do repositório, crie uma branch com suas
modificações, e envie um pull request.

Sua ajuda é crucial para apoiar a comunidade afetada pelas enchentes no Rio Grande do Sul!
23 changes: 13 additions & 10 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,34 @@ version: '3.8'
services:
api:
container_name: sos-rs-api
image: node:18.18
image: node:18.18-alpine
restart: always
tty: true
depends_on:
- db
ports:
- '4000:4000'
- '${PORT}:${PORT}'
volumes:
- .:/usr/app
- /usr/app/node_modules
working_dir: '/usr/app'
environment:
- DB_HOST=sos-rs-db
- DB_PORT=5432
- DB_DATABASE_NAME=sos_rs
- DB_USER=root
- DB_PASSWORD=root
- DB_HOST=${DB_HOST}
- DB_PORT=${DB_PORT}
- DB_DATABASE_NAME=${DB_DATABASE_NAME}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- PORT=${PORT}
command: >
sh -c "npm install &&
npx prisma generate &&
npx prisma migrate dev &&
npm run start:dev"
npm run start:dev -- --preserveWatchOutput"
db:
container_name: sos-rs-db
image: postgres
ports:
- '${DB_PORT}:${DB_PORT}'
environment:
- POSTGRES_PASSWORD=root
- POSTGRES_USER=root
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_USER=${DB_USER}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"lint:ci": "eslint \"{src,apps,libs,test}/**/*.ts\" --format=stylish",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
Expand Down
6 changes: 6 additions & 0 deletions prisma/migrations/20240512005246_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- AlterTable
ALTER TABLE "shelters" ADD COLUMN "city" TEXT,
ADD COLUMN "neighbourhood" TEXT,
ADD COLUMN "street" TEXT,
ADD COLUMN "street_number" TEXT,
ADD COLUMN "zip_code" TEXT;
5 changes: 5 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ model Shelter {
name String @unique
pix String? @unique
address String
street String?
neighbourhood String?
city String?
streetNumber String? @map("street_number")
zipCode String? @map("zip_code")
petFriendly Boolean? @map("pet_friendly")
shelteredPeople Int? @map("sheltered_people")
capacity Int?
Expand Down
8 changes: 8 additions & 0 deletions src/decorators/UserDecorator/user.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createParamDecorator, ExecutionContext } from '@nestjs/common';

export const UserDecorator = createParamDecorator(
(data: unknown, ctx: ExecutionContext) => {
const request = ctx.switchToHttp().getRequest();
return request?.user;
},
);
10 changes: 10 additions & 0 deletions src/guards/apply-user.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';

@Injectable()
export class ApplyUser extends AuthGuard('jwt') {
handleRequest(err: any, user: any) {
if (user) return user;
return null;
}
}
38 changes: 25 additions & 13 deletions src/guards/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,34 @@ async function canActivate(context: ExecutionContext, allowed: AccessLevel[]) {
if (request.user) {
const { userId, sessionId } = request.user;

const session = await service.session.findUnique({
where: { id: sessionId, active: true, user: { id: userId } },
include: {
user: true,
},
});

if (
session &&
allowed.some((permission) => permission === session.user.accessLevel)
) {
return true;
}
return isRightSessionRole(allowed, sessionId, userId);
}

return false;
}

async function isRightSessionRole(
allowed: AccessLevel[],
sessionId?: string,
userId?: string,
) {
if (!sessionId) return false;
if (!userId) return false;

const session = await service.session.findUnique({
where: { id: sessionId, active: true, user: { id: userId } },
include: {
user: true,
},
});

if (
session &&
allowed.some((permission) => permission === session.user.accessLevel)
) {
return true;
}
return false;
}

export { canActivate };
Loading

0 comments on commit 2954d7a

Please sign in to comment.