chore: add all the code from original repo
This commit is contained in:
48
app/components/Dashboard/Items/actions/ItemsTableAction.ts
Normal file
48
app/components/Dashboard/Items/actions/ItemsTableAction.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
'use server';
|
||||
|
||||
import { Items } from '../../../../../data/types';
|
||||
import prisma from '../../../../../prisma/prisma';
|
||||
|
||||
interface ItemsTableActionProps {
|
||||
take: number;
|
||||
profile: string | undefined;
|
||||
}
|
||||
|
||||
export async function ItemsTableAction({
|
||||
take,
|
||||
profile
|
||||
}: ItemsTableActionProps) {
|
||||
if (!profile) {
|
||||
return [] as Items;
|
||||
}
|
||||
|
||||
try {
|
||||
const items = await prisma.item.findMany({
|
||||
where: {
|
||||
profileId: profile
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc'
|
||||
},
|
||||
include: {
|
||||
Tag: {
|
||||
select: {
|
||||
name: true
|
||||
}
|
||||
}
|
||||
},
|
||||
take
|
||||
});
|
||||
|
||||
const itemsWithTag = items.map((item) => {
|
||||
return {
|
||||
...item,
|
||||
tag: item?.Tag?.name
|
||||
};
|
||||
});
|
||||
|
||||
return itemsWithTag as Items;
|
||||
} catch (error) {
|
||||
throw new Error('Failed to find items');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user