Simple project to import contacts from a CSV file.
- Node 18
- Docker (PostgreSQL and Redis)
In order to run the project, you need to run the following commands:
mv .env.example .env
npm ci
npm test
npm run build # This is required to RUN the compiled code
npm run db:up # Remove the -d flag in order to avoid running in background
npm run db:migrate
npm run db:seed # This command adds the test user to the database
The project is composed for two processes: the server and the worker.
npm run start # This command runs the server
npm run start-consumer # This command runs the worker
There are 4 sample files:
Files | Result |
---|---|
failed.csv | Failed |
mixed.csv | Finished |
success.csv | Finished |
different_mapping.csv | Finished |
All but different_mapping.csv
use the same mapping and it is hardcoded in the Import form for the sake of simplicity. In order to use a different mapping, just fill out the form with the correct headers.
The queue has a delay of 3 seconds in order to simulate a long running process. This is done in order to test the queue and the worker. Also, we can update the Imports page and see how each import is updated.
There is an issue with Bull
when running on Docker. Didn't have the time to look into it.
The most critical parts of the project are well tested, but all tests are unit tests.
We could save the contacts and logs in batches so we don't have to make a lot of queries to the database.
It would be nice to get the first row of the CSV file in the frontend and use it to fill out the form. So instead of writing the headers manually, we could just click on the correct field.