Edit seed db function

This commit is contained in:
Aaron William Po
2023-01-22 23:49:58 -05:00
parent 0065525f5c
commit f08731de17
21 changed files with 1115 additions and 166 deletions

View File

@@ -0,0 +1,36 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { faker } from '@faker-js/faker';
import { User } from '@prisma/client';
import DBClient from '../../DBClient';
interface CreateNewBreweryPostsArgs {
numberOfPosts: number;
joinData: {
users: User[];
};
}
const createNewBreweryPosts = async ({
numberOfPosts,
joinData,
}: CreateNewBreweryPostsArgs) => {
const { users } = joinData;
const prisma = DBClient.instance;
const breweryPromises = [];
// eslint-disable-next-line no-plusplus
for (let i = 0; i < numberOfPosts; i++) {
const name = `${faker.commerce.productName()} Brewing Company`;
const location = faker.address.cityName();
const description = faker.lorem.lines(5);
const user = users[Math.floor(Math.random() * users.length)];
breweryPromises.push(
prisma.breweryPost.create({
data: { name, location, description, postedBy: { connect: { id: user.id } } },
}),
);
}
return Promise.all(breweryPromises);
};
export default createNewBreweryPosts;