-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fb1057
commit 5ddf951
Showing
4 changed files
with
117 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ module.exports = { | |
moduleNameMapper: { | ||
'^@src/(.*)$': '<rootDir>/src/$1', | ||
}, | ||
bail: true | ||
}; |
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,34 @@ | ||
import express, { Request, Response, NextFunction } from 'express'; | ||
import * as file from '@src/scripts/file'; | ||
import { create as createError } from '@src/error'; | ||
import { validationResult, query } from 'express-validator'; | ||
|
||
const router = express.Router(); | ||
|
||
router.get('/', | ||
[query('index').isInt().withMessage("not an integer") | ||
.isLength({ max: 3 }).withMessage("not in range") | ||
.toInt()], | ||
async function getRead(req:Request, res:Response, next:NextFunction) { | ||
const errors = validationResult(req); | ||
if (!errors.isEmpty()) { | ||
return createError(res, 400, JSON.stringify({errors: errors.array()}), next) | ||
} | ||
|
||
const fileObj: File.Obj = file.getFile(res, next); | ||
fileObj.content = await file.readAsJson(res, fileObj.path, next) | ||
if (!fileObj.content || !Array.isArray(fileObj.content.entries)) { | ||
return createError(res, undefined, `File corrupt: ${fileObj.path}`, next); | ||
} | ||
|
||
let entries = fileObj.content.entries; | ||
|
||
if (req.query.index) { | ||
entries = entries.slice(Number(req.query.index)); | ||
} | ||
|
||
res.json({entries}); | ||
}); | ||
|
||
|
||
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