Hi, welcome to the "projects-api" repo. Please use this readme as an introduction to get you started on working with this repo.
Additional info can also be found in the Engineering Wiki section of Notion.
To get started, please follow these instructions:
-
Ensure you have the
.env
file set up. Please place it in the root directory of this repo (same directory-level as thisREADME.md
) -
Check the
package.json
and make sure yourPORT
is configured properly. It should read:
// Located in package.json, 'scripts', 'start'
// for PORT=30##, # can be any integer from 0-9. (i.e. 3004)
// Windows
set PORT=30## && react-scripts start
// Mac & Unix
PORT=30## react-scripts start
You should probably make sure this is the same PORT
used in the other projects when they need to refer to this repo.
-
Make sure that you have access to Naya npm packages. Login with same email using
npm login
. -
Install dependencies using
npm install
oryarn install
-
Run with
npm start
oryarn start
to start in production environment, Run withnpm run dev
oryarn run dev
to start in development environment
For information about all the CRUD actions you can perform in this repo, please refer to our wiki.
Here are some of the folders/files we will talk about in this section:
repo
|--> actions/
|--> middlewares/
|--> models/
|--> routes/
|--> services/
|--> .env
There are other folders and files found in this repo (such as src/public/
) that will not be discussed in this chapter (most of them are used for configuration)
Here we will go over the general purposes for each of the folder/file (mentioned above).
-
actions/
src |--> actions/
This folder is used to contain all the side-effect actions that occur from a route. It is common to have CRUD requests to other APIs in this folder.
Example: After an ecosystem user has updated their estimation, we would want to email an admin about this update. This folder will contain the logic used to send the email.
-
middleware/
src |--> middleware/
This folder is used to contain all custom middlewares used in this repo. For middleware initialization from external packages (npm), please initialize in the 'services' folder.
-
models/
src |--> models/
This folder is used to contain all the Mongoose schema's used throughout this repo. If necessary, sub-directories can be created for organization purposes.
-
routes/
src |--> routes/
This folder contains all routes available from this repo. If necessary, sub-directories can be created for organization purposes.
NOTE: Before writing a new route, please refer to the wiki and see if there are existing routes that will satisfy your requirements.
-
services/
src |--> services/
This folder contains all external service initialization. (i.e. Firebase-admin, SendGrid)
-
.env
repo |--> .env
.env
is for our sensitive constants, you can find a copy for local usage in our Notion
All errors that occurs in a route should return a response with this template. You can extend this template and add additional fields but this is the bare minimum.
{
status: false,
message // describes why the request failed
}
The message should be of type string
and should be descriptive enough to highlight the problem with the developer's request. The message can also provide hints for the developer on how to fix their request.
As a rule of thumb, there should be error messsages if:
- a request payload is missing required fields
- failed database query
- failed validation check of any data (i.e. non-valid email is provided for a sign-up)
Also remember to return
your error messages if it is not at the end of a closure.
if (!user) // this will throw an error
res.json({ status: false, message: 'No user found with the provided credentials. Invalid email/uid' })
if (!user) // this will not throw an error
return res.json({ status: false, message: 'No user found with the provided credentials. Invalid email/uid' })
TODO: Standardize status codes? Do we even need status codes as it's redundant?
Here are some helpful links to wikis that cover topics missed in this readme:
TBD? What rules for dependencies?