-
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.
Adding routes and controllers for reading data
- Loading branch information
Showing
4 changed files
with
65 additions
and
26 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { getOrbisContext } from '@/utils/context.js' | ||
import { Request, Response, NextFunction } from 'express' | ||
|
||
const readValidations = async (_req: Request, res: Response, next: NextFunction): Promise<void> => { | ||
try { | ||
const { orbis, table, context } = await getOrbisContext() | ||
const validationResults = await orbis.select().from(table).context(context).run() | ||
|
||
res.locals = { | ||
...res.locals, | ||
validations: validationResults.rows.length ? validationResults.rows : null, | ||
} | ||
return next() | ||
} catch (error) { | ||
console.error(error) | ||
next(error) | ||
} | ||
} | ||
|
||
export const readController = { | ||
readValidations, | ||
} |
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,41 @@ | ||
import { RequestHandler, Request, Response, Router } from 'express' | ||
import { writeController } from '@/controllers/writeController.js' | ||
import { readController } from '@/controllers/readController.js' | ||
|
||
const router: Router = Router() | ||
|
||
type PostResponse = Response & { | ||
locals: { | ||
validationUpdate: unknown | ||
streamID: string | ||
} | ||
} | ||
|
||
type ReadResponse = Response & { | ||
locals: { | ||
validations: unknown | ||
} | ||
} | ||
|
||
router.post( | ||
'/write', | ||
writeController.writeValidation as RequestHandler, | ||
(_req: Request, res: PostResponse) => { | ||
return res.json({ | ||
validationUpdate: res.locals.validationUpdate, | ||
streamID: res.locals.streamID, | ||
}) | ||
}, | ||
) | ||
|
||
router.get( | ||
'/read', | ||
readController.readValidations as RequestHandler, | ||
(_req: Request, res: ReadResponse) => { | ||
return res.json({ | ||
validations: res.locals.validations, | ||
}) | ||
}, | ||
) | ||
|
||
export default router |
This file was deleted.
Oops, something went wrong.