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-11-25 16:51:47 -05:00
|
|
|
import { brand } from "@db/schema/Brand";
|
2024-11-21 15:24:37 -05:00
|
|
|
export const getData = async () => {
|
2024-11-21 15:58:57 -05:00
|
|
|
const data = await db.select().from(brand).orderBy(asc(brand.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) => {
|
|
|
|
|
await db.insert(brand).values({
|
|
|
|
|
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-11-21 15:24:37 -05:00
|
|
|
await db.delete(brand).where(eq(brand.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
|
|
|
|
|
.update(brand)
|
|
|
|
|
.set({
|
|
|
|
|
name: name,
|
|
|
|
|
})
|
|
|
|
|
.where(eq(brand.id, id));
|
|
|
|
|
revalidatePath("/");
|
|
|
|
|
};
|