This project is set up with NestJS, which will be the primary back-end framework you will be working with.
Your abilities will be tested in the following:
- Typescript
- NodeJS
- MongoDB
- REST API
- Detail Orientation
When you are done with your project, please push to your personal github account, and share the link with the person who is administering this test.
Your tasks will consist of the following:
Before getting started, you will need to be running NodeJS version 12 or 14.
I recommend installing Node Version Manager or NVM for short.
Please google steps for installing for your environment (ie. mac, windows, linux, etc.).
Once installed, please install node v12 and set as your default.
nvm install 12.22.12
Then set as your default node version
nvm alias default 12.22.12
Confirm you are running version 12
node -v
If you haven't already, clone the repo:
git clone https://github.com/brothatru/jr-nestjs-user-api-test.git
Install dependencies
cd <project_folder>
npm install
Download and install the community edition of MongoDB from https://www.mongodb.com/docs/manual/installation/.
After installing, you'll want to start the service.
Next, download and install Studio 3T. This is a GUI for connecting to your Mongo database, and will allow you to query your database for easier debugging and troubleshooting.
Open up Studio 3T and connect to localhost:27017.
Once connected, go ahead and create a new database named "soldcom".
Once you've got Node and MongoDB installed, you can go ahead and start the app.
nest start --watch
This will start the project in watch mode at http://localhost:9001/docs#/, so any file changes will immediately take effect in the browser.
The users collection should automatically already be created on app start.
You may need to refresh Studio 3T.
If not, go ahead and create manually using Studio 3T.
I've set up a User Controller and set up the following endpoints already:
- POST /user/create
- Save a new user into the database
- DELETE /user/{_id}
- Delete a user by mongo object id
- GET /user/{_id}
- Find a user by mongo object id
The following methods are stubbed, and you will need to fill in the logic by making changes to both the User Controller and the User Service:
- PATCH /user/update/{_id}
- This endpoint should allow you to partially update an EXISTING user by firstname, lastname, password, username, AND any combination of these.
- GET /user/username/{username}
- Find a user by username
- POST /user/search
- Search a user by any combination of these fields:
- firstname
- lastname
- username
- If NOT found, a 404 HTTP Exception should be thrown
- Search a user by any combination of these fields:
For more info on controllers and services, you can find more in the NestJs Docs:
Seed test data from users.csv using for loop.
The seed method in your User Controller has already been stubbed.
This method should save all users from the CSV file into our local mongo database.
Feel free to use existing service methods OR create your own.
Typically, REST APIs have validation so that non-valid input is blocked.
ie. Invalid email should NOT be saved when creating a user
In NestJs, this is typically set up using class validators in DTO objects (Data Transfer Objects). I've set up a basic example to prevent empty data and non-strings from being entered. See create-user.dto.ts.
Your task is to add a new user field named "email".
This field will need to enforce valid emails when creating new users and updating existing users.
Don't worry about filling in previous existing user emails.
More info on validation can be found here: https://docs.nestjs.com/techniques/validation
If you have any questions about anything, please reach out to the person or team that administered this test to you.
Other than that, happy coding!