Refactor portfolio
This commit is contained in:
40
src/actions/portfolio/sortItems.ts
Normal file
40
src/actions/portfolio/sortItems.ts
Normal file
@ -0,0 +1,40 @@
|
||||
'use server';
|
||||
|
||||
import prisma from "@/lib/prisma";
|
||||
import { SortableItem } from "@/types/SortableItem";
|
||||
|
||||
export async function sortItems(items: SortableItem[], type: string) {
|
||||
|
||||
switch(type) {
|
||||
case "categories":
|
||||
await Promise.all(
|
||||
items.map(item =>
|
||||
prisma.portfolioCategory.update({
|
||||
where: { id: item.id },
|
||||
data: { sortIndex: item.sortIndex },
|
||||
})
|
||||
)
|
||||
);
|
||||
break;
|
||||
case "tags":
|
||||
await Promise.all(
|
||||
items.map(item =>
|
||||
prisma.portfolioTag.update({
|
||||
where: { id: item.id },
|
||||
data: { sortIndex: item.sortIndex },
|
||||
})
|
||||
)
|
||||
);
|
||||
break;
|
||||
case "types":
|
||||
await Promise.all(
|
||||
items.map(item =>
|
||||
prisma.portfolioType.update({
|
||||
where: { id: item.id },
|
||||
data: { sortIndex: item.sortIndex },
|
||||
})
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user