Feat: Implement infinite scrolling brewery comment section

Refactor beer comment schemas to work on brewery comments as well. Add robots.txt to block crawling for now.
This commit is contained in:
Aaron William Po
2023-04-30 13:43:51 -04:00
parent 99e3eba7d6
commit b3b1d5b6d1
27 changed files with 670 additions and 261 deletions

View File

@@ -30,7 +30,7 @@ const createNewBreweryPostComments = async ({
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(5);
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)];

View File

@@ -1,8 +1,8 @@
import argon2 from 'argon2';
// eslint-disable-next-line import/no-extraneous-dependencies
import { faker } from '@faker-js/faker';
import crypto from 'crypto';
import DBClient from '../../DBClient';
import { hashPassword } from '../../../config/auth/passwordFns';
interface CreateNewUsersArgs {
numberOfUsers: number;
@@ -21,24 +21,40 @@ interface UserData {
const createNewUsers = async ({ numberOfUsers }: CreateNewUsersArgs) => {
const prisma = DBClient.instance;
const hashedPasswords = await Promise.all(
Array.from({ length: numberOfUsers }, () => argon2.hash(faker.internet.password())),
);
const password = 'passwoRd!3';
const hash = await hashPassword(password);
const data: UserData[] = [];
const takenUsernames: string[] = [];
const takenEmails: string[] = [];
// eslint-disable-next-line no-plusplus
for (let i = 0; i < numberOfUsers; i++) {
const randomValue = crypto.randomBytes(4).toString('hex');
const randomValue = crypto.randomBytes(1).toString('hex');
const firstName = faker.name.firstName();
const lastName = faker.name.lastName();
const username = `${firstName[0]}.${lastName}.${randomValue}`;
const email = faker.internet.email(firstName, randomValue, 'example.com');
const hash = hashedPasswords[i];
const username = `${firstName[0]}.${lastName}.${randomValue}`.toLowerCase();
const email = faker.internet
.email(firstName, randomValue, 'example.com')
.toLowerCase();
const userAvailable =
!takenUsernames.includes(username) && !takenEmails.includes(email);
if (!userAvailable) {
i -= 1;
// eslint-disable-next-line no-continue
continue;
}
takenUsernames.push(username);
takenEmails.push(email);
const dateOfBirth = faker.date.birthdate({ mode: 'age', min: 19 });
const createdAt = faker.date.past(1);
const user = { firstName, lastName, email, username, dateOfBirth, createdAt, hash };
data.push(user);
}

View File

@@ -28,30 +28,32 @@ import logger from '../../config/pino/logger';
logger.info('Users created successfully.');
const locations = await createNewLocations({
numberOfLocations: 150,
numberOfLocations: 1600,
joinData: { users },
});
logger.info('Locations created successfully.');
const [breweryPosts, beerTypes] = await Promise.all([
createNewBreweryPosts({ numberOfPosts: 130, joinData: { users, locations } }),
createNewBreweryPosts({ numberOfPosts: 1500, joinData: { users, locations } }),
createNewBeerTypes({ joinData: { users } }),
]);
logger.info('Brewery posts and beer types created successfully.');
const beerPosts = await createNewBeerPosts({
numberOfPosts: 200,
numberOfPosts: 3000,
joinData: { breweryPosts, beerTypes, users },
});
logger.info('Beer posts created successfully.');
const [beerPostComments, breweryPostComments] = await Promise.all([
createNewBeerPostComments({
numberOfComments: 45000,
numberOfComments: 100000,
joinData: { beerPosts, users },
}),
createNewBreweryPostComments({
numberOfComments: 45000,
numberOfComments: 100000,
joinData: { breweryPosts, users },
}),
]);
@@ -59,11 +61,11 @@ import logger from '../../config/pino/logger';
const [beerPostLikes, breweryPostLikes] = await Promise.all([
createNewBeerPostLikes({
numberOfLikes: 10000,
numberOfLikes: 100000,
joinData: { beerPosts, users },
}),
createNewBreweryPostLikes({
numberOfLikes: 10000,
numberOfLikes: 100000,
joinData: { breweryPosts, users },
}),
]);
@@ -71,11 +73,11 @@ import logger from '../../config/pino/logger';
const [beerImages, breweryImages] = await Promise.all([
createNewBeerImages({
numberOfImages: 100000,
numberOfImages: 20000,
joinData: { beerPosts, users },
}),
createNewBreweryImages({
numberOfImages: 100000,
numberOfImages: 20000,
joinData: { breweryPosts, users },
}),
]);