feat: add workspace member assertion to remaining routers

This commit is contained in:
Henry
2025-05-26 22:03:39 +01:00
parent 76b65acc0f
commit 8a81d1ff17
7 changed files with 176 additions and 19 deletions

View File

@@ -12,6 +12,7 @@ import { colours } from "@kan/shared/constants";
import { generateUID } from "@kan/shared/utils";
import { createTRPCRouter, protectedProcedure } from "../trpc";
import { assertUserInWorkspace } from "../utils/auth";
const TRELLO_API_URL = "https://api.trello.com/1";
@@ -125,15 +126,6 @@ export const importRouter = createTRPCRouter({
code: "UNAUTHORIZED",
});
const newImport = await importRepo.create(ctx.db, {
source: "trello",
createdBy: userId,
});
const newImportId = newImport?.id;
let boardsCreated = 0;
const workspace = await workspaceRepo.getByPublicId(
ctx.db,
input.workspacePublicId,
@@ -145,6 +137,17 @@ export const importRouter = createTRPCRouter({
code: "NOT_FOUND",
});
await assertUserInWorkspace(ctx.db, userId, workspace.id);
const newImport = await importRepo.create(ctx.db, {
source: "trello",
createdBy: userId,
});
const newImportId = newImport?.id;
let boardsCreated = 0;
for (const boardId of input.boardIds) {
const response = await fetch(
`${TRELLO_API_URL}/boards/${boardId}?key=${input.apiKey}&token=${input.token}&lists=open&cards=open&labels=all`,