167 lines
3.0 KiB
TypeScript
167 lines
3.0 KiB
TypeScript
import { ContainerType, PrismaClient } from "@prisma/client";
|
|
import { enhance } from "@zenstackhq/runtime";
|
|
import { BeerStyle, Country, Manufacturer } from "@zenstackhq/runtime/models";
|
|
const pr = new PrismaClient();
|
|
const db = enhance(pr);
|
|
|
|
async function seed() {
|
|
|
|
await db.container.deleteMany({});
|
|
await db.beer.deleteMany({});
|
|
await db.beerStyle.deleteMany({});
|
|
await db.manufacturer.deleteMany({});
|
|
await db.country.deleteMany({});
|
|
|
|
await Promise.all(
|
|
getCountries().map((country) => {
|
|
return db.country.create({ data: country });
|
|
})
|
|
);
|
|
|
|
await Promise.all(
|
|
getManufacturers().map((man) => {
|
|
return db.manufacturer.create({ data: man });
|
|
})
|
|
);
|
|
|
|
await Promise.all(
|
|
getBeerStyles().map((style) => {
|
|
return db.beerStyle.create({ data: style });
|
|
})
|
|
);
|
|
|
|
await Promise.all(
|
|
getBeers().map((beer) => {
|
|
return db.beer.create({ data: beer });
|
|
})
|
|
);
|
|
|
|
await Promise.all(
|
|
getContainers().map((container) => {
|
|
return db.container.create({ data: container });
|
|
})
|
|
);
|
|
}
|
|
|
|
seed();
|
|
|
|
interface BeerQuery {
|
|
slug: string;
|
|
manufacturer: any;
|
|
name: string;
|
|
description: string;
|
|
abv: number;
|
|
style: any;
|
|
ibu: number | null;
|
|
}
|
|
|
|
interface ContainerQuery {
|
|
barcode: string;
|
|
drink: any;
|
|
type: ContainerType;
|
|
volume: number;
|
|
portions: number | null;
|
|
}
|
|
|
|
function getCountries() : Country[]{
|
|
return [
|
|
{
|
|
code: "nl",
|
|
name: "Netherlands"
|
|
},
|
|
{
|
|
code: "de",
|
|
name: "Germany"
|
|
},
|
|
{
|
|
code: "be",
|
|
name: "Belgium"
|
|
}
|
|
];
|
|
}
|
|
|
|
function getManufacturers() : Manufacturer[] {
|
|
return [
|
|
{
|
|
id: 1,
|
|
country_id: "nl",
|
|
name: "Hertog Jan",
|
|
image: null
|
|
},
|
|
{
|
|
id: 2,
|
|
country_id: "nl",
|
|
name: "Heineken",
|
|
image: null
|
|
},
|
|
{
|
|
id: 3,
|
|
country_id: "nl",
|
|
name: "Jupiler",
|
|
image: null
|
|
},
|
|
{
|
|
id: 4,
|
|
country_id: "nl",
|
|
name: "Brouwerij Het IJ",
|
|
image: null
|
|
}
|
|
];
|
|
}
|
|
|
|
function getBeerStyles() : BeerStyle[] {
|
|
return [
|
|
{
|
|
id: 1,
|
|
name: "Pilsener",
|
|
},
|
|
{
|
|
id: 2,
|
|
name: "Dubbel"
|
|
},
|
|
{
|
|
id: 3,
|
|
name: "Tripel"
|
|
}
|
|
];
|
|
}
|
|
|
|
function getBeers() : BeerQuery[] {
|
|
return [
|
|
{
|
|
slug: "ginger_paradise",
|
|
name: "Ginger Paradise",
|
|
abv: 6.2,
|
|
ibu: 5,
|
|
|
|
manufacturer: {connect: { id: 4}},
|
|
style: {connect: { id: 3}},
|
|
|
|
description: "Some desciption on why this beer is so great and it has this and that flavour",
|
|
},
|
|
{
|
|
slug: "ginger_paradise",
|
|
name: "Ginger Paradise",
|
|
abv: 6.2,
|
|
ibu: 5,
|
|
|
|
manufacturer: {connect: { id: 4}},
|
|
style: {connect: { id: 3}},
|
|
|
|
description: "Some desciption on why this beer is so great and it has this and that flavour",
|
|
}
|
|
];
|
|
}
|
|
|
|
function getContainers() : ContainerQuery[] {
|
|
return [
|
|
{
|
|
barcode: "temporary1",
|
|
drink: {connect: { slug: "ginger_paradise"}},
|
|
type: ContainerType.BeerBottle,
|
|
volume: 330,
|
|
portions: 1
|
|
}
|
|
];
|
|
}
|