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:
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user