Skip to content

Commit 3853582

Browse files
committed
feat(poll): add endpoint for polling
1 parent f5d1208 commit 3853582

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/routes/api/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { NextFunction, Request, Response, Router } from 'express'
22
import run from './run'
33
import submit from './submit'
4+
import result from './result'
45
import { route as langs } from './langs'
56
import { checkValidApiKey } from '../../validators/ApiKeyValidators'
67
import * as debug from 'debug'
@@ -26,6 +27,7 @@ route.use((req: Request, res: Response, next: NextFunction) => {
2627
})
2728

2829
route.use('/runs', run)
30+
route.use('/result', result)
2931
route.use('/submissions', submit)
3032
route.use('/langs', langs)
3133

src/routes/api/result/controller.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {Request, Response} from "express";
2+
import DB from 'models'
3+
4+
export default {
5+
async sendResult(req: Request, res: Response) {
6+
const submissionId = req.params.id ? parseInt(req.params.id) : null
7+
if (!submissionId) {
8+
res.status(400).json({err: 'SubmissionId not found'})
9+
}
10+
else {
11+
DB.submissions.findByPk(submissionId)
12+
.then((submission) => {
13+
res.status(200).json(submission.results)
14+
}).catch((err) => {
15+
res.status(404).json({err: 'Submission not found'})
16+
})
17+
}
18+
}
19+
}

src/routes/api/result/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Router } from 'express'
2+
import Controller from './controller'
3+
4+
const router: Router = Router()
5+
6+
router.get('/:id', Controller.sendResult)
7+
8+
export default router

0 commit comments

Comments
 (0)