All files / owid-grapher/adminSiteServer publicApiRouter.ts

71.43% Statements 20/28
100% Branches 0/0
100% Functions 0/0
71.43% Lines 20/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 211x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                 1x 1x
import { FunctionalRouter } from "./FunctionalRouter"
import { Request, Response } from "./authentication"
import { writeVariableCSV } from "../db/model/Variable"
import { expectInt } from "../serverUtils/serverUtil"
import { stringifyUnkownError } from "../clientUtils/Util"
 
export const publicApiRouter = new FunctionalRouter()
 
publicApiRouter.router.get(
    "/variables/:variableIds.csv",
    async (req: Request, res: Response) => {
        const variableIds = req.params.variableIds.split("+").map(expectInt)
        try {
            await writeVariableCSV(variableIds, res)
            res.end()
        } catch (error) {
            res.send(`Error: ${stringifyUnkownError(error)}`)
        }
    }
)