2015-12-16 20:09:22 -05:00
|
|
|
mw = require '../middleware'
|
|
|
|
|
2015-12-14 14:10:37 -05:00
|
|
|
module.exports.setup = (app) ->
|
2016-06-01 12:53:16 -04:00
|
|
|
|
2016-04-11 19:51:51 -04:00
|
|
|
passport = require('passport')
|
|
|
|
app.post('/auth/login', passport.authenticate('local'), mw.auth.afterLogin)
|
|
|
|
app.post('/auth/login-facebook', mw.auth.loginByFacebook, mw.auth.afterLogin)
|
|
|
|
app.post('/auth/login-gplus', mw.auth.loginByGPlus, mw.auth.afterLogin)
|
|
|
|
app.post('/auth/logout', mw.auth.logout)
|
|
|
|
app.get('/auth/name/?(:name)?', mw.auth.name)
|
|
|
|
app.post('/auth/reset', mw.auth.reset)
|
2016-03-03 17:22:50 -05:00
|
|
|
app.post('/auth/spy', mw.auth.spy)
|
|
|
|
app.post('/auth/stop-spying', mw.auth.stopSpying)
|
2016-04-11 19:51:51 -04:00
|
|
|
app.get('/auth/unsubscribe', mw.auth.unsubscribe)
|
|
|
|
app.get('/auth/whoami', mw.auth.whoAmI)
|
2016-05-16 17:33:20 -04:00
|
|
|
|
2016-06-16 19:00:45 -04:00
|
|
|
app.delete('/db/*', mw.auth.checkHasUser())
|
|
|
|
app.patch('/db/*', mw.auth.checkHasUser())
|
|
|
|
app.post('/db/*', mw.auth.checkHasUser())
|
|
|
|
app.put('/db/*', mw.auth.checkHasUser())
|
2016-06-01 12:53:16 -04:00
|
|
|
|
2016-04-11 14:59:51 -04:00
|
|
|
Achievement = require '../models/Achievement'
|
|
|
|
app.get('/db/achievement', mw.achievements.fetchByRelated, mw.rest.get(Achievement))
|
|
|
|
app.post('/db/achievement', mw.auth.checkHasPermission(['admin', 'artisan']), mw.rest.post(Achievement))
|
|
|
|
app.get('/db/achievement/:handle', mw.rest.getByHandle(Achievement))
|
|
|
|
app.put('/db/achievement/:handle', mw.auth.checkLoggedIn(), mw.achievements.put)
|
|
|
|
app.delete('/db/achievement/:handle', mw.auth.checkHasPermission(['admin', 'artisan']), mw.rest.delete(Achievement))
|
|
|
|
app.get('/db/achievement/names', mw.named.names(Achievement))
|
2016-04-29 16:37:47 -04:00
|
|
|
app.post('/db/achievement/names', mw.named.names(Achievement))
|
2016-04-11 14:59:51 -04:00
|
|
|
app.get('/db/achievement/:handle/patches', mw.patchable.patches(Achievement))
|
|
|
|
app.post('/db/achievement/:handle/watchers', mw.patchable.joinWatchers(Achievement))
|
|
|
|
app.delete('/db/achievement/:handle/watchers', mw.patchable.leaveWatchers(Achievement))
|
2016-05-16 17:33:20 -04:00
|
|
|
|
2015-12-16 20:09:22 -05:00
|
|
|
Article = require '../models/Article'
|
|
|
|
app.get('/db/article', mw.rest.get(Article))
|
2016-06-01 12:53:16 -04:00
|
|
|
app.post('/db/article', mw.auth.checkLoggedIn(), mw.auth.checkHasPermission(['admin', 'artisan']), mw.rest.post(Article))
|
2015-12-16 20:09:22 -05:00
|
|
|
app.get('/db/article/names', mw.named.names(Article))
|
|
|
|
app.post('/db/article/names', mw.named.names(Article))
|
|
|
|
app.get('/db/article/:handle', mw.rest.getByHandle(Article))
|
|
|
|
app.put('/db/article/:handle', mw.auth.checkHasPermission(['admin']), mw.rest.put(Article))
|
|
|
|
app.patch('/db/article/:handle', mw.auth.checkHasPermission(['admin']), mw.rest.put(Article))
|
|
|
|
app.post('/db/article/:handle/new-version', mw.auth.checkLoggedIn(), mw.versions.postNewVersion(Article, { hasPermissionsOrTranslations: 'artisan' }))
|
|
|
|
app.get('/db/article/:handle/versions', mw.versions.versions(Article))
|
|
|
|
app.get('/db/article/:handle/version/?(:version)?', mw.versions.getLatestVersion(Article))
|
|
|
|
app.get('/db/article/:handle/files', mw.files.files(Article, {module: 'article'}))
|
|
|
|
app.get('/db/article/:handle/patches', mw.patchable.patches(Article))
|
|
|
|
app.post('/db/article/:handle/watchers', mw.patchable.joinWatchers(Article))
|
|
|
|
app.delete('/db/article/:handle/watchers', mw.patchable.leaveWatchers(Article))
|
2016-04-13 14:39:17 -04:00
|
|
|
|
2016-05-04 15:05:28 -04:00
|
|
|
Campaign = require '../models/Campaign'
|
|
|
|
app.post('/db/campaign', mw.auth.checkHasPermission(['admin']), mw.rest.post(Campaign))
|
|
|
|
app.get('/db/campaign', mw.campaigns.fetchByType, mw.rest.get(Campaign))
|
|
|
|
app.get('/db/campaign/names', mw.named.names(Campaign))
|
|
|
|
app.post('/db/campaign/names', mw.named.names(Campaign))
|
|
|
|
app.get('/db/campaign/:handle', mw.rest.getByHandle(Campaign))
|
2016-04-13 14:39:17 -04:00
|
|
|
app.put('/db/campaign/:handle', mw.campaigns.put)
|
2016-05-04 15:05:28 -04:00
|
|
|
app.get('/db/campaign/:handle/achievements', mw.campaigns.fetchRelatedAchievements)
|
|
|
|
app.get('/db/campaign/:handle/levels', mw.campaigns.fetchRelatedLevels)
|
|
|
|
app.get('/db/campaign/:handle/patches', mw.patchable.patches(Campaign))
|
|
|
|
app.get('/db/campaign/-/overworld', mw.campaigns.fetchOverworld)
|
2016-05-16 17:33:20 -04:00
|
|
|
|
2016-04-13 14:39:17 -04:00
|
|
|
app.post('/db/classroom', mw.classrooms.post)
|
2016-05-11 17:39:26 -04:00
|
|
|
app.get('/db/classroom', mw.classrooms.fetchByCode, mw.classrooms.getByOwner)
|
2016-04-13 12:54:24 -04:00
|
|
|
app.get('/db/classroom/:handle/levels', mw.classrooms.fetchAllLevels)
|
|
|
|
app.get('/db/classroom/:handle/courses/:courseID/levels', mw.classrooms.fetchLevelsForCourse)
|
2016-06-02 13:27:20 -04:00
|
|
|
app.post('/db/classroom/:handle/invite-members', mw.classrooms.inviteMembers)
|
2016-03-30 16:57:19 -04:00
|
|
|
app.get('/db/classroom/:handle/member-sessions', mw.classrooms.fetchMemberSessions)
|
|
|
|
app.get('/db/classroom/:handle/members', mw.classrooms.fetchMembers) # TODO: Use mw.auth?
|
2016-05-20 17:52:04 -04:00
|
|
|
app.post('/db/classroom/:classroomID/members/:memberID/reset-password', mw.classrooms.setStudentPassword)
|
2016-05-13 13:55:22 -04:00
|
|
|
app.post('/db/classroom/:anything/members', mw.auth.checkLoggedIn(), mw.classrooms.join)
|
2016-03-30 19:20:37 -04:00
|
|
|
app.get('/db/classroom/:handle', mw.auth.checkLoggedIn()) # TODO: Finish migrating route, adding now so 401 is returned
|
2016-06-21 12:29:41 -04:00
|
|
|
app.get('/db/classroom/-/users', mw.auth.checkHasPermission(['admin']), mw.classrooms.getUsers)
|
2016-02-08 17:24:08 -05:00
|
|
|
|
|
|
|
CodeLog = require ('../models/CodeLog')
|
2016-06-01 12:53:16 -04:00
|
|
|
app.post('/db/codelogs', mw.codelogs.post)
|
2016-02-08 17:24:08 -05:00
|
|
|
app.get('/db/codelogs', mw.auth.checkHasPermission(['admin']), mw.rest.get(CodeLog))
|
|
|
|
|
2016-03-30 16:57:19 -04:00
|
|
|
Course = require '../models/Course'
|
|
|
|
app.get('/db/course', mw.rest.get(Course))
|
|
|
|
app.get('/db/course/:handle', mw.rest.getByHandle(Course))
|
2016-04-27 18:36:16 -04:00
|
|
|
app.get('/db/course/:handle/levels/:levelOriginal/next', mw.courses.fetchNextLevel)
|
2016-05-16 17:33:20 -04:00
|
|
|
|
2016-05-23 13:26:34 -04:00
|
|
|
app.post('/db/course_instance/-/recent', mw.auth.checkHasPermission(['admin']), mw.courseInstances.fetchRecent)
|
2016-04-13 12:54:24 -04:00
|
|
|
app.get('/db/course_instance/:handle/levels/:levelOriginal/next', mw.courseInstances.fetchNextLevel)
|
2016-03-30 16:57:19 -04:00
|
|
|
app.post('/db/course_instance/:handle/members', mw.auth.checkLoggedIn(), mw.courseInstances.addMembers)
|
2016-04-13 12:54:24 -04:00
|
|
|
app.get('/db/course_instance/:handle/classroom', mw.auth.checkLoggedIn(), mw.courseInstances.fetchClassroom)
|
2016-05-16 17:33:20 -04:00
|
|
|
|
2016-05-20 17:52:04 -04:00
|
|
|
app.put('/db/user/:handle', mw.users.resetEmailVerifiedFlag)
|
2016-04-07 17:55:42 -04:00
|
|
|
app.delete('/db/user/:handle', mw.users.removeFromClassrooms)
|
2016-02-25 18:24:16 -05:00
|
|
|
app.get('/db/user', mw.users.fetchByGPlusID, mw.users.fetchByFacebookID)
|
2016-05-16 17:33:20 -04:00
|
|
|
app.put('/db/user/-/become-student', mw.users.becomeStudent)
|
|
|
|
app.put('/db/user/-/remain-teacher', mw.users.remainTeacher)
|
2016-05-11 17:39:26 -04:00
|
|
|
app.post('/db/user/:userID/request-verify-email', mw.users.sendVerificationEmail)
|
|
|
|
app.post('/db/user/:userID/verify/:verificationCode', mw.users.verifyEmailAddress) # TODO: Finalize URL scheme
|
2016-06-20 17:35:52 -04:00
|
|
|
app.get('/db/level/:handle/session', mw.auth.checkHasUser(), mw.levels.upsertSession)
|
2016-06-21 12:29:41 -04:00
|
|
|
app.get('/db/user/-/students', mw.auth.checkHasPermission(['admin']), mw.users.getStudents)
|
|
|
|
app.get('/db/user/-/teachers', mw.auth.checkHasPermission(['admin']), mw.users.getTeachers)
|
2016-05-09 18:16:54 -04:00
|
|
|
|
|
|
|
app.get('/db/prepaid', mw.auth.checkLoggedIn(), mw.prepaids.fetchByCreator)
|
|
|
|
app.post('/db/prepaid', mw.auth.checkHasPermission(['admin']), mw.prepaids.post)
|
|
|
|
app.post('/db/prepaid/:handle/redeemers', mw.prepaids.redeem)
|
2015-12-16 20:09:22 -05:00
|
|
|
|
2015-12-29 00:03:43 -05:00
|
|
|
app.get '/db/products', require('./db/product').get
|
2016-05-16 17:33:20 -04:00
|
|
|
|
2016-03-09 19:59:25 -05:00
|
|
|
TrialRequest = require '../models/TrialRequest'
|
|
|
|
app.get('/db/trial.request', mw.trialRequests.fetchByApplicant, mw.auth.checkHasPermission(['admin']), mw.rest.get(TrialRequest))
|
2016-04-05 13:01:51 -04:00
|
|
|
app.post('/db/trial.request', mw.trialRequests.post)
|
2016-03-09 19:59:25 -05:00
|
|
|
app.get('/db/trial.request/:handle', mw.auth.checkHasPermission(['admin']), mw.rest.getByHandle(TrialRequest))
|
|
|
|
app.put('/db/trial.request/:handle', mw.auth.checkHasPermission(['admin']), mw.trialRequests.put)
|
2016-06-21 12:29:41 -04:00
|
|
|
app.get('/db/trial.request/-/users', mw.auth.checkHasPermission(['admin']), mw.trialRequests.getUsers)
|
2015-12-29 00:03:43 -05:00
|
|
|
|
2016-05-05 13:01:58 -04:00
|
|
|
app.get('/healthcheck', mw.healthcheck)
|