2024-11-22 11:14:00 -05:00
|
|
|
"use server";
|
|
|
|
|
import { eq, not , asc} from "drizzle-orm";
|
|
|
|
|
import { revalidatePath } from "next/cache";
|
|
|
|
|
import { db } from "../db";
|
2024-11-22 14:56:37 -05:00
|
|
|
import { Account } from "../db/schema/Account";
|
2024-11-22 11:14:00 -05:00
|
|
|
export const getData = async () => {
|
2024-11-22 14:56:37 -05:00
|
|
|
const data = await db.select().from(Account).orderBy(asc(Account.last_name));
|
2024-11-22 11:14:00 -05:00
|
|
|
return data;
|
|
|
|
|
};
|
2024-11-22 14:56:37 -05:00
|
|
|
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
|
2024-11-22 11:14:00 -05:00
|
|
|
});
|
|
|
|
|
};
|
2024-11-22 14:56:37 -05:00
|
|
|
export const deleteAccount = async (id: number) => {
|
|
|
|
|
await db.delete(Account).where(eq(Account.id, id));
|
2024-11-22 11:14:00 -05:00
|
|
|
revalidatePath("/");
|
|
|
|
|
};
|
2024-11-22 14:56:37 -05:00
|
|
|
export const editAccount = async (id: number, first_name: string, last_name: string, username: string, email : string, password_hash: string) => {
|
2024-11-22 11:14:00 -05:00
|
|
|
await db
|
2024-11-22 14:56:37 -05:00
|
|
|
.update(Account)
|
2024-11-22 11:14:00 -05:00
|
|
|
.set({
|
2024-11-22 14:56:37 -05:00
|
|
|
first_name : first_name,
|
|
|
|
|
last_name: last_name,
|
|
|
|
|
username: username,
|
|
|
|
|
email: email,
|
|
|
|
|
password_hash: password_hash
|
2024-11-22 11:14:00 -05:00
|
|
|
})
|
2024-11-22 14:56:37 -05:00
|
|
|
.where(eq(Account.id, id));
|
2024-11-22 11:14:00 -05:00
|
|
|
revalidatePath("/");
|
|
|
|
|
};
|