---
# System prepended metadata

title: CSC309 Express Routes
tags: [CSC309]

---

CSC309 Express Routes
===

###### tags: `CSC309`

## Schema
### User
```json=
{
    _id: "default User Id",
    icon_img: "url",
    name: "UserName",
    email: "xxxx@gmail.com",
    password:"encodedpassword_0asdfadfawer",
    description: "I am an Academic waste",
    manageProjectList: ["pid1", "pid2"],
    contributeProjectList: ["pid3", "pid4", "pid5"]
}
```
### Project

```json=
{
    _id: "default project Id",
    name: "projectName",
    teamList: ["teamID1", "teamID2", "teamID3"],
    description: "description about this project"
 }

```
### team
```json=
{
_id: "team id",
name: "teamName",
managers: "user_id",
contributors: [
        {userId: "uid_3", userName: "userName3", 
        taskList: ["tid1", "tid2"]},
        {userId: "uid_4", userName: "userName4",
        taskList: ["tid3", "tid4"]},
        {userId: "uid_4", userName: "userName4",
        taskList: ["tid5"]}
        ],
projects: "pid"
}
```
### task
note that progress is 0-6, where 0 is the initial state and 6 means 100% complete.
```json=
_id："task Id",
name: "taskName",
description: "What is this task",
progess: 1
```

## Routes

### admin.js
HTTP Request Methods: get
Route: "admin/users"
Purpose: Allows admin users to get every users in the system
Usage: **actions** -> **admin.js** -> **adminGetUsers**

HTTP Request Methods: delete
Route： "admin/:user_id"
Purpose: Allows admin users to delete a specific user given a user_id in the route
Usage: **actions** -> **admin.js** -> **deleteUsers**

---

### auth.js
HTTP Request Methods: get
Route： "auth/currentUser"
Purpose: Get the current session user, use to see if the current user is still valid to perform any other requests
Usage: **actions** -> **user.js** -> **getCurrentUser**

HTTP Request Methods: post
Route： "auth/signup"
Purpose: Sign up for the new user. Expect req.body to contain name, email and password of the new users.
Usage: **actions** -> **user.js** -> **signUp**

HTTP Request Methods: post
Route： "auth/login"
Purpose: Allows the user to login. Expect the user to have either email or username and the correct password for login.
Usage: **actions** -> **user.js** -> **login**


HTTP Request Methods: get
Route： "auth/logout"
Purpose: Logout the current user, destroy the session cookies and clear any local storage.
Usage: **actions** -> **user.js** -> **logout**

---
### project.js

HTTP Request Methods: get
Route： "api/project/details/:id"
Purpose: return a JSON to populate ProjectPage. Will get team of this project, not just the team_ids.
Usage: used in **actions** -> **project.js** -> **getProjectInfo**
Called: **ProjectPage** in `componentWillMount()`
sample JSON Format: 
```json=
{
    name: "projectName",
    description: "project.description",
    teamList: [team1, team2, team3],
    
 }
}
```
note: team1, team2, and team3 are JSON object, it's format is pretty much the same as getTeam object

HTTP Request Methods: put
Route： "api/project/"
Purpose: Create a project, Expect a teamList, name of the project, and a description in the req.body
Usage: used in **actions** -> **project.js** -> **createProject**
Called: **UserPage** in Create New Project button

---
### task.js
HTTP Request Methods: get
Route： "api/task/:id"
Purpose: get the task information based on task id.
Usage: used in **actions** -> **project.js** -> **getTaskInfo**

HTTP Request Methods: put
Route： "api/task/"
Purpose: create a task that doesn't have to belong to any team or project. Expect name and description of this task. It's progress is default 0 when created.
Usage: used in **actions** -> **project.js** -> **createTask**

---

### team.js

HTTP Request Methods: get
Route： "api/team/:id"
Purpose: get the entire team information, including all the members and their specific tasks.
Usage: used in **actions** -> **project.js** -> **getTeam**
sample JSON Format: 
```json=
{
_id: "team id",
name: "teamName",
contributors: [
        {userId: "uid_3", userName: "userName3", 
        taskList: [task1, task2]},
        {userId: "uid_4", userName: "userName4",
        taskList: [task3]}
        ],
projects: "pid"
}

```
note: task1, task2, and task3 are JSON object that maps to a specific task, they are not just task_ids

HTTP Request Methods: put
Route： "api/team/"
Purpose: Add a new team into the database. Expect given a project_id, contributors, and the name of this team in the req.body. The contributors are default an empty list.
Usage: used in **actions** -> **project.js** -> **createTeam**

HTTP Request Methods: post
Route： "api/team/:team_id/:member_id"
Purpose: Add a member to the team corresponding to team_id
Usage: **actions** -> **project.js** -> **addMember**

HTTP Request Methods: patch
Route： "api/team/:team_id/:user_id"
Purpose: Update task list of a member in a team. This is used to assign task to members of the team.
Usage: used in **actions** -> **project.js** -> **assignTaskToContributor**

---

### user.js
HTTP Request Methods: get
Route： "/api/user/:id"
Purpose: Retrieve a user with corresponding id from database
Usage: used in **actions** -> **user.js** -> **getUserInfo**