-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Histórico de suprimentos (#162)
1. **Criada Tabela de Registro de Histórico de Supplies dos abrigos** - Foi criada uma nova tabela no banco de dados para registrar o histórico de cada supply de cada abrigo, permitindo um melhor acompanhamento e gerenciamento dos recursos, incluindo dados como ip e user agent do usuário; 2. **Criado Decorator para Registro de Log de Supplies** - Implementado um decorator para registro de log, separando a lógica do controller da lógica de registro de log. Isso melhora a organização e manutenção do código. 3. **Removido Dependências Desnecessárias do Express** - As dependências desnecessárias do Express foram removidas, considerando que o projeto utiliza Fastify. Essa mudança reduz o peso e possíveis conflitos no projeto. 4. **Atualizado o Hook do Prisma** - A lógica hard coded de criptografia de senhas de usuários foi removida do hook do Prisma e movida para um módulo separado. Esse módulo agora serve como exemplo para futuras implementações relacionadas a hooks do Prisma. 5. **Adicionada Referência Singleton do Prisma** - Foi adicionada a referência singleton do Prisma, facilitando o uso em casos onde era necessário quebrar a cabeça para injetar dependências em funções utilitárias e afins. 6. **Criado Endpoint para Listar Histórico de Suprimentos** - Um novo endpoint foi criado para listar o histórico de suprimentos de um abrigo de forma paginada, melhorando a eficiência na consulta e visualização dos dados. --- **Nota:** Essas mudanças visam melhorar a organização do código, a eficiência do sistema e a manutenção futura do projeto.
- Loading branch information
1 parent
bc100dd
commit d5be560
Showing
38 changed files
with
825 additions
and
183 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- CreateTable | ||
CREATE TABLE "supplies_history" ( | ||
"id" TEXT NOT NULL, | ||
"shelter_id" TEXT NOT NULL, | ||
"supply_id" TEXT NOT NULL, | ||
"priority" INTEGER, | ||
"quantity" INTEGER, | ||
"created_at" VARCHAR(32) NOT NULL, | ||
|
||
CONSTRAINT "supplies_history_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "supplies_history_shelter_id_supply_id_idx" ON "supplies_history"("shelter_id", "supply_id"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "supplies_history" ADD CONSTRAINT "supplies_history_shelter_id_supply_id_fkey" FOREIGN KEY ("shelter_id", "supply_id") REFERENCES "shelter_supplies"("shelter_id", "supply_id") ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Warnings: | ||
- A unique constraint covering the columns `[sucessor_id]` on the table `supplies_history` will be added. If there are existing duplicate values, this will fail. | ||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE "supplies_history" DROP CONSTRAINT "supplies_history_shelter_id_supply_id_fkey"; | ||
|
||
-- DropIndex | ||
DROP INDEX "supplies_history_shelter_id_supply_id_idx"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "supplies_history" ADD COLUMN "sucessor_id" TEXT; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "supplies_history_sucessor_id_key" ON "supplies_history"("sucessor_id"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "supplies_history" ADD CONSTRAINT "supplies_history_sucessor_id_fkey" FOREIGN KEY ("sucessor_id") REFERENCES "supplies_history"("id") ON DELETE SET NULL ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "supplies_history" ADD CONSTRAINT "supplies_history_shelter_id_fkey" FOREIGN KEY ("shelter_id") REFERENCES "shelters"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "supplies_history" ADD CONSTRAINT "supplies_history_supply_id_fkey" FOREIGN KEY ("supply_id") REFERENCES "supplies"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `sucessor_id` on the `supplies_history` table. All the data in the column will be lost. | ||
- A unique constraint covering the columns `[predecessor_id]` on the table `supplies_history` will be added. If there are existing duplicate values, this will fail. | ||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE "supplies_history" DROP CONSTRAINT "supplies_history_sucessor_id_fkey"; | ||
|
||
-- DropIndex | ||
DROP INDEX "supplies_history_sucessor_id_key"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "supplies_history" DROP COLUMN "sucessor_id", | ||
ADD COLUMN "predecessor_id" TEXT; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "supplies_history_predecessor_id_key" ON "supplies_history"("predecessor_id"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "supplies_history" ADD CONSTRAINT "supplies_history_predecessor_id_fkey" FOREIGN KEY ("predecessor_id") REFERENCES "supplies_history"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- AlterTable | ||
ALTER TABLE "supplies_history" ADD COLUMN "ip" TEXT, | ||
ADD COLUMN "user_agent" TEXT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- AlterTable | ||
ALTER TABLE "supplies_history" ADD COLUMN "user_id" TEXT; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "supplies_history" ADD CONSTRAINT "supplies_history_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/decorators/RegisterShelterSupplyHistory/RegisterShelterSupplyHistory.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { applyDecorators, UseInterceptors } from '@nestjs/common'; | ||
|
||
import { ShelterSupplyHistoryAction } from '@/interceptors/interceptors/shelter-supply-history/types'; | ||
import { ShelterSupplyHistoryInterceptor } from '@/interceptors/interceptors'; | ||
|
||
export function RegisterShelterSupplyHistory( | ||
action: ShelterSupplyHistoryAction, | ||
) { | ||
return applyDecorators( | ||
UseInterceptors(new ShelterSupplyHistoryInterceptor(action)), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { RegisterShelterSupplyHistory } from './RegisterShelterSupplyHistory.decorator'; | ||
|
||
export { RegisterShelterSupplyHistory }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { ServerResponseInterceptor } from './server-response'; | ||
import { ShelterSupplyHistoryInterceptor } from './shelter-supply-history'; | ||
|
||
export { ServerResponseInterceptor }; | ||
export { ServerResponseInterceptor, ShelterSupplyHistoryInterceptor }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/interceptors/interceptors/shelter-supply-history/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { ShelterSupplyHistoryInterceptor } from './shelter-supply-history.interceptor'; | ||
|
||
export { ShelterSupplyHistoryInterceptor }; |
22 changes: 22 additions & 0 deletions
22
src/interceptors/interceptors/shelter-supply-history/shelter-supply-history.interceptor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
CallHandler, | ||
ExecutionContext, | ||
Injectable, | ||
NestInterceptor, | ||
} from '@nestjs/common'; | ||
import { Observable } from 'rxjs'; | ||
|
||
import { ShelterSupplyHistoryAction } from './types'; | ||
import { handler } from './utils'; | ||
import { prisma } from '../../../prisma/prisma.service'; | ||
|
||
@Injectable() | ||
export class ShelterSupplyHistoryInterceptor implements NestInterceptor { | ||
constructor(private readonly action: ShelterSupplyHistoryAction) {} | ||
|
||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> { | ||
const request = context.switchToHttp().getRequest(); | ||
handler(prisma, this.action, request); | ||
return next.handle(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/interceptors/interceptors/shelter-supply-history/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export enum ShelterSupplyHistoryAction { | ||
Create = 'shelter-supply-history-action/create', | ||
Update = 'shelter-supply-history-action/update', | ||
UpdateMany = 'shelter-supply-history-action/update-many', | ||
} | ||
|
||
export interface UserIdentity { | ||
ip?: string; | ||
userAgent?: string; | ||
userId?: string; | ||
} |
Oops, something went wrong.