diff --git a/db/seed/donationWish/seed.ts b/db/seed/donationWish/seed.ts index fc9f23764..b70ff273a 100644 --- a/db/seed/donationWish/seed.ts +++ b/db/seed/donationWish/seed.ts @@ -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 }) }