2014-03-06 13:04:00 -05:00
|
|
|
express = require("express")
|
|
|
|
app = express()
|
|
|
|
|
|
|
|
module.exports = MockWebApi =
|
|
|
|
users: {}
|
|
|
|
|
2014-03-28 12:01:34 -04:00
|
|
|
projects: {}
|
|
|
|
|
2014-03-06 13:04:00 -05:00
|
|
|
getUser: (user_id, callback = (error) ->) ->
|
|
|
|
callback null, @users[user_id]
|
|
|
|
|
2014-03-28 12:01:34 -04:00
|
|
|
getProject: (project_id, callback = (error, project) ->) ->
|
|
|
|
callback null, @projects[project_id]
|
|
|
|
|
2014-03-06 13:04:00 -05:00
|
|
|
run: () ->
|
|
|
|
app.get "/user/:user_id/personal_info", (req, res, next) =>
|
|
|
|
@getUser req.params.user_id, (error, user) ->
|
|
|
|
if error?
|
|
|
|
res.send 500
|
|
|
|
if !user?
|
|
|
|
res.send 404
|
|
|
|
else
|
|
|
|
res.send JSON.stringify user
|
|
|
|
|
2014-03-28 12:01:34 -04:00
|
|
|
app.get "/project/:project_id/details", (req, res, next) =>
|
|
|
|
@getProject req.params.project_id, (error, project) ->
|
|
|
|
if error?
|
|
|
|
res.send 500
|
|
|
|
if !project?
|
|
|
|
res.send 404
|
|
|
|
else
|
|
|
|
res.send JSON.stringify project
|
|
|
|
|
2014-03-06 13:04:00 -05:00
|
|
|
app.listen 3000, (error) ->
|
|
|
|
throw error if error?
|
|
|
|
|
|
|
|
MockWebApi.run()
|
|
|
|
|