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

Update prisma schema according to discussion #223

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export class CreateRecurringDonationDto {
@IsUUID()
personId: string

@ApiProperty()
@Expose()
@IsUUID()
campaignId: string

@ApiProperty()
@Expose()
@IsString()
Expand Down Expand Up @@ -51,6 +56,7 @@ export class CreateRecurringDonationDto {
status: this.status,
extSubscriptionId: this.extSubscriptionId,
extCustomerId: this.extCustomerId,
campaignId: this.campaignId,
amount: this.amount,
currency: this.currency,
sourceVault: {
Expand Down
65 changes: 40 additions & 25 deletions schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ model Coordinator {
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
person Person @relation(fields: [personId], references: [id])
beneficiaries Beneficiary[]
campaigns Campaign[]
beneficiaries Beneficiary[]
bankAccounts BankAccount[]

@@unique([personId])
@@map("coordinators")
Expand Down Expand Up @@ -154,32 +155,33 @@ model CampaignType {
}

model Campaign {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
state CampaignState @default(draft)
slug String @unique @db.VarChar(250)
title String @db.VarChar(200)
essence String @db.VarChar(500)
coordinatorId String @map("coordinator_id") @db.Uuid
beneficiaryId String @map("beneficiary_id") @db.Uuid
campaignTypeId String @map("campaign_type_id") @db.Uuid
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
state CampaignState @default(draft)
slug String @unique @db.VarChar(250)
title String @db.VarChar(200)
essence String @db.VarChar(500)
coordinatorId String @map("coordinator_id") @db.Uuid
beneficiaryId String @map("beneficiary_id") @db.Uuid
campaignTypeId String @map("campaign_type_id") @db.Uuid
approvedById String? @map("approved_by_id") @db.Uuid
description String?
targetAmount Int? @default(0) @map("target_amount")
startDate DateTime? @map("start_date") @db.Timestamptz(6)
endDate DateTime? @map("end_date") @db.Timestamptz(6)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6)
approvedById String? @map("approved_by_id") @db.Uuid
currency Currency @default(BGN)
approvedBy Person? @relation(fields: [approvedById], references: [id])
beneficiary Beneficiary @relation(fields: [beneficiaryId], references: [id])
campaignType CampaignType @relation(fields: [campaignTypeId], references: [id], onDelete: Cascade, onUpdate: NoAction)
coordinator Coordinator @relation(fields: [coordinatorId], references: [id])
outgoingTransfers Transfer[] @relation("source_campaign")
incomingTransfers Transfer[] @relation("target_campaign")
targetAmount Int? @default(0) @map("target_amount") @db.Integer
currency Currency @default(BGN)
startDate DateTime? @map("start_date") @db.Timestamptz(6)
endDate DateTime? @map("end_date") @db.Timestamptz(6)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6)
approvedBy Person? @relation(fields: [approvedById], references: [id])
coordinator Coordinator @relation(fields: [coordinatorId], references: [id])
beneficiary Beneficiary @relation(fields: [beneficiaryId], references: [id])
campaignType CampaignType @relation(fields: [campaignTypeId], references: [id], onDelete: Cascade, onUpdate: NoAction)
vaults Vault[]
withdrawals Withdrawal[]
incomingTransfers Transfer[] @relation("target_campaign")
outgoingTransfers Transfer[] @relation("source_campaign")
campaignFiles CampaignFile[]
withdrawals Withdrawal[]
bankAccounts BankAccount[]

@@map("campaigns")
}
Expand Down Expand Up @@ -269,6 +271,7 @@ model Country {
model Vault {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String @default("") @db.VarChar(100)
type VaultType @default(campaign)
currency Currency @default(BGN)
amount Int @default(0)
campaignId String @map("campaign_id") @db.Uuid
Expand Down Expand Up @@ -317,6 +320,7 @@ model RecurringDonation {
/// Payment provider Subscription id
extSubscriptionId String @map("ext_subscription_id") @db.VarChar(50)
extCustomerId String? @map("ext_customer_id") @db.VarChar(50)
campaignId String
///
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
Expand All @@ -333,7 +337,8 @@ model Transfer {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
status TransferStatus @default(initial)
currency Currency
amount Int @default(0)
amount Int @default(0) @db.Integer
tax Int @default(0) @db.Integer
reason String @db.VarChar(100)
/// Source vault
sourceVaultId String @map("source_vault_id") @db.Uuid
Expand Down Expand Up @@ -383,6 +388,7 @@ model Withdrawal {
model BankAccount {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
status BankAccountStatus @default(new)
currency Currency @default(BGN)
/// IBAN number
ibanNumber String @db.VarChar(34)
/// Name of account holder
Expand All @@ -394,9 +400,12 @@ model BankAccount {
/// Bank Identification Code, BIC/SWIFT code
bankIdCode String? @map("bank_id_code") @db.VarChar(50)
fingerprint String? @db.VarChar(100)
coordinatorId String? @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
withdraws Withdrawal[]
campaigns Campaign[]
coordinator Coordinator? @relation(fields: [coordinatorId], references: [id])

@@map("bank_accounts")
}
Expand Down Expand Up @@ -651,3 +660,9 @@ enum CampaignFileRole {

@@map("campaign_file_role")
}

enum VaultType {
system
campaign
person
}