From 2d69cf76d7128648db2aa873e9033eca5e400ba7 Mon Sep 17 00:00:00 2001 From: Donald Strawsburg Date: Fri, 22 Nov 2024 11:14:00 -0500 Subject: [PATCH] adding accouns screens --- src/actions/accountActions.ts | 27 +++++++++++++++++++++++++++ src/app/Accounts/page.tsx | 12 ++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/actions/accountActions.ts create mode 100644 src/app/Accounts/page.tsx diff --git a/src/actions/accountActions.ts b/src/actions/accountActions.ts new file mode 100644 index 0000000..b10c83b --- /dev/null +++ b/src/actions/accountActions.ts @@ -0,0 +1,27 @@ +"use server"; +import { eq, not , asc} from "drizzle-orm"; +import { revalidatePath } from "next/cache"; +import { db } from "../db"; +import { brand } from "../db/schema/Brand"; +export const getData = async () => { + const data = await db.select().from(brand).orderBy(asc(brand.name)); + return data; +}; +export const addBrand = async ( name: string) => { + await db.insert(brand).values({ + name: name, + }); +}; +export const deleteBrand = async (id: number) => { + await db.delete(brand).where(eq(brand.id, id)); + revalidatePath("/"); +}; +export const editBrand = async (id: number, name: string) => { + await db + .update(brand) + .set({ + name: name, + }) + .where(eq(brand.id, id)); + revalidatePath("/"); +}; \ No newline at end of file diff --git a/src/app/Accounts/page.tsx b/src/app/Accounts/page.tsx new file mode 100644 index 0000000..e68f00e --- /dev/null +++ b/src/app/Accounts/page.tsx @@ -0,0 +1,12 @@ +import { getData } from "../../actions/brandActions"; +import Brands from "../../components/Brand/brands"; + +export default async function BrandsPage() { + const data = await getData(); + return ( +
+ +
+ ); +} +