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

Add seeding of donation wishes - seed 1 wish to each donation #569

Merged
merged 1 commit into from
Oct 29, 2023
Merged
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
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 })
}
Loading