import * as api from '../../client/src/api'; import { EndpointError, EndpointHandler, catchUnhandledErrors } from './types'; import Knex from 'knex'; export const TagDetailsEndpointHandler: EndpointHandler = async (req: any, res: any, knex: Knex) => { if (!api.checkTagDetailsRequest(req)) { const e: EndpointError = { internalMessage: 'Invalid TagDetails request: ' + JSON.stringify(req.body), httpStatus: 400 }; throw e; } const { id: userId } = req.user; try { const results = await knex.select(['id', 'name', 'parentId']) .from('tags') .where({ 'user': userId }) .where({ 'id': req.params.id }); const response: api.TagDetailsResponse = { name: results[0].name, parentId: results[0].parentId, } await res.send(response); } catch (e) { catchUnhandledErrors(e) } }