Skip to content

Commit

Permalink
Add seeding of donation wishes - seed 1 wish to each donation (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitur2204 authored Oct 29, 2023
1 parent 6d1bd9f commit cdda5b3
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions db/seed/donationWish/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,42 @@ import { donationWishFactory } from './factory'

const prisma = new PrismaClient()

const SEED_DONATION_WISHES = 25

export async function donationsWishesSeed() {
console.log('Donation wishes seed')

const person = await prisma.person.findFirst()
if (!person) {
throw new Error('There are no people created yet!')
const campaigns = await prisma.campaign.findMany()
if (!campaigns) {
throw new Error('There are no campaigns created yet!')
}

const campaign = await prisma.campaign.findFirst()
if (!campaign) {
throw new Error('There are no vaults created yet!')
const donations = await prisma.donation.findMany()
if (!donations) {
throw new Error('There are no donations created yet!')
}

const donationWishesData = donationWishFactory.buildList(
SEED_DONATION_WISHES,
{},
{
associations: {
campaignId: campaign.id,
personId: person.id,
donations.forEach(async (donation) => {
const person = await prisma.person.findFirst()
if (!person) {
throw new Error('There are no people created yet!')
}
const campaign = await prisma.campaign.findFirst({
where: {
vaults: {
some: {
id: donation.targetVaultId,
},
},
},
},
)

const insertDonationWishes = await prisma.donationWish.createMany({
data: donationWishesData,
skipDuplicates: true,
})
if (!campaign) {
throw new Error('There are no campaign with this vault created yet!')
}
const donationWishData = donationWishFactory.build({
campaignId: campaign.id,
personId: person.id,
donationId: donation.id,
})

await prisma.donationWish.create({
data: donationWishData,
})
})

console.log({ insertDonationWishes })
}

0 comments on commit cdda5b3

Please sign in to comment.