2024-11-22 11:14:00 -05:00
|
|
|
"use server";
|
|
|
|
|
import { eq, not , asc} from "drizzle-orm";
|
|
|
|
|
import { revalidatePath } from "next/cache";
|
2025-01-16 21:26:30 -05:00
|
|
|
import { db } from "@db/index";
|
2024-12-17 13:44:08 -05:00
|
|
|
import { accounts } from "@schemas/schema";
|
2024-11-25 17:09:47 -05:00
|
|
|
|
2024-11-22 11:14:00 -05:00
|
|
|
export const getData = async () => {
|
2024-12-17 13:44:08 -05:00
|
|
|
const data = await db.select().from(accounts).orderBy(asc(accounts.last_name));
|
2024-11-22 11:14:00 -05:00
|
|
|
return data;
|
|
|
|
|
};
|
2024-11-25 17:09:47 -05:00
|
|
|
|
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) => {
|
2024-12-17 13:44:08 -05:00
|
|
|
/* await db.insert(accounts).values({
|
2024-11-22 14:56:37 -05:00
|
|
|
first_name : first_name, last_name: last_name, username: username, password_hash : password_hash
|
2024-12-17 13:44:08 -05:00
|
|
|
}); */
|
2024-11-22 11:14:00 -05:00
|
|
|
};
|
2024-11-25 17:09:47 -05:00
|
|
|
|
2024-11-22 14:56:37 -05:00
|
|
|
export const deleteAccount = async (id: number) => {
|
2024-12-17 13:44:08 -05:00
|
|
|
await db.delete(accounts).where(eq(accounts.userId, id));
|
2024-11-22 11:14:00 -05:00
|
|
|
revalidatePath("/");
|
|
|
|
|
};
|
2024-11-25 17:09:47 -05:00
|
|
|
|
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-12-17 13:44:08 -05:00
|
|
|
.update(accounts)
|
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-12-17 13:44:08 -05:00
|
|
|
.where(eq(accounts.userId, id));
|
2024-11-22 11:14:00 -05:00
|
|
|
revalidatePath("/");
|
|
|
|
|
};
|