Files
ballistic-builder/src/actions/brandActions.ts

31 lines
752 B
TypeScript
Raw Normal View History

2024-11-21 15:24:37 -05:00
"use server";
2024-11-21 15:58:57 -05:00
import { eq, not , asc} from "drizzle-orm";
2024-11-21 15:24:37 -05:00
import { revalidatePath } from "next/cache";
import { db } from "../db";
2024-12-17 13:44:08 -05:00
import { brands } from "@schemas/schema";
2024-11-21 15:24:37 -05:00
export const getData = async () => {
2024-12-17 13:44:08 -05:00
const data = await db.select().from(brands).orderBy(asc(brands.name));
2024-11-21 15:24:37 -05:00
return data;
};
2024-11-22 16:16:04 -05:00
2024-11-21 15:24:37 -05:00
export const addBrand = async ( name: string) => {
2024-12-17 13:44:08 -05:00
await db.insert(brands).values({
2024-11-21 15:24:37 -05:00
name: name,
});
};
2024-11-22 16:16:04 -05:00
2024-11-21 15:24:37 -05:00
export const deleteBrand = async (id: number) => {
2024-11-22 16:16:04 -05:00
"use server";
2024-12-17 13:44:08 -05:00
await db.delete(brands).where(eq(brands.id, id));
2024-11-22 16:16:04 -05:00
revalidatePath("/Brands");
2024-11-21 15:24:37 -05:00
};
2024-11-22 16:16:04 -05:00
2024-11-21 15:24:37 -05:00
export const editBrand = async (id: number, name: string) => {
await db
2024-12-17 13:44:08 -05:00
.update(brands)
2024-11-21 15:24:37 -05:00
.set({
name: name,
})
2024-12-17 13:44:08 -05:00
.where(eq(brands.id, id));
2024-11-21 15:24:37 -05:00
revalidatePath("/");
};