mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-04-05 18:09:04 +00:00
Edit seed db function
This commit is contained in:
36
prisma/seed/create/createNewBreweryPosts.ts
Normal file
36
prisma/seed/create/createNewBreweryPosts.ts
Normal 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;
|
||||
Reference in New Issue
Block a user