Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
222f671
people api partially working
sarahduv Nov 12, 2019
3e34e03
Merge pull request #1 from JS401d32-Project/googleContactRouter
sarahduv Nov 12, 2019
c9dd522
base working code
pcarmichael22 Nov 12, 2019
a70dca6
fixed for travis
pcarmichael22 Nov 12, 2019
c24d5e9
Merge pull request #2 from JS401d32-Project/workingCode
pcarmichael22 Nov 12, 2019
86af050
google.js console.log instrumentation & original docker-compose.yml
JAKimball Nov 13, 2019
0f2e5aa
fetching of people API data is working with oauth tokens
sarahduv Nov 13, 2019
c878e10
can now save people api conatcts to the prisma DB
sarahduv Nov 13, 2019
ab26fea
Add Google OAuth credentials.json comment to .gitignore, add JSDOC st…
JAKimball Nov 13, 2019
1f2d9fc
Merge pull request #3 from JS401d32-Project/sgbranch2
sarahduv Nov 13, 2019
6158af8
readme fixed
pcarmichael22 Nov 13, 2019
309ee56
merge sarahs changes
JAKimball Nov 13, 2019
c108c12
fixed readme
pcarmichael22 Nov 13, 2019
b40dcaf
Merge pull request #4 from JS401d32-Project/workingCode
pcarmichael22 Nov 13, 2019
65c90ef
Merge branch 'sgbranch2' into jon-wed
JAKimball Nov 13, 2019
ffe4fba
Posting to Google API!
JAKimball Nov 13, 2019
a413f7c
Merge pull request #5 from JS401d32-Project/jon-wed
pcarmichael22 Nov 13, 2019
da3f661
refactored and modularized routes
heyerthb Nov 13, 2019
befc54f
Merge branch 'master' into modules
pcarmichael22 Nov 13, 2019
4101653
Merge pull request #6 from JS401d32-Project/modules
pcarmichael22 Nov 13, 2019
bbe8264
partial test for router
pcarmichael22 Nov 14, 2019
d4324c6
Merge pull request #7 from JS401d32-Project/workingCode
pcarmichael22 Nov 14, 2019
dc2da55
adding comments, cleaning up code, adding jsdocs, refactoring to use …
sarahduv Nov 14, 2019
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ build/Release
node_modules/
jspm_packages/

# Google OAuth credentials
credentials.json

# TypeScript v1 declaration files
typings/

Expand Down
53 changes: 43 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,47 @@

####To run an instance of the back end of CaseHawk:

** DISCLAIMER FOR WINDOWS USERS **

In order for Prisma/Docker to work for you, the following is required:

- Windows Pro and the Docker Desktop for Windows
- https://docs.docker.com/docker-for-windows/install/
- https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly
- Alternatively, you may download WSL2
- Note that this requires a Windows 10 build 18917 or higher
- https://docs.microsoft.com/en-us/windows/wsl/wsl2-install

1. Clone this repo
2. `$ npm i`
3. Create a project on Google's Developer console and create a client secret and client id for [OAuth](https://developers.google.com/identity/protocols/OAuth2WebServer).
4. Set environment variables for:

2. `$ npm install`

3. Create a project on Google's Developer console and create a client secret and client id for [OAuth](https://developers.google.com/identity/protocols/OAuth2WebServer). Set Redirect URI to http://localhost:3000/oauth and set Js origins to both local 3000 and 4000.

4. Create a .env file and set environment variables for:
`GOOGLE_CLIENT_ID` - from Google
`GOOGLE_CLIENT_SECRET` - from Google
`PORT` - the port for your server
`SECRET` - the signature string for JWT
`CLIENT_URL` - the url for your CaseHawk front end
5. Set up a [Prisma Databse Client](https://www.prisma.io/docs/get-started/01-setting-up-prisma-new-database-JAVASCRIPT-a002/)
6. Seed the database `$ npm run seedDB`
7. Start the server `$node index.js`
`PORT` - the port for your server (4000)
`SECRET` - the signature string for JWT (Can be anything)
`CLIENT_URL` - the url for your CaseHawk front end (3000)
`API_URL` - http://localhost:4000
`TOKEN_EXPIRE_TIME` - 1h

5. Download and install [Docker CE](https://docs.docker.com/v17.12/install/)

6. Set up a [Prisma Databse Client](https://www.prisma.io/docs/get-started/01-setting-up-prisma-new-database-JAVASCRIPT-a002/)

7. Seed the database `$ npm run seedDB`

8. Start the server `$node index.js`

9. Refer to the README on the front-end repo for futher instructions.

##Additions from November 2019

We added access to the Google People API so it can fetch, and create data. This is implemented on the back end but currently not on the front. To test these features use Postman or HTTPie. The route of /googlecontacts uses Oauth and the People API to fetch that authenticated users contacts. The route of /importgooglecontacts that uses Oauth to authenticate which contacts you are trying to receive, and writes them to the Prisma DB.

##Authorization
For more info on Google People API reference the [docs](https://developers.google.com/people/api/rest/v1/people)

####Overview

Expand Down Expand Up @@ -58,3 +85,9 @@ The app uses Postgres and Prisma for our database stack.
- Lillian Gales
- Joanna Arroyo
- Trae Bennett
- 401d32
- Sarah Gilliam
- Peter Carmichael
- Matthew Heyert
- Johnathon Kimball
- Corey Marchand
31 changes: 30 additions & 1 deletion __tests__/routes.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
'use strict';

const caseRouter = require('../src/routes/cases-router')
const { prisma } = require('../../../prisma-database/generated/prisma-client');
process.env.TOKEN_EXPIRE_TIME = '24h';
process.env.SECRET = 'testsecret';




describe('Dummy test', () => {
test('Test test!', () => {
expect(true).toBeTruthy();

});
});


const prisma = {}
prisma.user = jest.fn();
prisma.$exists.user = jest.fn();
prisma.createUser = jest.fn();
context = {
prisma
}
const res = graphql(schema, MUTATION, null, context)

const prisma = new Prisma({
endpoint: '',
});
prisma.user = jest.fn();
prisma.$exists.user = jest.fn();
prisma.createUser = jest.fn();
context = {
prisma
}
const res = graphql(schema, MUTATION, null, context)
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.34
restart: always
ports:
- '4466:4466'
environment:
PRISMA_CONFIG: |
port: 4466
databases:
default:
connector: postgres
host: host.docker.internal
schema: public
database: casehawk
port: 5432
user: prisma
password: prisma
postgres:
image: postgres:10.3
restart: always
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: prisma
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres: ~
62 changes: 62 additions & 0 deletions docs/swagger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Altered version of sample usage code
* https://www.npmjs.com/package/express-swagger-generator#usage
*
* This will add the /api-docs route to the express app instance.
*
* To use, alter the options object as needed and call the exported
* function as follows:
*
* ```js
* const express = require('express');
* // Prepare the express app
* const app = express();
* // Add the swagger /api-docs route to the server
* const swagger = require('../docs/swagger');
* swagger(app);
* ```
*/
'use strict';

const swaggerGenerator = require('express-swagger-generator');

let options = {
swaggerDefinition: {
info: {
description: 'CaseHawk API Server',
title: 'CaseHawk API Server',
version: '1.0.0',
},
// host: 'CHANGE_THIS.herokuapp.com', // TODO: Deployment Link Here
host: 'localhost:4000',
basePath: '/',
produces: [
"application/json",
"application/xml"
],
schemes: ['http', 'https'],
securityDefinitions: {
JWT: {
type: 'apiKey',
in: 'header',
name: 'Authorization',
description: "",
},
basicAuth: {
type: 'basic',
in: 'header',
name: 'Authorization',
description: "",
}
}
},
basedir: __dirname, //app absolute path
files: ['../lib/**/*.js', '../src/**/*.js'] //Path to the API handle folder
};

/**
* Add the /api-docs route to the express app instance.
*
* @param {Express} app - Your express app instance
*/
module.exports = app => swaggerGenerator(app)(options);
Loading