This is the API Node.js server code for the app DiaGram written for CPEN-321
Creates a patient user
-
URL
/signup -
Method:
POST -
URL Body
Required:
username: <String>(5-32 characters)
password: <String>(8-64 characters)
accessCode: <String>Optional:
firstName: <String>
lastName: <String>
medications: <String>
recentProcedures: <String>
conditions: <String> -
Success Response:
- Code:
200
Content:
{ jwt: <String>, user: { _id: <String>, username: <String>, userType: <String>, firstName: <String>, lastName: <String>, medications: <String>, recentProcedures: <String>, conditions: <String>, } }
- Code:
-
Error Response:
- Code:
400BAD REQUEST
Content:
{ errors : [ "DUPLICATE_USERNAME", "INVALID_ACCESS_CODE", "INVALID_USERNAME", "INVALID_PASSWORD" ] }
- Code:
Creates a doctor user
-
URL
/signup -
Method:
POST -
URL Body
Required:
username: <String>(5-32 characters)
password: <String>(8-64 characters)
accessCode: <String>Optional:
firstName: <String>
lastName: <String>
experience: <String>
department: <String>
specializations: <String> -
Success Response:
- Code:
200
Content:
{ jwt: <String>, user: { _id: <String>, username: <String>, userType: <String>, firstName: <String>, lastName: <String>, experience: <String>, department: <String>, specializations: <String>, } }
- Code:
-
Error Response:
- Code:
400BAD REQUEST
Content:
{ errors : [ "DUPLICATE_USERNAME", "INVALID_ACCESS_CODE", "INVALID_USERNAME", "INVALID_PASSWORD" ] }
- Code:
Grant session to a patient user given the username and password
-
URL
/login -
Method:
POST -
URL Body
Required:
username: <String>
password: <String> -
Success Response:
- Code:
200
Content:
{ jwt: <String>, user: { _id: <String>, username: <String>, userType: <String>, firstName: <String>, lastName: <String>, medications: <String>, recentProcedures: <String>, conditions: <String>, } }
- Code:
-
Error Response:
- Code:
400BAD REQUEST
Content:
{ errors : [ "INVALID_CREDENTIALS" ] }
- Code:
Grant session to a doctor user given the username and password
-
URL
/login -
Method:
POST -
URL Body
Required:
username: <String>
password: <String> -
Success Response:
- Code:
200
Content:
{ jwt: <String>, user: { _id: <String>, username: <String>, userType: <String>, firstName: <String>, lastName: <String>, experience: <String>, department: <String>, specializations: <String>, } }
- Code:
-
Error Response:
- Code:
400BAD REQUEST
Content:
{ errors : [ "INVALID_CREDENTIALS" ] }
- Code:
Get posts for app feed
-
URL
/posts -
Method:
GET -
URL HEADER
Required:
Authorization: "Bearer ${jwt}" -
Success Response:
- Code:
200
Content:
[ { _id: <String>, tite: <String>, body: <String>, userId: <String>, userType: enum { patient, doctor }, private: <Boolean>, comments: [ { body: <String>, userId: <String>, docLastName: <String>, userType: enum { patient, doctor }, createdAt: <Timestamp> }, ... ], createdAt: <Timestamp>, updatedAt: <Timestamp> }, ... ]
- Code:
-
Error Response:
- Code:
401UNAUTHORIZED
Content:
{ errors : [ "UNAUTHORIZED", "SESSION_EXPIRED" ] }
- Code:
Get single post
-
URL
/posts?post_id=<postId> -
Method:
GET -
URL HEADER
Required:
Authorization: "Bearer ${jwt}" -
Success Response:
- Code:
200
Content:
[ { _id: <String>, tite: <String>, body: <String>, userId: <String>, userType: enum { patient, doctor }, private: <Boolean>, comments: [ { body: <String>, userId: <String>, docLastName: <String>, userType: enum { patient, doctor }, createdAt: <Timestamp> }, ... ], createdAt: <Timestamp>, updatedAt: <Timestamp> } ]
- Code:
-
Error Response:
- Code:
401UNAUTHORIZED
Content:
{ errors : [ "UNAUTHORIZED", "SESSION_EXPIRED" ] }
- Code:
Make a new post
-
URL
/posts -
Method:
POST -
URL HEADER
Required:
Authorization: "Bearer ${jwt}" -
URL Body
Required:
title: <String>
body: <String>Optional:
private: <Boolean> -
Success Response:
- Code:
200
Content:
{ _id: <String>, tite: <String>, body: <String>, userId: <String>, userType: enum { patient, doctor }, private: <Boolean>, comments: [], createdAt: <Timestamp>, updatedAt: <Timestamp> }
- Code:
-
Error Response:
-
Code:
400BAD REQUEST
Content:
{ errors : [ "EMPTY_TITLE", "EMPTY_BODY" ] } -
Code:
401UNAUTHORIZED
Content:
{ errors : [ "UNAUTHORIZED", "SESSION_EXPIRED" ] }
-
Comments on a post, only permissible by doctor userType and OP
-
URL
/posts/:post_id/comments -
Method:
POST -
URL HEADER
Required:
Authorization: "Bearer ${jwt}" -
URL Body
Required:
body: <String> -
Success Response:
- Code:
200
Content:
{ _id: <String>, tite: <String>, body: <String>, userId: <String>, userType: enum { patient, doctor }, private: <Boolean>, comments: [ {newly added comment} ], createdAt: <Timestamp>, updatedAt: <Timestamp> }
- Code:
-
Error Response:
-
Code:
400BAD REQUEST
Content:
{ errors : [ "POST_NOT_FOUND" ] } -
Code:
401UNAUTHORIZED
Content:
{ errors : [ "UNAUTHORIZED", "SESSION_EXPIRED" ] } -
Code: 403 FORBIDDEN
Content:
{ errors : [ "WRONG_USER" ] }
-
Get posts that the user is following. Posts are automatically followed by a user they make the post, and followed by a doctor if they comment on it.
-
URL
/posts/followed -
Method:
GET -
URL HEADER
Required:
Authorization: "Bearer ${jwt}" -
Success Response:
- Code:
200
Content:
[ { _id: <String>, tite: <String>, body: <String>, userId: <String>, userType: enum { patient, doctor }, private: <Boolean>, comments: [ { body: <String>, userId: <String>, docLastName: <String>, userType: enum { patient, doctor }, createdAt: <Timestamp> }, ... ], createdAt: <Timestamp>, updatedAt: <Timestamp> }, ... ]
- Code:
edit the patients profile information, returns updated information
-
URL
/users -
Method:
PUT -
URL HEADER
Required:
Authorization: "Bearer ${jwt}" -
Body
Optional:
firstName: <String>
lastName: <String>
medications: <String>
recentProcedures: <String>
conditions: <String> -
Success Response:
- Code:
200
Content:
{ _id: <String> username: <String> userType: enum { patient, doctor }, firstName: <String> lastName: <String> medications: <String> recentProcedures: <String> conditions: <String> }
- Code:
-
Error Response:
- Code:
401UNAUTHORIZED
Content:
{ errors : [ "UNAUTHORIZED", "SESSION_EXPIRED" ] }
- Code:
edit the doctor's profile information, returns updated information
-
URL
/users -
Method:
PUT -
URL HEADER
Required:
Authorization: "Bearer ${jwt}" -
Body
Optional:
firstName: <String>
lastName: <String>
experience: <String>
specializations: <String>
department: <String> -
Success Response:
- Code:
200
Content:
{ _id: <String> username: <String> userType: enum { patient, doctor }, firstName: <String> lastName: <String> experience: <String> specializations: <String> department: <String> }
- Code:
-
Error Response:
- Code:
401UNAUTHORIZED
Content:
{ errors : [ "UNAUTHORIZED", "SESSION_EXPIRED" ] }
- Code:
get the profile information of another user
-
URL
/users/:user_id -
Method:
GET -
URL HEADER
Required:
Authorization: "Bearer ${jwt}" -
Success Response:
-
Code:
200
Content:If profile is of a doctor{ _id: <String> username: <String> userType: enum { patient, doctor }, firstName: <String> lastName: <String> experience: <String> department: <String> specializations: <String> }If profile is another patient{ _id: <String> userType: enum { patient, doctor }, medications: <String> recentProcedures: <String> conditions: <String> }
-
-
Error Response:
-
Code:
400user_id provided doesn't exist
Content:
{ errors : [ "INVALID_USER_ID" ] } -
Code:
401UNAUTHORIZED
Content:
{ errors : [ "UNAUTHORIZED", "SESSION_EXPIRED" ] }
-
get the profile information of another user
-
URL
/users/:user_id -
Method:
GET -
URL HEADER
Required:
Authorization: "Bearer ${jwt}" -
Success Response:
-
Code:
200
Content:If profile is of another doctor{ _id: <String> username: <String> userType: enum { patient, doctor }, firstName: <String> lastName: <String> experience: <String> department: <String> specializations: <String> }If profile is a patient{ _id: <String> username: <String> userType: enum { patient, doctor }, firstName: <String> lastName: <String> medications: <String> recentProcedures: <String> conditions: <String> }
-
-
Error Response:
-
Code:
400user_id provided doesn't exist
Content:
{ errors : [ "INVALID_USER_ID" ] } -
Code:
401UNAUTHORIZED
Content:
{ errors : [ "UNAUTHORIZED", "SESSION_EXPIRED" ] }
-
-
INTERNAL SERVER ERROR
happens when there is something wrong with the server internally- Code:
500
Content:
{ errors : [ "INTERNAL_SERVER_ERROR" ] }
- Code:
-
NOT FOUND
happens the URL does not exist- Code: 404
Content:
{ errors : [ "NOT_FOUND" ] }
- Code: 404