An open-sourced backend service for Resell.
Make sure that npm
installed (nvm
is recomended to manage node versions.)
Depending on preference, either run yarn install
or npm install
to ensure
all required dependencies are installed. Copy the .env_template
to either a
.env
file , and update with necessary credentials. Sourcing the file is not
necessary.
Steps to install Postgres:
- Update Homebrew
brew update
- Install and start
brew install postgresql
brew services start postgresql
- Initialize DB
initdb /usr/local/var/postgres
- Create User In order to run the create and alter commands, you must be inside psql.
psql postgres
create user postgres with password 'postgres';
alter user postgres with superuser;
create database "resell-dev";
In order to connect to the database, follow these steps:
- Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Update Homebrew to ensure you have the latest information
brew update
- Install pgAdmin
brew install --cask pgadmin4
Open pgAdmin and configure the connection using the defined user and password.
To create/update the database objects, run:
npm run db:migrate
This project includes a mechanism for seeding consistent data for the development environment using TypeORM and typeorm-seeding. The seeders generate users, posts, feedback, reviews, reports, and requests, ensuring all developers work with the same data set.
To seed the database for development, use the following command:
npm run db:seed
The seeding script checks the environment to ensure it only runs in the development environment. If the environment variable IS_PROD
is set to "true"
, the seeding process will be skipped to prevent accidental execution in production.
The factories and seeders are configured to generate consistent data that is shared across all development environments. This allows developers to have predictable data while working on the project.
- Factories: Each entity has a corresponding factory that generates consistent data using an
index
to differentiate between records. - Seeders: The main seeder script (
SeedInitialData
) handles the creation of all entities, ensuring relationships are properly established.
- Resetting Data: The seeder script will delete all existing data for users, posts, feedback, reviews, reports, and requests before creating new records. This ensures a clean slate for each run.
- Relationships: Factories take into consideration entity relationships, such as assigning posts to users, feedback entries to users, and creating reports and reviews between users.
This consistent seeding process ensures that all developers work with the same initial data, making it easier to test features and maintain alignment across the team.
To run in a development environment, open two terminal tabs. In one, run either
yarn dev
if using yarn, or npm run dev
otherwise. This command will
watch the TypeScript files for changes and recompile the JavaScript whenever an
update occurs. If the compilation succeeds, it will restart the server with the
changes applied.