-
Notifications
You must be signed in to change notification settings - Fork 2
API Docs
Welcome to the HackRU-Backend wiki! We'll be using Typescript, Node.js, and Serverless to set up our backend.
METHOD: POST
BODY REQUEST TYPE: JSON
EXAMPLE BODY REQUEST:
"email": "hacker@hackru.org",
"password": "plain-text-password"
Return:
| Situation | Return Value |
|---|---|
| Wrong password | {'statusCode': 403, message: 'Wrong password'} |
| Email doesn't exist in DB | {'statusCode': 403, message: 'Invalid email'} |
| Success Auth | {'statusCode': 200, message: 'Authentication Successful', token} |
| Internal error | {'statusCode': 500, message: 'Internal server error'} |
METHOD: POST
BODY REQUEST TYPE: JSON
EXAMPLE BODY REQUEST:
auth_email: "AuthUser@gmail.com" (this user must have role director/organizer),
auth_token: "authentication-token",
qr: "hacker-email@hackru.org",
event: "dinner",
again: true/false (optional) - whether an event can be checked in again (more than once)
RETURN:
| Situation | Return value |
|---|---|
| Auth token not valid | {'statusCode': 401, message: 'Unauthorized'} |
| Hacker (qr) not found | {'statusCode': 404, message: 'User not found'} |
| Auth user (auth_email) not found | {'statusCode': 404, message: 'Auth user not found'} |
| Auth user does not have roles organizer/director | {'statusCode': 401, message: 'Only directors/organizers can call this endpoint.'} |
| User tries to check into an event that can only be attended once and they have already checked into that event once before (again = false) | {'statusCode': 409, message: 'User already checked into event.'} |
| Success check-in | {'statusCode': 200, message: 'user successfully checked into event'} |
| Internal error | {'statusCode': 500, message: 'Internal server error'} |
METHOD: POST
BODY REQUEST TYPE: JSON
EXAMPLE BODY REQUEST:
{
email: 'hacker@hackru.org',
password: 'hackerPassword'
}
This is the minimum required JSON body for the /create endpoint which includes simply the Hacker email and password.
Return:
| Situation | Return value |
|---|---|
| Registration Time Has Passed | {'statusCode': 400, message: 'Registration is closed!'} |
| Creating a duplicate of existing user | {'statusCode': 400, message: 'Duplicate User'} |
| Successfully create user | {'statusCode': 200, message: 'User created!'} |
METHOD: POST
BODY REQUEST TYPE: JSON
EXAMPLE BODY REQUEST:
{
user_email: 'hacker@hackru.org',
auth_email: 'hacker@hackru.org',
auth_token: 'user.JWT.token',
updates: {
$set: {
last_name: 'sampleLastName'
}
}
}
This sample JSON request body represents changing the last name of the hacker, given they provide a valid auth token.
Return:
| Situation | Return value |
|---|---|
| Invalid auth token | {'statusCode': 401, message: 'Unauthorized'} |
| Auth user (auth_email) not found | {'statusCode': 404, message: 'Auth user not found'} |
| Auth user does not have a valid role to update (organizer/director/hacker) | {'statusCode': 401, message: 'Unauthorized. Auth user is not an organizer/director/hacker.'} |
| User to be updated not found | {'statusCode': 404, message: 'User to be updated not found.'} |
| User provided invalid updates: update registration status in a way that doesn't follow registration order, update password or _id | {'statusCode': 400, message: 'Bad updates.'} |
| Success update | {'statusCode': 200, message: 'User updated successfully'} |
| Internal error | {'statusCode': 500, message: 'Internal server error'} |
METHOD: POST
BODY REQUEST TYPE: JSON
EXAMPLE BODY REQUEST:
{
email: 'hacker@hackru.org',
auth_token: 'user JWT',
code: 'discord code from OAuth2',
redirect_uri: 'discord redirect uri'
}
Return:
| Situation | Return value |
|---|---|
| Invalid auth token | {'statusCode': 401, message: 'Unauthorized'} |
| User (email) not found | {'statusCode': 404, message: 'User not found'} |
| Success | {'statusCode': 200, message: 'Discord user verified', discordId: 'discord user id', discordUsername: 'discord username'} |
| Internal error | {'statusCode': 500, message: 'Internal Server Error', error: error} |
If successful, user in database gets updated:
{
discord: {
user_id: 'discord user id',
username: 'discord username',
access_token: 'discord auth access token',
refresh_token: 'discord auth refresh token',
expires_at: 'timestamp (ms) when token expires'
}
}
METHOD: POST
BODY REQUEST TYPE: JSON
EXAMPLE BODY REQUEST:
{
"auth_email": "hacker@hackru.org",
"auth_token": "user.JWT.token",
"email": "lookup@hackru.org"
}
RETURN:
| Situation | Return value |
|---|---|
| Invalid auth token | {'statusCode': 401, message: 'Unauthorized'} |
| Auth user (auth_email) not found | {'statusCode': 404, message: 'Auth user not found.'} |
| Auth user does not have a valid role (hacker/director/organizer) | {'statusCode': 401, message: 'Unauthorized. Auth user is not an organizer/director/hacker.'} |
| Hacker tries to look up information for a different user | {'statusCode': 403, message: 'Hackers can only look up their own information.'} |
| Look-up user (email) not found | {'statusCode': 404, message: 'Look-up user not found.'} |
| Success | {'statusCode': 200, body: [User Object]} |
| Internal error | {'statusCode': 500, message: 'Internal server error.', error: [Error details]} |
METHOD: POST
BODY REQUEST TYPE: JSON
EXAMPLE BODY REQUEST:
{
"email": "hacker@hackru.org",
"auth_token": "user.JWT.token"
}
RETURN:
| Situation | Return value |
|---|---|
| Invalid auth token | {'statusCode': 401, message: 'Unauthorized'} |
| User has already submitted a resume before | {'statusCode': 400, message: 'You already submitted a resume'} |
| Success | {'statusCode': 200, body: {url, message: 'Upload the resume through the generated URL.'}} |
| Internal error | {'statusCode': 500, message: 'Internal server error.', error: [Error details]} |
If this endpoint returns the success case, there will be a URL in the return body. You can call that URL, with PUT http method, and attach your PDF file in the body as type 'Binary.' Do keep in mind that it ONLY accepts PDF files.
METHOD: POST
BODY REQUEST TYPE: JSON
EXAMPLE BODY REQUEST:
{
"email": "hacker@hackru.org",
"auth_token": "user.JWT.token"
}
RETURN:
| Situation | Return value |
|---|---|
| Invalid auth token | {'statusCode': 401, message: 'Unauthorized'} |
| User has already submitted a waiver before | {'statusCode': 400, message: 'You already submitted a waiver'} |
| Success | {'statusCode': 200, body: {url, message: 'Upload the waiver through the generated URL.'}} |
| Internal error | {'statusCode': 500, message: 'Internal server error.', error: [Error details]} |
If this endpoint returns the success case, there will be a URL in the return body. You can call that URL, with PUT http method, and attach your PDF file in the body as type 'Binary.' Do keep in mind that it ONLY accepts PDF files.
METHOD: POST
BODY REQUEST TYPE: JSON
EXAMPLE BODY REQUEST:
{
"email": "hacker@hackru.org",
"reset_token": "tokenFromEmail",
"new_password": "iLoveHackRU"
}
RETURN:
| Situation | Return value |
|---|---|
| User did not request a password change | {'statusCode': 403, message: 'You did not request a password change'} |
| Invalid reset token | {'statusCode': 401, message: 'Reset token is invalid'} |
| Reset token has expired | {'statusCode': 401, message: 'Reset token has expired'} |
| Successful password update | {'statusCode': 200, message: 'Password reset successful'} |
| Internal error | {'statusCode': 500, message: 'Internal server error.', error: [Error details]} |