-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change codebase to TypeScript and beginning of event API (#14)
* typescript redo * create event test * move to typescript * remove build folder * typescript redo * ignore build folder * ignore build folder * update draft pull request * change route entrypoint * change route * add event description * schema change * change from class to function * get event query test * fix getevent model * add event test * change to class
- Loading branch information
Showing
19 changed files
with
696 additions
and
8,327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"watch": "src/**/*.ts", | ||
"execMap": { | ||
"ts": "ts-node" | ||
}, | ||
"exec": "ts-node -r tsconfig-paths/register --cacheDirectory tmp/tscache src/server.ts" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
exports.getEvents = { | ||
id: 1, | ||
title: 'Community Challenge', | ||
description:'Join us as we celebrate a year of growth and collaboration', | ||
location: [{ | ||
"name": "Sirikwa Hotel", | ||
"street": "Oloo Street", | ||
"city": "Eldoret" | ||
}], | ||
startTime: '2019-08-15 21:05:15.723336+07', | ||
endTime: '2019-08-15 21:05:15.723336+07', | ||
mediaLink: 'https://photos.app.goo.gl/323EcdkmFTzrfLd96', | ||
speakers: [{ | ||
"name": "Marvin Kweyu", | ||
"job title": "Django Developer", | ||
"bio": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." | ||
}] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Pool } from "pg"; | ||
|
||
const pool = new Pool({ | ||
//ignore this im getting stuck on destructuring and passing my env variables with Typescript | ||
connectionString: "postgres://postgres:50filthyCENT!@localhost:5432/devceldoret" | ||
}); | ||
|
||
class Database { | ||
static async query(query:any, value:any, isArray = false) { | ||
const response = await pool.query(query, value); | ||
const result = isArray ? response.rows : response.rows[0]; | ||
return result; | ||
} | ||
} | ||
|
||
export default Database; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class ErrorHandler extends Error { | ||
status: number; | ||
constructor(message:string, status:number) { | ||
super(message); | ||
this.status = status; | ||
} | ||
} | ||
|
||
export default ErrorHandler; | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require("dotenv").config({ path: `${__dirname}/.env` }); | ||
const pg = require("pg"); | ||
|
||
const { | ||
APP_ENV, | ||
DB_HOST, | ||
DB_USER, | ||
DB_PASS | ||
} = process.env; | ||
|
||
if (process.env.NODE_ENV === "development") | ||
|
||
module.exports = new pg.Pool(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import EventModel from "../models/events"; | ||
|
||
class EventController { | ||
static async getEvents(_req: any, res: any, next: any) { | ||
try { | ||
const events = await EventModel.getEvents(); | ||
const data = [...events]; | ||
res.status(200).json(data); | ||
} catch (error) { | ||
next(error); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
export default EventController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Database from "../db/index"; | ||
|
||
class EventModel { | ||
static async getEvents() { | ||
const response = await Database.query('SELECT * FROM events ORDER BY id ASC', '',true).catch((error) => { | ||
throw new Error(error.message); | ||
}); | ||
return response; | ||
} | ||
} | ||
|
||
export default EventModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Router } from "express"; | ||
//import { Pool } from 'pg'; | ||
import EventController from "../controllers/event-controller"; | ||
|
||
const router = Router(); | ||
// Added for testing purposes | ||
// const pool = new Pool({ | ||
// connectionString: "postgres://postgres:50filthyCENT!@localhost:5432/devceldoret" | ||
// }); | ||
|
||
// const getEvents = (_request:any, response:any) => { | ||
// pool.query('SELECT * FROM events ORDER BY id ASC', (error, results) => { | ||
// if (error) { | ||
// throw error; | ||
// } | ||
// response.status(200).json(results.rows); | ||
// }); | ||
// }; | ||
|
||
router.get("/", EventController.getEvents); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { expect } from "chai"; | ||
|
||
import request from "supertest"; | ||
|
||
const getEvents = require("../DB/db.js"); | ||
const Database = require ("../DB/index"); | ||
|
||
import app from "../server"; | ||
|
||
const url = '/api/v1/'; | ||
|
||
describe("DevC", () => { | ||
describe('User can view all events', () => { | ||
it('GET /event', (done) => { | ||
request(app) | ||
.get('/api/v1/event') | ||
.set('Accept', 'application/json') | ||
.expect("Content-Type", /json/) | ||
.then((response) => { | ||
const { data,status } = response.body; | ||
expect(response.status).to.equal(200); | ||
//expect(data.id).to.be.a("number"); | ||
// expect(data.title).to.be.a("string"); | ||
// expect(data.description).to.be.a("string"); | ||
// expect(data.location).to.be.an("array"); | ||
// expect(data.startTime).to.be.a("string"); | ||
// expect(data.endTime).to.be.a("string"); | ||
// expect(data.mediaLink).to.be.a("string"); | ||
// expect(data.speakers).to.be.an("array"); | ||
done(); | ||
}) | ||
.catch((error: any) => done(error)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"target": "es6", | ||
"noImplicitAny": true, | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"outDir": "dist", | ||
"baseUrl": ".", | ||
"paths": { | ||
"*": ["node_modules/*"] | ||
} | ||
}, | ||
"include": ["src/**/*"] | ||
} |
Oops, something went wrong.