Add board type binding support
This commit is contained in:
1 parent
07ff25bf7e
commit
f76b22b303
16 files changed
+496
-99
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import { BOARD_TYPES } from '@/lib/boards';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { badRequest, json, ok, serverError, unauthorized } from '@/lib/response';
|
||||
import { canDeleteBoard, canUpdateBoard, canViewBoard } from '@/permissions';
|
||||
@@ -24,6 +25,15 @@ export async function GET(request: Request, { params }: { params: Promise<{ boar
|
||||
|
||||
export async function POST(request: Request, { params }: { params: Promise<{ boardId: string }> }) {
|
||||
const schema = z.object({
|
||||
type: z
|
||||
.enum([
|
||||
BOARD_TYPES.dashboard,
|
||||
BOARD_TYPES.open,
|
||||
BOARD_TYPES.website,
|
||||
BOARD_TYPES.pixel,
|
||||
BOARD_TYPES.link,
|
||||
])
|
||||
.optional(),
|
||||
name: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
parameters: z.object({}).passthrough().optional(),
|
||||
@@ -36,14 +46,14 @@ export async function POST(request: Request, { params }: { params: Promise<{ boa
|
||||
}
|
||||
|
||||
const { boardId } = await params;
|
||||
const { name, description, parameters } = body;
|
||||
const { type, name, description, parameters } = body;
|
||||
|
||||
if (!(await canUpdateBoard(auth, boardId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
try {
|
||||
const board = await updateBoard(boardId, { name, description, parameters });
|
||||
const board = await updateBoard(boardId, { type, name, description, parameters });
|
||||
|
||||
return Response.json(board);
|
||||
} catch (e: any) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import { BOARD_TYPES } from '@/lib/boards';
|
||||
import { uuid } from '@/lib/crypto';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
@@ -27,13 +28,20 @@ export async function GET(request: Request) {
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const schema = z.object({
|
||||
type: z.string(),
|
||||
type: z.enum([BOARD_TYPES.open, BOARD_TYPES.website, BOARD_TYPES.pixel, BOARD_TYPES.link]),
|
||||
name: z.string().max(100),
|
||||
description: z.string().max(500).optional(),
|
||||
slug: z.string().max(100),
|
||||
userId: z.uuid().nullable().optional(),
|
||||
teamId: z.uuid().nullable().optional(),
|
||||
parameters: z.object({ websiteId: z.uuid().optional() }).passthrough().optional(),
|
||||
parameters: z
|
||||
.object({
|
||||
websiteId: z.uuid().optional(),
|
||||
pixelId: z.uuid().optional(),
|
||||
linkId: z.uuid().optional(),
|
||||
})
|
||||
.passthrough()
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
|
||||
Reference in new issue
Block a user