mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 18:52:06 +00:00
Feat: Implement mapbox for geocoding and location data for brewery posts
This commit is contained in:
15
src/prisma/migrations/20230424192859_/migration.sql
Normal file
15
src/prisma/migrations/20230424192859_/migration.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `location` on the `BreweryPost` table. All the data in the column will be lost.
|
||||
- Added the required column `address` to the `BreweryPost` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `city` to the `BreweryPost` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "BreweryPost" DROP COLUMN "location";
|
||||
ALTER TABLE "BreweryPost" ADD COLUMN "address" STRING NOT NULL;
|
||||
ALTER TABLE "BreweryPost" ADD COLUMN "city" STRING NOT NULL;
|
||||
ALTER TABLE "BreweryPost" ADD COLUMN "coordinates" FLOAT8[];
|
||||
ALTER TABLE "BreweryPost" ADD COLUMN "country" STRING;
|
||||
ALTER TABLE "BreweryPost" ADD COLUMN "stateOrProvince" STRING;
|
||||
@@ -96,7 +96,11 @@ model BeerType {
|
||||
model BreweryPost {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
location String
|
||||
city String
|
||||
stateOrProvince String?
|
||||
country String?
|
||||
coordinates Float[]
|
||||
address String
|
||||
beers BeerPost[]
|
||||
description String
|
||||
createdAt DateTime @default(now()) @db.Timestamptz(3)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import logger from '@/config/pino/logger';
|
||||
import logger from '../../../config/pino/logger';
|
||||
import cleanDatabase from './cleanDatabase';
|
||||
|
||||
cleanDatabase().then(() => {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { User } from '@prisma/client';
|
||||
import DBClient from '../../DBClient';
|
||||
import geocode from '../../../config/mapbox/geocoder';
|
||||
|
||||
interface CreateNewBreweryPostsArgs {
|
||||
numberOfPosts: number;
|
||||
@@ -21,6 +22,15 @@ const createNewBreweryPosts = async ({
|
||||
for (let i = 0; i < numberOfPosts; i++) {
|
||||
const name = `${faker.commerce.productName()} Brewing Company`;
|
||||
const location = faker.address.cityName();
|
||||
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const geodata = await geocode(location);
|
||||
|
||||
const city = geodata.text;
|
||||
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;
|
||||
const description = faker.lorem.lines(5);
|
||||
const user = users[Math.floor(Math.random() * users.length)];
|
||||
const createdAt = faker.date.past(1);
|
||||
@@ -30,7 +40,13 @@ const createNewBreweryPosts = async ({
|
||||
prisma.breweryPost.create({
|
||||
data: {
|
||||
name,
|
||||
location,
|
||||
|
||||
city,
|
||||
stateOrProvince,
|
||||
country,
|
||||
coordinates,
|
||||
address,
|
||||
|
||||
description,
|
||||
postedBy: { connect: { id: user.id } },
|
||||
createdAt,
|
||||
|
||||
@@ -26,7 +26,7 @@ import createNewBreweryPostLikes from './create/createNewBreweryPostLikes';
|
||||
|
||||
const users = await createNewUsers({ numberOfUsers: 1000 });
|
||||
const [breweryPosts, beerTypes] = await Promise.all([
|
||||
createNewBreweryPosts({ numberOfPosts: 100, joinData: { users } }),
|
||||
createNewBreweryPosts({ numberOfPosts: 30, joinData: { users } }),
|
||||
createNewBeerTypes({ joinData: { users } }),
|
||||
]);
|
||||
const beerPosts = await createNewBeerPosts({
|
||||
|
||||
Reference in New Issue
Block a user