Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL API #159

Merged
merged 14 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,13 @@ jspm_packages
*.js.map
.vscode/
uploads/

# Build Artifacts
server/config/config.json
server/config/questions\.schema\.d\.ts
api.graphql.types.ts
server/routes/api/api.graphql.types.ts

# Editors!
.nvimlog
.#*
54 changes: 54 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# APIs

## Current REST API

### `user.ts`
All routes mounted under `/api/user/:id`

- POST `/application/:branch`
- Submits or edits if already submitted the requested application branch
- *Note:* should actually be HTTP PUT
- DELETE `/application/:branch`
- Deletes previously submitted application branch
- POST `/confirmation/:branch`
- Identical to POST `/application/:branch` but for confirmation branches
- *Note:* should also actually be HTTP PUT
- DELETE `/confirmation/:branch`
- Identical to DELETE `/application/:branch` but for confirmation branches
- POST `/status` (**admin only**)
- Sets user's accepted status to `true` or `false`
- POST `/send_acceptances` (**admin only**, ignores `id` param)
- Sends accepted notification emails to users who have been accepted and not yet notified
- GET `/export` (**admin only**, ignores `id` param, requires update post-HackGT Catalyst)
- Downloads .zip file containing `.csv` files of current user data
- POST `/team/create/:teamName`
- Creates a team with the specified name and places the user into it`
- POST `/team/join/:teamName`
- Adds the user to the specified team
- POST `/team/leave`
- Removes the user from any team they are on
- POST `/team/rename/:newTeamName`
- Renames the team that the user is currently on if they are the team's leader

### `settings.ts`
All routes mounted under `/api/settings`

- GET `/application_availability`
- Gets the current application and confirmation open and close times
- PUT `/application_availability` (**admin only**)
- Sets the current application and confirmation open and close times
- GET `/teams_enabled`
- Gets a boolean value representing whether teams are enabled
- PUT `/teams_enabled` (**admin only**)
- Sets the boolean value representing whether teams are enabled
- GET `/branch_roles` (**admin only**)
- Returns the question branches from `questions.json` sorted into the categories `noop`, `applicationBranches`, and `confirmationBranches`.
- PUT `/branch_roles` (**admin only**)
- Sets the role of the question branches from `questions.json` as one of `noop`, `application`, or `confirmation`.
- GET `/email_content/:type` (**admin only**)
- Returns the Markdown content of the email type specified
- PUT `/email_content/:type` (**admin only**)
- Sets the Markdown content of the email type specified
- POST `/email_content/:type/rendered` (**admin only**)
- Returns rendered HTML and text from Markdown input using the same Markdown engine used for generating emails
- Used for live preview of rendered Markdown in admin panel
106 changes: 106 additions & 0 deletions api.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
schema {
query: Query
}

# The root query type
type Query {
# Retrieve user through a user ID or through the token passed to
# Query. Leave id empty if you'd like to view the currently logged in
# user.
user(id: ID): User
# All the users in the database, useful for polling for new user information.
# This is paginated, n is the number of results, and last_id is the last ID
# seen from the latest page retrieved, if you want the first page leave this out.
users(last_id: ID, n: Int!): [User!]!
# Search through a user's name and email through regex
search_user(search: String!, offset: Int!, n: Int!): [User!]!
# All possible question branches
question_branches: [String!]!
# All possible question names, or names of question in a branch
question_names(branch: String): [String!]
}

# Registration info about the user
type User {
# User ID, valid across the entire system
id: ID!

# User's full name
name: String!
# User's email
email: String!
# If the user's email is a verified email
email_verified: Boolean!

# If the user has applied to the event
applied: Boolean!
# If the user has been accepted to the event
accepted: Boolean!
# If the user has been accepted and notified of his or her acceptance
accepted_and_notified: Boolean!
# If the user has indicated that he or she is attending
attending: Boolean!

# A users application phase answers
# null if user has not filled out this phase
application: Branch

# A users confirmation phase answers
# null if user has not filled out this phase
confirmation: Branch

# Get the answer to one of the questions asked of this user.
# If branch is not given, find this question name in any branch.
question(name: String!): FormItem

# What team, if any, is the user a part of?
team: Team
}

# A filled out form (application / confirmation form)
type Branch {
# What type of application did the user fill out (mentor, participant, etc.)
# when going through the form?
type: String!
# A key-value list of questions and answers from the confirmation application
data: [FormItem!]!
# Start of application as some RFC's date string
start_time: String
# Submit time of application as some RFC's date string
submit_time: String
}

# Application teams
type Team {
# ID of the Team
id: ID!
}

# Entries to various forms (application, confirmation, etc.)
type FormItem {
# Name of the question / form item
name: String!
# Type of form item (textbox, checkbox, phone no.)
type: String!
# Value (if just one string)
value: String
# Values (if many selections are applicable, like checkbox)
values: [String!]
# File if type contains a file
file: File
}

# Uploaded file
type File {
# The original name of the uploaded file
original_name: String!
# The file's encoding
encoding: String!
# The file's mimetype
mimetype: String!
# The path to the file in S3
path: String!
# The size of the file in bytes
size: Int!
}

17 changes: 17 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
SOURCE_DIR=$(readlink -f "${BASH_SOURCE[0]}")
cd "$(dirname "$SOURCE_DIR")" || exit
set -xeuo pipefail

node node_modules/json-schema-to-typescript/dist/src/cli.js \
server/config/questions.schema.json \
> server/config/questions.schema.d.ts

./node_modules/.bin/graphql-typewriter -i ./api.graphql
mv ./api.graphql.types.ts ./server/routes/api/

./node_modules/tslint/bin/tslint -p server/
./node_modules/tslint/bin/tslint -p client/
./node_modules/typescript/bin/tsc -p server/
./node_modules/typescript/bin/tsc -p client/

131 changes: 130 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading