This repository has been archived on 2026-01-31. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
nextjs-serve-actions/app/components/Dashboard/Items/ItemsTableRowAction.ts
2024-05-23 16:55:29 +02:00

29 lines
643 B
TypeScript

'use server';
import { z } from 'zod';
import { ItemComment } from '../../../../data/types';
import prisma from '../../../../prisma/prisma';
export async function ItemsTableRowAction(id: string) {
const validatedId = z.string().safeParse(id);
if (!validatedId.success) {
throw new Error('Bad request');
}
try {
const itemWithComments = await prisma.item.findFirstOrThrow({
where: {
id: validatedId.data
},
include: {
ItemComment: true
}
});
return itemWithComments.ItemComment as ItemComment[];
} catch (error) {
throw new Error('Failed to find item comments');
}
}