accounts stuff

This commit is contained in:
2024-11-22 14:56:37 -05:00
parent 4f461cfc40
commit c0ae295734
5 changed files with 24 additions and 16 deletions

BIN
bun.lockb Executable file

Binary file not shown.

View File

@@ -40,6 +40,7 @@
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@types/bun": "^1.1.13",
"@types/node": "^20.17.6",
"@types/pg": "^8.11.10",
"@types/react": "^18",

View File

@@ -2,26 +2,30 @@
import { eq, not , asc} from "drizzle-orm";
import { revalidatePath } from "next/cache";
import { db } from "../db";
import { brand } from "../db/schema/Brand";
import { Account } from "../db/schema/Account";
export const getData = async () => {
const data = await db.select().from(brand).orderBy(asc(brand.name));
const data = await db.select().from(Account).orderBy(asc(Account.last_name));
return data;
};
export const addBrand = async ( name: string) => {
await db.insert(brand).values({
name: name,
export const addAccount = async ( first_name: string, last_name: string, username: string, email: string, password_hash : string) => {
await db.insert(Account).values({
first_name : first_name, last_name: last_name, username: username, password_hash : password_hash
});
};
export const deleteBrand = async (id: number) => {
await db.delete(brand).where(eq(brand.id, id));
export const deleteAccount = async (id: number) => {
await db.delete(Account).where(eq(Account.id, id));
revalidatePath("/");
};
export const editBrand = async (id: number, name: string) => {
export const editAccount = async (id: number, first_name: string, last_name: string, username: string, email : string, password_hash: string) => {
await db
.update(brand)
.update(Account)
.set({
name: name,
first_name : first_name,
last_name: last_name,
username: username,
email: email,
password_hash: password_hash
})
.where(eq(brand.id, id));
.where(eq(Account.id, id));
revalidatePath("/");
};

View File

@@ -1,11 +1,12 @@
import { getData } from "../../actions/brandActions";
import { Account } from "@/db/schema/Account";
import { getData } from "../../actions/accountActions";
import Brands from "../../components/Brand/brands";
export default async function BrandsPage() {
export default async function AccountsPage() {
const data = await getData();
return (
<div className="bg-gray-100 min-h-screen flex flex-col">
<Brands brands={data} />
{/* <Account account={data} /> */}
</div>
);
}

View File

@@ -1,4 +1,6 @@
// db/queries.ts
"use server";
import { eq, not , asc} from "drizzle-orm";
import { Account } from '../schema/Account'
import { db } from '../index';
@@ -14,10 +16,10 @@ export async function addAcount(first_name: string, last_name : string, username
// Update a account
export async function updateAcount(id: number, first_name: string, last_name : string, username : string, password_hash: string ) {
return await db.update(Account).set({ first_name, last_name, username, password_hash }).where(Account.id.equals(id));
return await db.update(Account).set({ first_name, last_name, username, password_hash }).where(eq(Account.id, id));
}
// Delete a account
export async function deleteAccount(id: number) {
return await db.delete(Account).where(Account.id.equals(id));
return await db.delete(Account).where(eq(Account.id, id));
}