mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Chore: update faker to replace deprecated methods, add canadianCities for location data
This commit is contained in:
@@ -15,7 +15,7 @@ const DesktopLinks: FC = () => {
|
||||
<ul className="menu menu-horizontal menu-sm">
|
||||
{pages.map((page) => {
|
||||
return (
|
||||
<li key={page.slug} >
|
||||
<li key={page.slug}>
|
||||
<Link tabIndex={0} href={page.slug} className="hover:bg-primary-focus">
|
||||
<span
|
||||
className={`text-lg uppercase ${
|
||||
|
||||
3
src/prisma/migrations/20230603010553_/migration.sql
Normal file
3
src/prisma/migrations/20230603010553_/migration.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Location" ADD COLUMN "createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
ADD COLUMN "updatedAt" TIMESTAMPTZ(3);
|
||||
@@ -106,6 +106,8 @@ model Location {
|
||||
postedBy User @relation(fields: [postedById], references: [id], onDelete: Cascade)
|
||||
postedById String
|
||||
BreweryPost BreweryPost?
|
||||
createdAt DateTime @default(now()) @db.Timestamptz(3)
|
||||
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
|
||||
}
|
||||
|
||||
model BreweryPost {
|
||||
|
||||
@@ -22,7 +22,6 @@ const createNewBeerImages = async ({
|
||||
joinData: { beerPosts, users },
|
||||
}: CreateNewBeerImagesArgs) => {
|
||||
const prisma = DBClient.instance;
|
||||
const createdAt = faker.date.past(1);
|
||||
|
||||
const beerImageData: BeerImageData[] = [];
|
||||
|
||||
@@ -33,6 +32,7 @@ const createNewBeerImages = async ({
|
||||
const caption = faker.lorem.sentence();
|
||||
const alt = faker.lorem.sentence();
|
||||
const path = imageUrls[Math.floor(Math.random() * imageUrls.length)];
|
||||
const createdAt = faker.date.past({ years: 1 });
|
||||
|
||||
beerImageData.push({
|
||||
path,
|
||||
|
||||
@@ -34,7 +34,7 @@ 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);
|
||||
const createdAt = faker.date.past({ years: 1 });
|
||||
const rating = Math.floor(Math.random() * 5) + 1;
|
||||
|
||||
beerCommentData.push({
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import type { BeerPost, User } from '@prisma/client';
|
||||
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import { faker } from '@faker-js/faker';
|
||||
import DBClient from '../../DBClient';
|
||||
|
||||
interface BeerPostLikeData {
|
||||
beerPostId: string;
|
||||
likedById: string;
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
const createNewBeerPostLikes = async ({
|
||||
@@ -19,10 +22,11 @@ const createNewBeerPostLikes = async ({
|
||||
for (let i = 0; i < numberOfLikes; i++) {
|
||||
const beerPost = beerPosts[Math.floor(Math.random() * beerPosts.length)];
|
||||
const user = users[Math.floor(Math.random() * users.length)];
|
||||
|
||||
const createdAt = faker.date.past({ years: 1 });
|
||||
beerPostLikeData.push({
|
||||
beerPostId: beerPost.id,
|
||||
likedById: user.id,
|
||||
createdAt,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ 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);
|
||||
const createdAt = faker.date.past({ years: 1 });
|
||||
|
||||
const abv = Math.floor(Math.random() * (12 - 4) + 4);
|
||||
const ibu = Math.floor(Math.random() * (60 - 10) + 10);
|
||||
|
||||
@@ -45,7 +45,7 @@ const createNewBeerTypes = async ({ joinData }: CreateNewBeerTypesArgs) => {
|
||||
|
||||
types.forEach((type) => {
|
||||
const user = users[Math.floor(Math.random() * users.length)];
|
||||
const createdAt = faker.date.past(1);
|
||||
const createdAt = faker.date.past({ years: 1 });
|
||||
|
||||
beerTypeData.push({
|
||||
name: type,
|
||||
|
||||
@@ -26,7 +26,7 @@ const createNewBreweryImages = async ({
|
||||
joinData: { breweryPosts, users },
|
||||
}: CreateBreweryImagesArgs) => {
|
||||
const prisma = DBClient.instance;
|
||||
const createdAt = faker.date.past(1);
|
||||
const createdAt = faker.date.past({ years: 1 });
|
||||
const breweryImageData: BreweryImageData[] = [];
|
||||
|
||||
// eslint-disable-next-line no-plusplus
|
||||
|
||||
@@ -26,13 +26,14 @@ const createNewBreweryPostComments = async ({
|
||||
const { breweryPosts, users } = joinData;
|
||||
const prisma = DBClient.instance;
|
||||
const breweryPostCommentData: BreweryPostCommentData[] = [];
|
||||
const createdAt = faker.date.past(1);
|
||||
const rating = Math.floor(Math.random() * 5) + 1;
|
||||
|
||||
// eslint-disable-next-line no-plusplus
|
||||
for (let i = 0; i < numberOfComments; i++) {
|
||||
const content = faker.lorem.lines(3).replace(/\n/g, ' ');
|
||||
const user = users[Math.floor(Math.random() * users.length)];
|
||||
const breweryPost = breweryPosts[Math.floor(Math.random() * breweryPosts.length)];
|
||||
const createdAt = faker.date.past({ years: 1 });
|
||||
const rating = Math.floor(Math.random() * 5) + 1;
|
||||
|
||||
breweryPostCommentData.push({
|
||||
content,
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import type { BreweryPost, User } from '@prisma/client';
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import { faker } from '@faker-js/faker';
|
||||
import DBClient from '../../DBClient';
|
||||
|
||||
interface BreweryPostLikeData {
|
||||
breweryPostId: string;
|
||||
likedById: string;
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
const createNewBreweryPostLikes = async ({
|
||||
@@ -21,10 +24,12 @@ const createNewBreweryPostLikes = async ({
|
||||
for (let i = 0; i < numberOfLikes; i++) {
|
||||
const breweryPost = breweryPosts[Math.floor(Math.random() * breweryPosts.length)];
|
||||
const user = users[Math.floor(Math.random() * users.length)];
|
||||
const createdAt = faker.date.past({ years: 1 });
|
||||
|
||||
breweryPostLikeData.push({
|
||||
breweryPostId: breweryPost.id,
|
||||
likedById: user.id,
|
||||
createdAt,
|
||||
});
|
||||
}
|
||||
await DBClient.instance.breweryPostLike.createMany({
|
||||
|
||||
@@ -36,8 +36,8 @@ const createNewBreweryPosts = async ({
|
||||
locations.splice(locationIndex, 1); // Remove the location from the array
|
||||
const description = faker.lorem.lines(20).replace(/(\r\n|\n|\r)/gm, ' ');
|
||||
const user = users[Math.floor(Math.random() * users.length)];
|
||||
const createdAt = faker.date.past(1);
|
||||
const dateEstablished = faker.date.past(40);
|
||||
const createdAt = faker.date.past({ years: 1 });
|
||||
const dateEstablished = faker.date.past({ years: 40 });
|
||||
|
||||
breweryData.push({
|
||||
name,
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { User } from '@prisma/client';
|
||||
import { GeocodeFeature } from '@mapbox/mapbox-sdk/services/geocoding';
|
||||
import DBClient from '../../DBClient';
|
||||
import geocode from '../../../config/mapbox/geocoder';
|
||||
import canadianCities from '../util/canadianCities';
|
||||
|
||||
interface CreateNewLocationsArgs {
|
||||
numberOfLocations: number;
|
||||
@@ -19,6 +18,7 @@ interface LocationData {
|
||||
coordinates: number[];
|
||||
address: string;
|
||||
postedById: string;
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
const createNewLocations = async ({
|
||||
@@ -27,42 +27,25 @@ const createNewLocations = async ({
|
||||
}: CreateNewLocationsArgs) => {
|
||||
const prisma = DBClient.instance;
|
||||
|
||||
const locationNames: string[] = [];
|
||||
const locationData: LocationData[] = [];
|
||||
|
||||
// eslint-disable-next-line no-plusplus
|
||||
for (let i = 0; i < numberOfLocations; i++) {
|
||||
locationNames.push(faker.address.cityName());
|
||||
}
|
||||
|
||||
const geocodePromises: Promise<GeocodeFeature>[] = [];
|
||||
|
||||
locationNames.forEach((locationName) => {
|
||||
geocodePromises.push(geocode(locationName));
|
||||
});
|
||||
|
||||
const geocodedLocations = await Promise.all(geocodePromises);
|
||||
|
||||
const locationData: LocationData[] = [];
|
||||
|
||||
geocodedLocations.forEach((geodata) => {
|
||||
const randomIndex = Math.floor(Math.random() * canadianCities.length);
|
||||
const randomCity = canadianCities[randomIndex];
|
||||
const randomUser = joinData.users[Math.floor(Math.random() * joinData.users.length)];
|
||||
|
||||
const city = geodata.text;
|
||||
const postedById = randomUser.id;
|
||||
const stateOrProvince = geodata.context?.find((c) => c.id.startsWith('region'))?.text;
|
||||
const country = geodata.context?.find((c) => c.id.startsWith('country'))?.text;
|
||||
const coordinates = geodata.center;
|
||||
const address = geodata.place_name;
|
||||
canadianCities.splice(randomIndex, 1);
|
||||
|
||||
locationData.push({
|
||||
city,
|
||||
stateOrProvince,
|
||||
country,
|
||||
coordinates,
|
||||
address,
|
||||
postedById,
|
||||
address: randomCity.city,
|
||||
city: randomCity.city,
|
||||
coordinates: [randomCity.longitude, randomCity.latitude],
|
||||
createdAt: faker.date.past({ years: 1 }),
|
||||
postedById: randomUser.id,
|
||||
stateOrProvince: randomCity.province,
|
||||
country: 'Canada',
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.location.createMany({ data: locationData, skipDuplicates: true });
|
||||
|
||||
|
||||
@@ -31,11 +31,11 @@ const createNewUsers = async ({ numberOfUsers }: CreateNewUsersArgs) => {
|
||||
// eslint-disable-next-line no-plusplus
|
||||
for (let i = 0; i < numberOfUsers; i++) {
|
||||
const randomValue = crypto.randomBytes(1).toString('hex');
|
||||
const firstName = faker.name.firstName();
|
||||
const lastName = faker.name.lastName();
|
||||
const firstName = faker.person.firstName();
|
||||
const lastName = faker.person.lastName();
|
||||
const username = `${firstName[0]}.${lastName}.${randomValue}`.toLowerCase();
|
||||
const email = faker.internet
|
||||
.email(firstName, randomValue, 'example.com')
|
||||
.email({ firstName, lastName, provider: 'example.com' })
|
||||
.toLowerCase();
|
||||
|
||||
const userAvailable =
|
||||
@@ -51,7 +51,7 @@ const createNewUsers = async ({ numberOfUsers }: CreateNewUsersArgs) => {
|
||||
takenEmails.push(email);
|
||||
|
||||
const dateOfBirth = faker.date.birthdate({ mode: 'age', min: 19 });
|
||||
const createdAt = faker.date.past(1);
|
||||
const createdAt = faker.date.past({ years: 4 });
|
||||
|
||||
const user = {
|
||||
firstName,
|
||||
|
||||
10425
src/prisma/seed/util/canadianCities.ts
Executable file
10425
src/prisma/seed/util/canadianCities.ts
Executable file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user