Refactor to accommodate authentication, transaction and pagination states together (#4636)

* fix: refactor to accommodate authentication, transaction and pagination together into ctx.state

* feat: allow passing response type to APIContext
This commit is contained in:
Apoorv Mishra
2023-01-04 23:51:44 +05:30
committed by GitHub
parent bb568d2e62
commit f4461573de
31 changed files with 753 additions and 675 deletions

View File

@@ -4,16 +4,17 @@ import { rateLimiter } from "@server/middlewares/rateLimiter";
import { View, Document, Event } from "@server/models";
import { authorize } from "@server/policies";
import { presentView } from "@server/presenters";
import { APIContext } from "@server/types";
import { RateLimiterStrategy } from "@server/utils/RateLimiter";
import { assertUuid } from "@server/validation";
const router = new Router();
router.post("views.list", auth(), async (ctx) => {
router.post("views.list", auth(), async (ctx: APIContext) => {
const { documentId, includeSuspended = false } = ctx.request.body;
assertUuid(documentId, "documentId is required");
const { user } = ctx.state;
const { user } = ctx.state.auth;
const document = await Document.findByPk(documentId, {
userId: user.id,
});
@@ -29,11 +30,11 @@ router.post(
"views.create",
auth(),
rateLimiter(RateLimiterStrategy.OneThousandPerHour),
async (ctx) => {
async (ctx: APIContext) => {
const { documentId } = ctx.request.body;
assertUuid(documentId, "documentId is required");
const { user } = ctx.state;
const { user } = ctx.state.auth;
const document = await Document.findByPk(documentId, {
userId: user.id,
});