Skip to content

Commit

Permalink
refactor: rename sheltersuppliesLogs to suppliesHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
Danilo Romano committed May 22, 2024
1 parent 7e4e193 commit c22adce
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Warnings:
- You are about to drop the `item_updates_log` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropTable
DROP TABLE "item_updates_log";

-- CreateTable
CREATE TABLE "supplies_history" (
"id" TEXT NOT NULL,
"supply_name" TEXT,
"shelter_name" TEXT,
"ip_address" TEXT,
"previousPriority" INTEGER,
"currentPriority" INTEGER,
"previousQuantity" INTEGER,
"currentQuantity" INTEGER,
"user_id" TEXT,
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "supplies_history_pkey" PRIMARY KEY ("id")
);
4 changes: 2 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ model Audit {
@@map("audit_logs")
}

model ShelterSupplyLogs {
model SuppliesHistory {
id String @id @default(uuid())
supplyName String? @map("supply_name")
shelterName String? @map("shelter_name")
Expand All @@ -180,5 +180,5 @@ model ShelterSupplyLogs {
userId String? @map("user_id")
updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamptz()
@@map("item_updates_log")
@@map("supplies_history")
}
6 changes: 3 additions & 3 deletions src/prisma/prisma.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function ExtendPrismaClient(client: PrismaClient) {
const afterUpdate = await client.shelterSupply.update(
args as Prisma.ShelterSupplyUpdateArgs,
);
await client.shelterSupplyLogs.create({
await client.suppliesHistory.create({
data: {
...auditArgs,
currentPriority: afterUpdate.priority,
Expand Down Expand Up @@ -239,7 +239,7 @@ function ExtendPrismaClient(client: PrismaClient) {
supply: { name: string };
})[];

const diffs: Prisma.ShelterSupplyLogsCreateInput[] = [];
const diffs: Prisma.SuppliesHistoryCreateInput[] = [];

shelterSuppliesBefore.forEach((previous, index) => {
const current = shelterSuppliesAfter[index];
Expand All @@ -258,7 +258,7 @@ function ExtendPrismaClient(client: PrismaClient) {
});

if (diffs.length > 0) {
await client.shelterSupplyLogs.createMany({ data: diffs });
await client.suppliesHistory.createMany({ data: diffs });
}

return shelterSuppliesAfter;
Expand Down

0 comments on commit c22adce

Please sign in to comment.