mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 18:52:06 +00:00
Did more work to beer post page, seed
Worked on comments and beer recs features. Fine tuning database seed amounts.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { BeerPost, BeerImage } from '@prisma/client';
|
||||
import DBClient from '../../DBClient';
|
||||
|
||||
@@ -10,7 +12,7 @@ const createNewBeerImages = async ({
|
||||
beerPosts,
|
||||
}: CreateNewBeerImagesArgs) => {
|
||||
const prisma = DBClient.instance;
|
||||
|
||||
const createdAt = faker.date.past(1);
|
||||
const beerImagesPromises: Promise<BeerImage>[] = [];
|
||||
|
||||
// eslint-disable-next-line no-plusplus
|
||||
@@ -22,6 +24,7 @@ const createNewBeerImages = async ({
|
||||
url: 'https://picsum.photos/900/1600',
|
||||
alt: 'Placeholder beer image.',
|
||||
beerPost: { connect: { id: beerPost.id } },
|
||||
createdAt,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -23,12 +23,15 @@ const createNewBeerComments = async ({
|
||||
const content = faker.lorem.lines(5);
|
||||
const user = users[Math.floor(Math.random() * users.length)];
|
||||
const beerPost = beerPosts[Math.floor(Math.random() * beerPosts.length)];
|
||||
const createdAt = faker.date.past(1);
|
||||
beerCommentPromises.push(
|
||||
prisma.beerComment.create({
|
||||
data: {
|
||||
content,
|
||||
postedBy: { connect: { id: user.id } },
|
||||
beerPost: { connect: { id: beerPost.id } },
|
||||
rating: Math.floor(Math.random() * 5) + 1,
|
||||
createdAt,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -25,17 +25,18 @@ const createNewBeerPosts = async ({
|
||||
const user = users[Math.floor(Math.random() * users.length)];
|
||||
const beerType = beerTypes[Math.floor(Math.random() * beerTypes.length)];
|
||||
const breweryPost = breweryPosts[Math.floor(Math.random() * breweryPosts.length)];
|
||||
|
||||
const createdAt = faker.date.past(1);
|
||||
beerPostPromises.push(
|
||||
prisma.beerPost.create({
|
||||
data: {
|
||||
abv: 10,
|
||||
ibu: 10,
|
||||
name: `${faker.commerce.productName()} ${beerType.name}`,
|
||||
abv: Math.floor(Math.random() * (12 - 4) + 4),
|
||||
ibu: Math.floor(Math.random() * (60 - 10) + 10),
|
||||
name: faker.commerce.productName(),
|
||||
description: faker.lorem.lines(24),
|
||||
brewery: { connect: { id: breweryPost.id } },
|
||||
postedBy: { connect: { id: user.id } },
|
||||
type: { connect: { id: beerType.id } },
|
||||
createdAt,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { User, BeerType } from '@prisma/client';
|
||||
import DBClient from '../../DBClient';
|
||||
|
||||
@@ -36,9 +38,10 @@ const createNewBeerTypes = async ({ joinData }: CreateNewBeerTypesArgs) => {
|
||||
|
||||
types.forEach((type) => {
|
||||
const user = users[Math.floor(Math.random() * users.length)];
|
||||
const createdAt = faker.date.past(1);
|
||||
beerTypePromises.push(
|
||||
prisma.beerType.create({
|
||||
data: { name: type, postedBy: { connect: { id: user.id } } },
|
||||
data: { name: type, postedBy: { connect: { id: user.id } }, createdAt },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { BreweryPost, BreweryImage } from '@prisma/client';
|
||||
import DBClient from '../../DBClient';
|
||||
|
||||
@@ -10,7 +12,7 @@ const createNewBreweryImages = async ({
|
||||
breweryPosts,
|
||||
}: CreateBreweryImagesArgs) => {
|
||||
const prisma = DBClient.instance;
|
||||
|
||||
const createdAt = faker.date.past(1);
|
||||
const breweryImagesPromises: Promise<BreweryImage>[] = [];
|
||||
|
||||
// eslint-disable-next-line no-plusplus
|
||||
@@ -23,6 +25,7 @@ const createNewBreweryImages = async ({
|
||||
url: 'https://picsum.photos/900/1600',
|
||||
alt: 'Placeholder brewery image.',
|
||||
breweryPost: { connect: { id: breweryPost.id } },
|
||||
createdAt,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -18,6 +18,7 @@ const createNewBreweryPostComments = async ({
|
||||
const { breweryPosts, users } = joinData;
|
||||
const prisma = DBClient.instance;
|
||||
const breweryCommentPromises: Promise<BreweryComment>[] = [];
|
||||
const createdAt = faker.date.past(1);
|
||||
// eslint-disable-next-line no-plusplus
|
||||
for (let i = 0; i < numberOfComments; i++) {
|
||||
const content = faker.lorem.lines(5);
|
||||
@@ -29,6 +30,8 @@ const createNewBreweryPostComments = async ({
|
||||
content,
|
||||
postedBy: { connect: { id: user.id } },
|
||||
breweryPost: { connect: { id: breweryPost.id } },
|
||||
rating: Math.floor(Math.random() * 5) + 1,
|
||||
createdAt,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -23,10 +23,16 @@ const createNewBreweryPosts = async ({
|
||||
const location = faker.address.cityName();
|
||||
const description = faker.lorem.lines(5);
|
||||
const user = users[Math.floor(Math.random() * users.length)];
|
||||
|
||||
const createdAt = faker.date.past(1);
|
||||
breweryPromises.push(
|
||||
prisma.breweryPost.create({
|
||||
data: { name, location, description, postedBy: { connect: { id: user.id } } },
|
||||
data: {
|
||||
name,
|
||||
location,
|
||||
description,
|
||||
postedBy: { connect: { id: user.id } },
|
||||
createdAt,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ const createNewUsers = async ({ numberOfUsers }: CreateNewUsersArgs) => {
|
||||
const username = `${firstName[0]}.${lastName}`;
|
||||
const email = faker.internet.email(firstName, lastName, 'example.com');
|
||||
const dateOfBirth = faker.date.birthdate({ mode: 'age', min: 19 });
|
||||
|
||||
const createdAt = faker.date.past(1);
|
||||
userPromises.push(
|
||||
prisma.user.create({
|
||||
data: {
|
||||
@@ -25,6 +25,7 @@ const createNewUsers = async ({ numberOfUsers }: CreateNewUsersArgs) => {
|
||||
email,
|
||||
username,
|
||||
dateOfBirth,
|
||||
createdAt,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user