-
Notifications
You must be signed in to change notification settings - Fork 1
Backend API
The pathways backend allows for persistent memory of pathways, criteria, and eventually users. It follows the MERN stack (MongoDB, ExpressJS, React, Node). Since the database can not be run in browser a new server is required to connect to the database. The React frontend will make calls to the server API (using something like axios). The API will link the client requests to persisting the data in the database.
MongoDB is a document-based NoSQL database which stores data as JSON. The Mongoose library is available for a Node app to connect to a MongoDB. Instructions on downloading and running MongoDB can be found here.
Collections in Mongo are equivalent to Tables in SQL based databases. There are 4 collections - Pathway, Criteria, User, and Workspace. The schemas for each collection are as follows:
const Pathway = new Schema({
id: String, // Pathway ID (not MongoDB) – pathway.id
userid: String, // ID for the user who owns this pathway
pathway: Object // The actual pathway JSON
});
const Criteria = new Schema({
id: String, // Criteria ID (not MongoDB) – criteria.id
userid: String, // ID for the user who owns this criteria
criteria: Object // The actual criteria JSON
});
const User = new Schema({
userid: String, // Unique ID for this user
email: String,
password: String // Hashed password (bcrypt)
});
const Workspace = new Schema({
userid: String, // ID for the user who owns this workspace
name: String, // Name for the workspace
initials: String, // 2 character abbreviation
admin: String[], // List of user IDs w/ admin privileges
member: String[], // List of user IDs w/ member privileges
criteria: String[], // List of criteria IDs in workspace
pathway: String[], // List of pathway IDs in workspace
});
Note: Before user authentication is implemented the User
and Workspace
collections will not exist. The userid
property on Pathway
and Criteria
will also not exist yet.
Service | Method | Description |
---|---|---|
/pathway?id={pathwayid}&user={userid}&workspace={workspaceid} |
GET |
Gets a list of all the pathways matching the conditions. Each query param is optional. Once user authentication is added it will only return pathways which the user has access to. Returns 200 OK on success or 403 FORBIDDEN. |
/pathway |
POST |
Creates a new pathway in the database. Body is the new Pathway. Returns 201 CREATED on success. |
/pathway/id |
PUT |
Updates the specific pathway. Body is the new Pathway. Returns 200 OK on success, 403 FORBIDDEN if not authorized, and 404 NOT FOUND if pathway with id id does not exist. |