From 4d44d38d7ee805cbc4774a66fa4276d21c21b06e Mon Sep 17 00:00:00 2001 From: Aleksandar Petkov Date: Mon, 20 May 2024 19:01:30 +0300 Subject: [PATCH] fix(prisma): Set default Donation Type to donation (#635) There are recurring donations, created prior the implementation of the corporate flow, and thus resulting in an error when creating new donation, as type field is missing from the metadata. Set default value of DonationType to donation to prevent this --- .../domain/generated/donation/dto/create-donation.dto.ts | 8 +------- .../domain/generated/donation/dto/update-donation.dto.ts | 8 +------- .../migration.sql | 2 ++ podkrepi.dbml | 2 +- schema.prisma | 2 +- 5 files changed, 6 insertions(+), 16 deletions(-) create mode 100644 migrations/20240517165753_set_default_donation_type/migration.sql diff --git a/apps/api/src/domain/generated/donation/dto/create-donation.dto.ts b/apps/api/src/domain/generated/donation/dto/create-donation.dto.ts index 290d9bee..538847f8 100644 --- a/apps/api/src/domain/generated/donation/dto/create-donation.dto.ts +++ b/apps/api/src/domain/generated/donation/dto/create-donation.dto.ts @@ -1,7 +1 @@ -import { DonationType } from '@prisma/client' -import { ApiProperty } from '@nestjs/swagger' - -export class CreateDonationDto { - @ApiProperty({ enum: DonationType }) - type: DonationType -} +export class CreateDonationDto {} diff --git a/apps/api/src/domain/generated/donation/dto/update-donation.dto.ts b/apps/api/src/domain/generated/donation/dto/update-donation.dto.ts index 050aef5e..730ce551 100644 --- a/apps/api/src/domain/generated/donation/dto/update-donation.dto.ts +++ b/apps/api/src/domain/generated/donation/dto/update-donation.dto.ts @@ -1,7 +1 @@ -import { DonationType } from '@prisma/client' -import { ApiProperty } from '@nestjs/swagger' - -export class UpdateDonationDto { - @ApiProperty({ enum: DonationType }) - type?: DonationType -} +export class UpdateDonationDto {} diff --git a/migrations/20240517165753_set_default_donation_type/migration.sql b/migrations/20240517165753_set_default_donation_type/migration.sql new file mode 100644 index 00000000..02392865 --- /dev/null +++ b/migrations/20240517165753_set_default_donation_type/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "donations" ALTER COLUMN "type" SET DEFAULT 'donation'; diff --git a/podkrepi.dbml b/podkrepi.dbml index 26ccf535..f16494f6 100644 --- a/podkrepi.dbml +++ b/podkrepi.dbml @@ -393,7 +393,7 @@ Table payments { Table donations { id String [pk] paymentId String [not null] - type DonationType [not null] + type DonationType [not null, default: 'donation'] targetVaultId String [not null, note: 'Vault where the funds are going'] amount Int [not null, default: 0] personId String diff --git a/schema.prisma b/schema.prisma index 1e41d536..89dc2b28 100644 --- a/schema.prisma +++ b/schema.prisma @@ -475,7 +475,7 @@ model Donation { id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid paymentId String @map("payment_id") @db.Uuid - type DonationType + type DonationType @default(donation) /// Vault where the funds are going targetVaultId String @map("target_vault_id") @db.Uuid amount Int @default(0)