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">
|
<ul className="menu menu-horizontal menu-sm">
|
||||||
{pages.map((page) => {
|
{pages.map((page) => {
|
||||||
return (
|
return (
|
||||||
<li key={page.slug} >
|
<li key={page.slug}>
|
||||||
<Link tabIndex={0} href={page.slug} className="hover:bg-primary-focus">
|
<Link tabIndex={0} href={page.slug} className="hover:bg-primary-focus">
|
||||||
<span
|
<span
|
||||||
className={`text-lg uppercase ${
|
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)
|
postedBy User @relation(fields: [postedById], references: [id], onDelete: Cascade)
|
||||||
postedById String
|
postedById String
|
||||||
BreweryPost BreweryPost?
|
BreweryPost BreweryPost?
|
||||||
|
createdAt DateTime @default(now()) @db.Timestamptz(3)
|
||||||
|
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
model BreweryPost {
|
model BreweryPost {
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ const createNewBeerImages = async ({
|
|||||||
joinData: { beerPosts, users },
|
joinData: { beerPosts, users },
|
||||||
}: CreateNewBeerImagesArgs) => {
|
}: CreateNewBeerImagesArgs) => {
|
||||||
const prisma = DBClient.instance;
|
const prisma = DBClient.instance;
|
||||||
const createdAt = faker.date.past(1);
|
|
||||||
|
|
||||||
const beerImageData: BeerImageData[] = [];
|
const beerImageData: BeerImageData[] = [];
|
||||||
|
|
||||||
@@ -33,6 +32,7 @@ const createNewBeerImages = async ({
|
|||||||
const caption = faker.lorem.sentence();
|
const caption = faker.lorem.sentence();
|
||||||
const alt = faker.lorem.sentence();
|
const alt = faker.lorem.sentence();
|
||||||
const path = imageUrls[Math.floor(Math.random() * imageUrls.length)];
|
const path = imageUrls[Math.floor(Math.random() * imageUrls.length)];
|
||||||
|
const createdAt = faker.date.past({ years: 1 });
|
||||||
|
|
||||||
beerImageData.push({
|
beerImageData.push({
|
||||||
path,
|
path,
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const createNewBeerComments = async ({
|
|||||||
const content = faker.lorem.lines(5);
|
const content = faker.lorem.lines(5);
|
||||||
const user = users[Math.floor(Math.random() * users.length)];
|
const user = users[Math.floor(Math.random() * users.length)];
|
||||||
const beerPost = beerPosts[Math.floor(Math.random() * beerPosts.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;
|
const rating = Math.floor(Math.random() * 5) + 1;
|
||||||
|
|
||||||
beerCommentData.push({
|
beerCommentData.push({
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import type { BeerPost, User } from '@prisma/client';
|
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';
|
import DBClient from '../../DBClient';
|
||||||
|
|
||||||
interface BeerPostLikeData {
|
interface BeerPostLikeData {
|
||||||
beerPostId: string;
|
beerPostId: string;
|
||||||
likedById: string;
|
likedById: string;
|
||||||
|
createdAt: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
const createNewBeerPostLikes = async ({
|
const createNewBeerPostLikes = async ({
|
||||||
@@ -19,10 +22,11 @@ const createNewBeerPostLikes = async ({
|
|||||||
for (let i = 0; i < numberOfLikes; i++) {
|
for (let i = 0; i < numberOfLikes; i++) {
|
||||||
const beerPost = beerPosts[Math.floor(Math.random() * beerPosts.length)];
|
const beerPost = beerPosts[Math.floor(Math.random() * beerPosts.length)];
|
||||||
const user = users[Math.floor(Math.random() * users.length)];
|
const user = users[Math.floor(Math.random() * users.length)];
|
||||||
|
const createdAt = faker.date.past({ years: 1 });
|
||||||
beerPostLikeData.push({
|
beerPostLikeData.push({
|
||||||
beerPostId: beerPost.id,
|
beerPostId: beerPost.id,
|
||||||
likedById: user.id,
|
likedById: user.id,
|
||||||
|
createdAt,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ const createNewBeerPosts = async ({
|
|||||||
const user = users[Math.floor(Math.random() * users.length)];
|
const user = users[Math.floor(Math.random() * users.length)];
|
||||||
const beerType = beerTypes[Math.floor(Math.random() * beerTypes.length)];
|
const beerType = beerTypes[Math.floor(Math.random() * beerTypes.length)];
|
||||||
const breweryPost = breweryPosts[Math.floor(Math.random() * breweryPosts.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 abv = Math.floor(Math.random() * (12 - 4) + 4);
|
||||||
const ibu = Math.floor(Math.random() * (60 - 10) + 10);
|
const ibu = Math.floor(Math.random() * (60 - 10) + 10);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ const createNewBeerTypes = async ({ joinData }: CreateNewBeerTypesArgs) => {
|
|||||||
|
|
||||||
types.forEach((type) => {
|
types.forEach((type) => {
|
||||||
const user = users[Math.floor(Math.random() * users.length)];
|
const user = users[Math.floor(Math.random() * users.length)];
|
||||||
const createdAt = faker.date.past(1);
|
const createdAt = faker.date.past({ years: 1 });
|
||||||
|
|
||||||
beerTypeData.push({
|
beerTypeData.push({
|
||||||
name: type,
|
name: type,
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const createNewBreweryImages = async ({
|
|||||||
joinData: { breweryPosts, users },
|
joinData: { breweryPosts, users },
|
||||||
}: CreateBreweryImagesArgs) => {
|
}: CreateBreweryImagesArgs) => {
|
||||||
const prisma = DBClient.instance;
|
const prisma = DBClient.instance;
|
||||||
const createdAt = faker.date.past(1);
|
const createdAt = faker.date.past({ years: 1 });
|
||||||
const breweryImageData: BreweryImageData[] = [];
|
const breweryImageData: BreweryImageData[] = [];
|
||||||
|
|
||||||
// eslint-disable-next-line no-plusplus
|
// eslint-disable-next-line no-plusplus
|
||||||
|
|||||||
@@ -26,13 +26,14 @@ const createNewBreweryPostComments = async ({
|
|||||||
const { breweryPosts, users } = joinData;
|
const { breweryPosts, users } = joinData;
|
||||||
const prisma = DBClient.instance;
|
const prisma = DBClient.instance;
|
||||||
const breweryPostCommentData: BreweryPostCommentData[] = [];
|
const breweryPostCommentData: BreweryPostCommentData[] = [];
|
||||||
const createdAt = faker.date.past(1);
|
|
||||||
const rating = Math.floor(Math.random() * 5) + 1;
|
|
||||||
// eslint-disable-next-line no-plusplus
|
// eslint-disable-next-line no-plusplus
|
||||||
for (let i = 0; i < numberOfComments; i++) {
|
for (let i = 0; i < numberOfComments; i++) {
|
||||||
const content = faker.lorem.lines(3).replace(/\n/g, ' ');
|
const content = faker.lorem.lines(3).replace(/\n/g, ' ');
|
||||||
const user = users[Math.floor(Math.random() * users.length)];
|
const user = users[Math.floor(Math.random() * users.length)];
|
||||||
const breweryPost = breweryPosts[Math.floor(Math.random() * breweryPosts.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({
|
breweryPostCommentData.push({
|
||||||
content,
|
content,
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import type { BreweryPost, User } from '@prisma/client';
|
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';
|
import DBClient from '../../DBClient';
|
||||||
|
|
||||||
interface BreweryPostLikeData {
|
interface BreweryPostLikeData {
|
||||||
breweryPostId: string;
|
breweryPostId: string;
|
||||||
likedById: string;
|
likedById: string;
|
||||||
|
createdAt: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
const createNewBreweryPostLikes = async ({
|
const createNewBreweryPostLikes = async ({
|
||||||
@@ -21,10 +24,12 @@ const createNewBreweryPostLikes = async ({
|
|||||||
for (let i = 0; i < numberOfLikes; i++) {
|
for (let i = 0; i < numberOfLikes; i++) {
|
||||||
const breweryPost = breweryPosts[Math.floor(Math.random() * breweryPosts.length)];
|
const breweryPost = breweryPosts[Math.floor(Math.random() * breweryPosts.length)];
|
||||||
const user = users[Math.floor(Math.random() * users.length)];
|
const user = users[Math.floor(Math.random() * users.length)];
|
||||||
|
const createdAt = faker.date.past({ years: 1 });
|
||||||
|
|
||||||
breweryPostLikeData.push({
|
breweryPostLikeData.push({
|
||||||
breweryPostId: breweryPost.id,
|
breweryPostId: breweryPost.id,
|
||||||
likedById: user.id,
|
likedById: user.id,
|
||||||
|
createdAt,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
await DBClient.instance.breweryPostLike.createMany({
|
await DBClient.instance.breweryPostLike.createMany({
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ const createNewBreweryPosts = async ({
|
|||||||
locations.splice(locationIndex, 1); // Remove the location from the array
|
locations.splice(locationIndex, 1); // Remove the location from the array
|
||||||
const description = faker.lorem.lines(20).replace(/(\r\n|\n|\r)/gm, ' ');
|
const description = faker.lorem.lines(20).replace(/(\r\n|\n|\r)/gm, ' ');
|
||||||
const user = users[Math.floor(Math.random() * users.length)];
|
const user = users[Math.floor(Math.random() * users.length)];
|
||||||
const createdAt = faker.date.past(1);
|
const createdAt = faker.date.past({ years: 1 });
|
||||||
const dateEstablished = faker.date.past(40);
|
const dateEstablished = faker.date.past({ years: 40 });
|
||||||
|
|
||||||
breweryData.push({
|
breweryData.push({
|
||||||
name,
|
name,
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import { faker } from '@faker-js/faker';
|
import { faker } from '@faker-js/faker';
|
||||||
import { User } from '@prisma/client';
|
import { User } from '@prisma/client';
|
||||||
import { GeocodeFeature } from '@mapbox/mapbox-sdk/services/geocoding';
|
|
||||||
import DBClient from '../../DBClient';
|
import DBClient from '../../DBClient';
|
||||||
import geocode from '../../../config/mapbox/geocoder';
|
import canadianCities from '../util/canadianCities';
|
||||||
|
|
||||||
interface CreateNewLocationsArgs {
|
interface CreateNewLocationsArgs {
|
||||||
numberOfLocations: number;
|
numberOfLocations: number;
|
||||||
@@ -19,6 +18,7 @@ interface LocationData {
|
|||||||
coordinates: number[];
|
coordinates: number[];
|
||||||
address: string;
|
address: string;
|
||||||
postedById: string;
|
postedById: string;
|
||||||
|
createdAt: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
const createNewLocations = async ({
|
const createNewLocations = async ({
|
||||||
@@ -27,42 +27,25 @@ const createNewLocations = async ({
|
|||||||
}: CreateNewLocationsArgs) => {
|
}: CreateNewLocationsArgs) => {
|
||||||
const prisma = DBClient.instance;
|
const prisma = DBClient.instance;
|
||||||
|
|
||||||
const locationNames: string[] = [];
|
const locationData: LocationData[] = [];
|
||||||
|
|
||||||
// eslint-disable-next-line no-plusplus
|
// eslint-disable-next-line no-plusplus
|
||||||
for (let i = 0; i < numberOfLocations; i++) {
|
for (let i = 0; i < numberOfLocations; i++) {
|
||||||
locationNames.push(faker.address.cityName());
|
const randomIndex = Math.floor(Math.random() * canadianCities.length);
|
||||||
}
|
const randomCity = canadianCities[randomIndex];
|
||||||
|
|
||||||
const geocodePromises: Promise<GeocodeFeature>[] = [];
|
|
||||||
|
|
||||||
locationNames.forEach((locationName) => {
|
|
||||||
geocodePromises.push(geocode(locationName));
|
|
||||||
});
|
|
||||||
|
|
||||||
const geocodedLocations = await Promise.all(geocodePromises);
|
|
||||||
|
|
||||||
const locationData: LocationData[] = [];
|
|
||||||
|
|
||||||
geocodedLocations.forEach((geodata) => {
|
|
||||||
const randomUser = joinData.users[Math.floor(Math.random() * joinData.users.length)];
|
const randomUser = joinData.users[Math.floor(Math.random() * joinData.users.length)];
|
||||||
|
canadianCities.splice(randomIndex, 1);
|
||||||
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;
|
|
||||||
|
|
||||||
locationData.push({
|
locationData.push({
|
||||||
city,
|
address: randomCity.city,
|
||||||
stateOrProvince,
|
city: randomCity.city,
|
||||||
country,
|
coordinates: [randomCity.longitude, randomCity.latitude],
|
||||||
coordinates,
|
createdAt: faker.date.past({ years: 1 }),
|
||||||
address,
|
postedById: randomUser.id,
|
||||||
postedById,
|
stateOrProvince: randomCity.province,
|
||||||
|
country: 'Canada',
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
await prisma.location.createMany({ data: locationData, skipDuplicates: true });
|
await prisma.location.createMany({ data: locationData, skipDuplicates: true });
|
||||||
|
|
||||||
|
|||||||
@@ -31,11 +31,11 @@ const createNewUsers = async ({ numberOfUsers }: CreateNewUsersArgs) => {
|
|||||||
// eslint-disable-next-line no-plusplus
|
// eslint-disable-next-line no-plusplus
|
||||||
for (let i = 0; i < numberOfUsers; i++) {
|
for (let i = 0; i < numberOfUsers; i++) {
|
||||||
const randomValue = crypto.randomBytes(1).toString('hex');
|
const randomValue = crypto.randomBytes(1).toString('hex');
|
||||||
const firstName = faker.name.firstName();
|
const firstName = faker.person.firstName();
|
||||||
const lastName = faker.name.lastName();
|
const lastName = faker.person.lastName();
|
||||||
const username = `${firstName[0]}.${lastName}.${randomValue}`.toLowerCase();
|
const username = `${firstName[0]}.${lastName}.${randomValue}`.toLowerCase();
|
||||||
const email = faker.internet
|
const email = faker.internet
|
||||||
.email(firstName, randomValue, 'example.com')
|
.email({ firstName, lastName, provider: 'example.com' })
|
||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
|
|
||||||
const userAvailable =
|
const userAvailable =
|
||||||
@@ -51,7 +51,7 @@ const createNewUsers = async ({ numberOfUsers }: CreateNewUsersArgs) => {
|
|||||||
takenEmails.push(email);
|
takenEmails.push(email);
|
||||||
|
|
||||||
const dateOfBirth = faker.date.birthdate({ mode: 'age', min: 19 });
|
const dateOfBirth = faker.date.birthdate({ mode: 'age', min: 19 });
|
||||||
const createdAt = faker.date.past(1);
|
const createdAt = faker.date.past({ years: 4 });
|
||||||
|
|
||||||
const user = {
|
const user = {
|
||||||
firstName,
|
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