Initial Commit

This commit is contained in:
Ahmad 2024-02-14 21:30:10 -05:00
commit f3e2f01bd7
No known key found for this signature in database
GPG key ID: 8FD8A93530D182BF
150 changed files with 13612 additions and 0 deletions

View file

@ -0,0 +1,49 @@
"use server";
import { auth } from "@clerk/nextjs";
import { revalidatePath } from "next/cache";
import { db } from "@/lib/db";
import { createSafeAction } from "@/lib/create-safe-action";
import { InputType, ReturnType } from "./types";
import { UpdateCardOrder } from "./schema";
const handler = async (data: InputType): Promise<ReturnType> => {
const { userId, orgId } = auth();
if (!userId || !orgId) return { error: "Unauthorized" };
const { items, boardId } = data;
let updatedCards;
try {
const transaction = items.map((card) =>
db.card.update({
where: {
id: card.id,
list: {
board: {
orgId,
},
},
},
data: {
order: card.order,
listId: card.listId,
},
})
);
updatedCards = await db.$transaction(transaction);
} catch (error) {
return {
error: "Failed to reorder list",
};
}
revalidatePath(`/board/${boardId}`);
return { data: updatedCards };
};
export const updateCardOrder = createSafeAction(UpdateCardOrder, handler);