Created
October 23, 2024 07:40
-
-
Save hrueger/0e3e9fe754e720de4373ecde7d5992c2 to your computer and use it in GitHub Desktop.
Load all discounts from the old db schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-check | |
import { PrismaClient } from '@prisma/client' | |
import chalk from "chalk"; | |
const prisma = new PrismaClient(); | |
const orgs = await prisma.organization.findMany({ | |
where: { | |
series: { | |
some: { | |
editions: { | |
some: { | |
events: { | |
some: { | |
start: { | |
gte: new Date() | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}, | |
include: { | |
series: { | |
where: { | |
editions: { | |
some: { | |
events: { | |
some: { | |
start: { | |
gte: new Date() | |
} | |
} | |
} | |
} | |
} | |
}, | |
include: { | |
editions: { | |
where: { | |
events: { | |
some: { | |
start: { | |
gte: new Date() | |
} | |
} | |
} | |
}, | |
include: { | |
events: { | |
where: { | |
start: { | |
gte: new Date() | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}); | |
for (const organization of orgs) { | |
// build tree out of utf-8 characters like └─, │, etc. | |
console.log(organization.name); | |
for (const series of organization.series) { | |
console.log(`└─ ${series.name}`); | |
for (const edition of series.editions) { | |
console.log(` └─ ${edition.name}`); | |
for (const event of edition.events) { | |
console.log(` └─ ${event.name}`); | |
const discounts = await prisma.discount.findMany({ | |
where: { | |
OR: [ | |
{ organizationId: organization.id }, | |
{ seriesId: series.id }, | |
{ editionId: edition.id }, | |
{ events: {some: {id: event.id}} }, | |
], | |
} | |
}); | |
for (const discount of discounts) { | |
// mark with block character | |
console.log(chalk.blue(` └─ ${discount.name} ${discount.description} ${discount.mode} ${discount.condition}`) + chalk.green(` ${(discount.value)}`)); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment