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

init commit #18

Merged
merged 7 commits into from
May 3, 2020
Merged
Changes from 1 commit
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
61 changes: 44 additions & 17 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,62 @@ const express = require('express')
const app = express()
const port = 3000

const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));

const organizations = {}
let currId = 0


const organizations = {
0: { 'Name': 'Nandu Business', 'Net Worth': '6 Billion', 'Business Type': 'Real Estate Dealer' },
1: { 'Name': 'Sailesh Business', 'Net Worth': '20 Billion', 'Business Type': 'Food Dealer' }
}
const event = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: To follow the format of organizations being plural, event here should also be plural

0: {'event': 'Teej', 'Location': 'niggerLand', 'Date': '9/11', 'Price': '$69' },
1: {'event': 'Christmas', 'Location': 'CuckLand', 'Date': '4/20', 'Price': '$69'}
}

app.get('/', (req, res) => res.send('Hello United Nepali!'))

app.get('/health-check', (req, res) => res.send('OK'))

app.listen(port, () => console.log(`Example app listening on port ${port}!`))
app.get('/nepali-check', (req, res) => res.send('Bhaat Khaiyo?'))

app.get('/organizations', (req, res) => res.send(organizations))

app.post('/organizations', function(req, res){
let id_val = currId;
currId = currId + 1;
app.get('/organizations_id', function (req, res) {
var id = req.query.id;
let org = organizations[id]
res.send(org)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: #8

})

organizations[id_val] = {'Name':req.body.name};
res.sendStatus(200);
app.delete('/organization_id', function (req, res) {
var id = req.query.id;
let org = organizations[id]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why do a let org here, did you mean to send it in the response?

delete organizations[id]
res.sendStatus(200)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: #11
Here's what you'd need to change to make it compliant to the issue:

Suggested change
res.sendStatus(200)
if (org) {
res.status(200)
res.send({
"success": 1,
"timestamp": new Date().getTime()
})
} else {
res.status(500)
res.send({
"success": 0,
"timestamp": new Date().getTime()
"error": "Organization with id " + id + " does not exist!"
})
}

I just wrote this in a comment and haven't tested this out, so there might be some bugs here :P

})

app.post('/organization_id', function(req, res) {
var id = req.query.id;
organizations[id] = req.query;
res.sendStatus(200);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: #9

})

app.put('/organization_id', function(req, res) {
var id = req.query.id;
var org = organizations[id];

for(var key in req.query){
if (key in org){
org[key] = req.query[key];
}
}
organizations[id] = org;

res.sendStatus(200);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: #10

})

// * [GET] [organizations/:id] Gets organization by ID
// * [POST] [organizations/:id] Creates new organization by ID
// * [PUT] [organizations/:id] Updates new organization by ID
// * [DELETE] [organizations/:id] Delete organization by ID
app.get('/event', (req, res) => res.send(event))

app.get('/event_details', function(req, res){
var id = req.query.id;
let lit = event[id]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: lit is probably not the best name 😂
If you rename event to events, then lit here can become event.

Suggested change
let lit = event[id]
let event = events[id]

res.send(lit)
})

app.listen(port, () => console.log(`Example app listening on port ${ port }!`))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Missing enter at the end of the file