Skip to content

Commit

Permalink
Added MySQL backend & User Table (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Gao authored Feb 14, 2020
1 parent 9f9e850 commit c802625
Show file tree
Hide file tree
Showing 24 changed files with 4,664 additions and 4,058 deletions.
3 changes: 0 additions & 3 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@ PORT=3000
# the graphql endpoint for @code-reviewer/api
GRAPHQL_ENDPOINT=graphql

# MongoDB server endpoint
MONGO_SERVER=mongodb://localhost:27017/code_reviewer

NODE_ENV=development
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Anonymous online peer code review made easy.

## Requirements

- MongoDB v4.2 https://docs.mongodb.com/manual/installation/
- MySQL v8.0.19 https://www.mysql.com/
- Node v10.16.3 https://nodejs.org/en/download/
- Yarn v1.19.0 https://yarnpkg.com/lang/en/docs/install

Expand All @@ -27,7 +27,6 @@ yarn # Run in project root to install all node dependencies
### Starting Application

```bash
mongod # Start MongoDB server at default port
yarn start # Run in project root to start code reviewer app
```

Expand Down
2 changes: 0 additions & 2 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const config = Object.freeze({
DOMAIN: process.env.DOMAIN || 'http://localhost',
GRAPHQL_ENDPOINT: process.env.GRAPHQL_ENDPOINT || 'graphql',
PORT: process.env.PORT || 3000,
MONGO_SERVER:
process.env.MONGO_SERVER || 'mongodb://localhost:27017/code_reviewer',
ENV: process.env.NODE_ENV || 'development'
})

Expand Down
18 changes: 18 additions & 0 deletions ormconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "mysql",
"host": "code-reviewer-instance.chelhhbpfj3v.ca-central-1.rds.amazonaws.com",
"port": 3306,
"username": "admin",
"password": "chickennuggets",
"database": "code_reviewer",
"synchronize": true,
"logging": false,
"entities": ["db/entity/**/*.ts"],
"migrations": ["db/migration/**/*.ts"],
"subscribers": ["db/subscriber/**/*.ts"],
"cli": {
"entitiesDir": "db/entity",
"migrationsDir": "db/migration",
"subscribersDir": "db/subscriber"
}
}
20 changes: 10 additions & 10 deletions packages/api/apollo-server/mock-data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const users = [
{
id: '001',
id: 1,
firstName: 'Alice',
lastName: 'A',
utorID: 'alice01',
Expand All @@ -9,7 +9,7 @@ export const users = [
isActive: true
},
{
id: '002',
id: 2,
firstName: 'Bob',
lastName: 'B',
utorID: 'bob01',
Expand All @@ -18,7 +18,7 @@ export const users = [
isActive: true
},
{
id: '003',
id: 3,
firstName: 'Charlie',
lastName: 'C',
utorID: 'charlie01',
Expand All @@ -27,7 +27,7 @@ export const users = [
isActive: true
},
{
id: '004',
id: 4,
firstName: 'David',
lastName: 'D',
utorID: 'david01',
Expand All @@ -39,15 +39,15 @@ export const users = [

export const assignments = [
{
id: '001',
id: 1,
name: 'Assignment 1',
requiredFiles: [],
feedbackQuestions: [],
groupSize: 4,
isActive: true
},
{
id: '002',
id: 2,
name: 'Assignment 2',
requiredFiles: [],
feedbackQuestions: [],
Expand All @@ -58,28 +58,28 @@ export const assignments = [

export const submissions = [
{
id: '001',
id: 1,
author: users[0],
assignment: assignments[0],
files: [],
reviewBy: [users[1], users[2], users[3]]
},
{
id: '002',
id: 2,
author: users[1],
assignment: assignments[0],
files: [],
reviewBy: [users[0], users[2], users[3]]
},
{
id: '003',
id: 3,
author: users[2],
assignment: assignments[0],
files: [],
reviewBy: [users[0], users[1], users[3]]
},
{
id: '004',
id: 4,
author: users[3],
assignment: assignments[0],
files: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/api/apollo-server/mutations/assignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const addAssignment = (_: any, args: IAddAssignment) => {
}

export interface IEditAssignment extends IAddAssignment {
id: String
id: number
}

// edit an assignment given its id and the properties that
Expand Down
10 changes: 5 additions & 5 deletions packages/api/apollo-server/mutations/submission.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { submissions } from '../mock-data'

export interface IEditSubmissions {
assignmentID: String
assignmentID: number
}

// edit all submissions related to an assignment
Expand All @@ -12,8 +12,8 @@ export const editSubmissions = async (_: any, args: IEditSubmissions) => {
}

export interface IAddAnnotation {
fileID: String
givenByID: String
fileID: number
givenByID: number
line: Number
content: String
}
Expand All @@ -23,7 +23,7 @@ export const addAnnotation = async (_: any, args: IAddAnnotation) => {
}

export interface IEditAnnotation {
id: String
id: number
content?: String
}

Expand All @@ -32,7 +32,7 @@ export const editAnnotation = async (_: any, args: IEditAnnotation) => {
}

export interface IDeleteAnnotation {
id: String
id: number
}

export const deleteAnnotation = async (_: any, args: IDeleteAnnotation) => {
Expand Down
8 changes: 4 additions & 4 deletions packages/api/apollo-server/mutations/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const addInstructor = (_: any, args: IAddInstructor) => {
}

export interface IEditStudent {
id: String
id: number
firstName?: String
lastName?: String
utorID: String
Expand All @@ -46,7 +46,7 @@ export const editStudent = (_: any, args: IEditStudent) => {
}

export interface IEditTA {
id: String
id: number
firstName?: String
lastName?: String
utorID: String
Expand All @@ -58,7 +58,7 @@ export const editTA = (_: any, args: IEditTA) => {
}

export interface IEditInstructor {
id: String
id: number
firstName?: String
lastName?: String
email?: String
Expand All @@ -69,7 +69,7 @@ export const editInstructor = (_: any, args: IEditInstructor) => {
}

export interface IDeleteUser {
id: String
id: number
}

export const deactivateUser = (_: any, args: IDeleteUser) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/apollo-server/queries/assignment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assignments } from '../mock-data'

export interface IGetAssignment {
id: String
id: number
}

// get a single assignment based on ID
Expand Down
8 changes: 4 additions & 4 deletions packages/api/apollo-server/queries/submission.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { submissions } from '../mock-data'

export interface IGetSubmission {
id: String
id: number
}

// don't have a use case for this one yet, put it there just for testing
Expand All @@ -14,7 +14,7 @@ export const getSubmission = async (_: any, args: IGetSubmission) => {
}

export interface IGetSubmissions {
userID: String
userID: number
}

// get this user's all submissions as well as the submissions has this user
Expand All @@ -27,7 +27,7 @@ export const getSubmissions = async (_: any, args: IGetSubmissions) => {
}

export interface IGetFiles {
submissionID: String
submissionID: number
}

// get files by submissionID
Expand All @@ -36,7 +36,7 @@ export const getFiles = async (_: any, args: IGetFiles) => {
}

export interface IGetAnnotations {
fileID: String
fileID: number
}

// get annotations by fileID
Expand Down
19 changes: 12 additions & 7 deletions packages/api/apollo-server/queries/user.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
import { users } from '../mock-data'
import { User } from '../../db/entity/User'

export interface IGetUser {
id?: String
id?: number
utorID?: String
email?: String
}

// get one user based on id, utorID or email
export const getUser = async (_: any, args: IGetUser) => {
const resultUser = users.find(user => user.id === args.id)
return resultUser
try {
const resultUser = await User.findOne(_, { where: args })
return resultUser
} catch (e) {
// TODO: Add Error management Urgent!!
console.log(e)
}
}

export interface IGetUsers {
users: {
id?: String
id?: number
firstName?: String
lastName?: String
utorID?: String
email?: String
userType?: String
isActive?: Boolean
isActive?: boolean
}
}

// get 0 or more usrs based on the criterion
// the criterion can be one or more properties from IGetUsers
export const getUsers = async (_: any, args: IGetUsers) => {
console.log(args)
const users = await User.find({ where: args })
return users
}
Loading

0 comments on commit c802625

Please sign in to comment.