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

Feat: added supporters module and create partner endpoint #132

Merged
merged 72 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
86768c9
feat(shelter-supply): add quantity property
jotahdavid May 10, 2024
b2550ee
feat(shelter-supply): show quantity property at query results
jotahdavid May 10, 2024
6a2694c
fix: removed unintended filter
MatheusDubin May 10, 2024
c117ab0
feat: improve readme file
filipepacheco May 10, 2024
7185fc8
feat: improve readme file
filipepacheco May 10, 2024
79f27fd
Bug fix: added verified field to the query
gustavocs May 10, 2024
4268e47
fix: verified was required on create shelter controller
kelvinsb May 10, 2024
dff6aad
feat: improve readme file
filipepacheco May 10, 2024
f61f86a
Fix linter issues
coelhotatiane May 10, 2024
3f787a5
feat(shelter-supply): set quantity to null if priority is UnderControl
jotahdavid May 10, 2024
e8bb18e
Implement some quality of life updates reg Docker
coelhotatiane May 10, 2024
d005c61
created lint:ci script
sombraSoft May 10, 2024
945296c
created CI job
sombraSoft May 10, 2024
317102a
fix linting in files
sombraSoft May 10, 2024
c887732
fixed ci job
sombraSoft May 10, 2024
18d631a
simplify ci job
sombraSoft May 10, 2024
cbf8971
fixed comment
sombraSoft May 10, 2024
36c7618
fixed lint script
sombraSoft May 10, 2024
8ac3e12
Merge branch 'develop' into feat/improve-readme-file
filipepacheco May 10, 2024
890b826
Merge pull request #29 from jotahdavid/feat/supply-quantity
AlbuquerqueRafael May 10, 2024
a88ed0a
Merge pull request #39 from SOS-RS/feat/improve-readme-file
filipepacheco May 10, 2024
8d050ac
Merge pull request #41 from coelhotatiane/quality-of-life-linter
AlbuquerqueRafael May 10, 2024
847252c
wip: search
fagundesjg May 10, 2024
520cdc5
refact: index search
fagundesjg May 10, 2024
ed08016
fix: fixed shelter OR and AND conditions
fagundesjg May 10, 2024
d9e6ed9
wip: donation tags
fagundesjg May 10, 2024
38c41ac
wip
fagundesjg May 10, 2024
0501b61
fix: parse tag response in shelter index
fagundesjg May 10, 2024
d0532d7
fix: qtd of shelter supplies tagged
fagundesjg May 10, 2024
794c7b8
fix: migration issue
fagundesjg May 10, 2024
2ccf427
wip
fagundesjg May 11, 2024
0248869
feat: update many supplies
fagundesjg May 11, 2024
caf62ea
wip
fagundesjg May 11, 2024
f2f112f
feat: created admin user role
fagundesjg May 11, 2024
cd27183
Fix/develop bugs (#54)
fagundesjg May 11, 2024
15a99b2
README.md 2.0 (#52)
4rthuurr May 11, 2024
057dde0
Add license (#50)
giggio May 11, 2024
0879745
Merge branch 'fix/develop-bugs' into develop
fagundesjg May 11, 2024
e4e9de2
Merge branch 'main' into develop
fagundesjg May 11, 2024
3732db7
docs: add templeate for PR
LeoFC97 May 11, 2024
dc37d79
Merge branch 'develop' into tooling/ci-improvement
sombraSoft May 11, 2024
18afdf7
rebase
sombraSoft May 11, 2024
cf2e38e
Merge pull request #42 from coelhotatiane/quality-of-life-docker
filipepacheco May 11, 2024
7abcf8e
Merge pull request #48 from sombraSoft/tooling/ci-improvement
filipepacheco May 11, 2024
b12e063
hotfix: Correção da Atualização Inconsistente de Prioridade em Shelte…
fagundesjg May 11, 2024
9f5fabc
feat: only show contact on shelter public routes on authorized roles
kelvinsb May 11, 2024
13d65ba
fix: remove unused and unauthorized contact field on list route
kelvinsb May 11, 2024
5d216b0
docs: improve readme file with discord link
RogerioPiatek May 12, 2024
8db01be
feat: return contact when user logged, instead of some Roles
kelvinsb May 12, 2024
ecdf8f4
fix: suggestions about separation
kelvinsb May 13, 2024
c9d0ec1
docs: updated to the link 'discord.gg/sosrs'
RogerioPiatek May 13, 2024
8ee010e
docs: changed discord link position
filipepacheco May 13, 2024
7a35052
Merge pull request #83 from RogerioPiatek/docs/improve-readme-file
filipepacheco May 13, 2024
873554c
Merge pull request #59 from LeoFC97/docs/add-pr-template
filipepacheco May 13, 2024
43561bf
Merge pull request #77 from kelvinsb/feat/hide-contact-for-unauthorized
filipepacheco May 13, 2024
9362f4c
Criação do endpoint para busca de cidades dos abrigos (#82)
AndersonCRocha May 13, 2024
b24a7b7
feat: add shelter filter by geolocation radius (#93)
AndersonCRocha May 14, 2024
c40e724
Fixing discord link on Readme (#95)
filipepacheco May 14, 2024
56928dc
feat: added default updated at in new shelter to avoid null field in …
fagundesjg May 14, 2024
43384ca
hotfix: login issue
fagundesjg May 14, 2024
a88475b
Fix tests (#78)
giggio May 14, 2024
fbf116f
feat: added partners endpoint (#106)
fagundesjg May 15, 2024
e8e5798
fix: Correção da issue #146 do frontend. (#105)
kevinpiske May 15, 2024
6da2ab5
feat: Add description and including a bearer token in swagger in user…
w-araujo May 15, 2024
718a620
fix: city filter (#116)
fagundesjg May 15, 2024
42fff38
hotfix: fixed update shelter prioritySum when use update many supplies
fagundesjg May 15, 2024
37e4d6a
feat: added stg and development actions
fagundesjg May 16, 2024
d4b1e35
hotfix: start:prod command
fagundesjg May 16, 2024
0321963
wip
fagundesjg May 16, 2024
3de7c29
Merge branch 'staging'
fagundesjg May 16, 2024
d4a98b5
fix: supporters module tests
fagundesjg May 17, 2024
7a9aea7
Merge branch 'develop' into staging
fagundesjg May 17, 2024
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
34 changes: 34 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Deploy Backend in Development Enviroment

on:
push:
branches: [develop]

jobs:
build:
runs-on: dev

steps:
- uses: actions/checkout@v4

- name: Create .env file
run: |
touch .env
echo TZ=${{ secrets.TZ }} >> .env
echo DB_HOST=${{ secrets.DB_HOST }} >> .env
echo DB_PORT=${{ secrets.DB_PORT }} >> .env
echo DB_USER=${{ secrets.DB_USER }} >> .env
echo DB_PASSWORD=${{ secrets.DB_PASSWORD }} >> .env
echo DB_DATABASE_NAME=${{ secrets.DEV_DB_DATABASE_NAME }} >> .env
echo DATABASE_URL=postgresql://${{ secrets.DB_USER }}:${{ secrets.DB_PASSWORD }}@${{ secrets.DB_HOST }}:${{ secrets.DB_PORT }}/${{ secrets.DEV_DB_DATABASE_NAME }}?schema=public >> .env
echo SECRET_KEY=${{ secrets.SECRET_KEY }} >> .env
echo HOST=${{ secrets.HOST }} >> .env
echo PORT=${{ secrets.PORT }} >> .env
echo SERVER_USER_PASSWORD=${{ secrets.SERVER_USER_PASSWORD }} >> .env
cat .env

- name: Remove old docker image
run: echo ${{ secrets.SERVER_USER_PASSWORD }} | sudo -S docker compose down --rmi all

- name: Create new docker image
run: echo ${{ secrets.SERVER_USER_PASSWORD }} | sudo -S docker compose up -d --force-recreate
34 changes: 34 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Deploy Backend in Development Enviroment

on:
push:
branches: [staging]

jobs:
build:
runs-on: stg

steps:
- uses: actions/checkout@v4

- name: Create .env file
run: |
touch .env
echo TZ=${{ secrets.TZ }} >> .env
echo DB_HOST=${{ secrets.DB_HOST }} >> .env
echo DB_PORT=${{ secrets.DB_PORT }} >> .env
echo DB_USER=${{ secrets.DB_USER }} >> .env
echo DB_PASSWORD=${{ secrets.DB_PASSWORD }} >> .env
echo DB_DATABASE_NAME=${{ secrets.STG_DB_DATABASE_NAME }} >> .env
echo DATABASE_URL=postgresql://${{ secrets.DB_USER }}:${{ secrets.DB_PASSWORD }}@${{ secrets.DB_HOST }}:${{ secrets.DB_PORT }}/${{ secrets.STG_DB_DATABASE_NAME }}?schema=public >> .env
echo SECRET_KEY=${{ secrets.SECRET_KEY }} >> .env
echo HOST=${{ secrets.HOST }} >> .env
echo PORT=${{ secrets.PORT }} >> .env
echo SERVER_USER_PASSWORD=${{ secrets.SERVER_USER_PASSWORD }} >> .env
cat .env

- name: Remove old docker image
run: echo ${{ secrets.SERVER_USER_PASSWORD }} | sudo -S docker compose down --rmi all

- name: Create new docker image
run: echo ${{ secrets.SERVER_USER_PASSWORD }} | sudo -S docker compose up -d --force-recreate
14 changes: 14 additions & 0 deletions prisma/migrations/20240516212629_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- CreateTable
CREATE TABLE "supporters" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"image_url" TEXT NOT NULL,
"link" TEXT NOT NULL,
"created_at" VARCHAR(32) NOT NULL,
"updated_at" VARCHAR(32),

CONSTRAINT "supporters_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "supporters_name_key" ON "supporters"("name");
11 changes: 11 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,14 @@ model Partners {

@@map("partners")
}

model Supporters {
id String @id @default(uuid())
name String @unique
imageUrl String @map("image_url")
link String
createdAt String @map("created_at") @db.VarChar(32)
updatedAt String? @map("updated_at") @db.VarChar(32)

@@map("supporters")
}
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SupplyCategoriesModule } from './supply-categories/supply-categories.mo
import { ShelterManagersModule } from './shelter-managers/shelter-managers.module';
import { ShelterSupplyModule } from './shelter-supply/shelter-supply.module';
import { PartnersModule } from './partners/partners.module';
import { SupportersModule } from './supporters/supporters.module';

@Module({
imports: [
Expand All @@ -24,6 +25,7 @@ import { PartnersModule } from './partners/partners.module';
ShelterManagersModule,
ShelterSupplyModule,
PartnersModule,
SupportersModule,
],
controllers: [],
providers: [
Expand Down
23 changes: 22 additions & 1 deletion src/partners/partners.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { Controller, Get, HttpException, Logger } from '@nestjs/common';
import {
Body,
Controller,
Get,
HttpException,
Logger,
Post,
UseGuards,
} from '@nestjs/common';
import { PartnersService } from './partners.service';
import { ServerResponse } from '../utils';
import { AdminGuard } from '@/guards/admin.guard';

@Controller('partners')
export class PartnersController {
Expand All @@ -18,4 +27,16 @@ export class PartnersController {
throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400);
}
}

@Post('')
@UseGuards(AdminGuard)
async store(@Body() body) {
try {
await this.partnersService.store(body);
return new ServerResponse(200, 'Successfully created partner');
} catch (err: any) {
this.logger.error(`Failed to create partner: ${err}`);
throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400);
}
}
}
9 changes: 9 additions & 0 deletions src/partners/partners.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Injectable } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';

import { PrismaService } from '../prisma/prisma.service';
import { z } from 'zod';
import { CreatePartnerSchema } from './types';

@ApiTags('Parceiros')
@Injectable()
Expand All @@ -11,4 +13,11 @@ export class PartnersService {
async index() {
return await this.prismaService.partners.findMany({});
}

async store(body: z.infer<typeof CreatePartnerSchema>) {
const payload = CreatePartnerSchema.parse(body);
await this.prismaService.partners.create({
data: { ...payload, createdAt: new Date().toISOString() },
});
}
}
17 changes: 17 additions & 0 deletions src/partners/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import z from 'zod';

const PartnerSchema = z.object({
id: z.string(),
name: z.string(),
link: z.string(),
createdAt: z.string(),
updatedAt: z.string().nullable().optional(),
});

const CreatePartnerSchema = PartnerSchema.omit({
id: true,
createdAt: true,
updatedAt: true,
});

export { PartnerSchema, CreatePartnerSchema };
30 changes: 30 additions & 0 deletions src/supporters/supporters.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Test, TestingModule } from '@nestjs/testing';

import { SupportersController } from './supporters.controller';
import { PrismaService } from '../prisma/prisma.service';
import { SupportersService } from './supporters.service';

describe('SupportersController', () => {
let controller: SupportersController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [SupportersController],
providers: [SupportersService],
})
.useMocker((token) => {
if (token === PrismaService) {
return {
supplyCategory: { findMany: jest.fn().mockResolvedValue(0) },
};
}
})
.compile();

controller = module.get<SupportersController>(SupportersController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
43 changes: 43 additions & 0 deletions src/supporters/supporters.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
Body,
Controller,
Get,
HttpException,
Logger,
Post,
UseGuards,
} from '@nestjs/common';

import { SupportersService } from './supporters.service';
import { ServerResponse } from '../utils';
import { AdminGuard } from '@/guards/admin.guard';

@Controller('supporters')
export class SupportersController {
private logger = new Logger(SupportersController.name);

constructor(private readonly supportersService: SupportersService) {}

@Get('')
async index() {
try {
const data = await this.supportersService.index();
return new ServerResponse(200, 'Successfully get supporters', data);
} catch (err: any) {
this.logger.error(`Failed to get supporters: ${err}`);
throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400);
}
}

@Post('')
@UseGuards(AdminGuard)
async store(@Body() body) {
try {
await this.supportersService.store(body);
return new ServerResponse(200, 'Successfully created supporter');
} catch (err: any) {
this.logger.error(`Failed to create supporter: ${err}`);
throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400);
}
}
}
12 changes: 12 additions & 0 deletions src/supporters/supporters.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';

import { SupportersService } from './supporters.service';
import { SupportersController } from './supporters.controller';
import { PrismaModule } from '../prisma/prisma.module';

@Module({
imports: [PrismaModule],
providers: [SupportersService],
controllers: [SupportersController],
})
export class SupportersModule {}
28 changes: 28 additions & 0 deletions src/supporters/supporters.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Test, TestingModule } from '@nestjs/testing';

import { SupportersService } from './supporters.service';
import { PrismaService } from '../prisma/prisma.service';

describe('SupportersService', () => {
let service: SupportersService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [SupportersService],
})
.useMocker((token) => {
if (token === PrismaService) {
return {
supplyCategory: { findMany: jest.fn().mockResolvedValue(0) },
};
}
})
.compile();

service = module.get<SupportersService>(SupportersService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
21 changes: 21 additions & 0 deletions src/supporters/supporters.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { z } from 'zod';
import { Injectable } from '@nestjs/common';

import { PrismaService } from '../prisma/prisma.service';
import { CreateSupporterSchema } from './types';

@Injectable()
export class SupportersService {
constructor(private readonly prismaService: PrismaService) {}

async index() {
return await this.prismaService.supporters.findMany({});
}

async store(body: z.infer<typeof CreateSupporterSchema>) {
const payload = CreateSupporterSchema.parse(body);
await this.prismaService.supporters.create({
data: { ...payload, createdAt: new Date().toISOString() },
});
}
}
18 changes: 18 additions & 0 deletions src/supporters/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import z from 'zod';

const SupporterSchema = z.object({
id: z.string(),
name: z.string(),
imageUrl: z.string(),
link: z.string(),
createdAt: z.string(),
updatedAt: z.string().nullable().optional(),
});

const CreateSupporterSchema = SupporterSchema.omit({
id: true,
createdAt: true,
updatedAt: true,
});

export { SupporterSchema, CreateSupporterSchema };