Move db calls to server file
This commit is contained in:
@@ -4,14 +4,13 @@ import TT_Header from "~/components/ui/TT_Header";
|
||||
import Techs_Table from "~/components/ui/Techs_Table";
|
||||
|
||||
export default async function HomePage() {
|
||||
const user = await auth();
|
||||
if (!user) {
|
||||
return (
|
||||
<No_Session />
|
||||
);
|
||||
const session = await auth();
|
||||
if (!session) {
|
||||
return <No_Session />
|
||||
} else {
|
||||
return (
|
||||
<main className="min-h-screen bg-gradient-to-b from-[#111111] to-[#111325]">
|
||||
<main className="min-h-screen bg-gradient-to-b
|
||||
from-[#111111] to-[#111325]">
|
||||
<TT_Header />
|
||||
<Techs_Table />
|
||||
</main>
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import { db } from '~/server/db';
|
||||
//import { auth } from "~/auth";
|
||||
import { getEmployees } from "~/server/functions";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function Techs_Table() {
|
||||
|
||||
const employees = await db.query.users.findMany({
|
||||
orderBy: (model, {desc}) => desc(model.id),
|
||||
});
|
||||
const employees = await getEmployees();
|
||||
|
||||
const formatTime = (timestamp: Date) => {
|
||||
const date = new Date(timestamp);
|
||||
@@ -14,35 +15,53 @@ export default async function Techs_Table() {
|
||||
const month = date.toLocaleString("default", { month: "long" });
|
||||
return `${time} - ${month} ${day}`;
|
||||
}
|
||||
//const session = await auth();
|
||||
//const users_name = session?.user?.name;
|
||||
|
||||
return (
|
||||
<table className="w-5/6 m-auto text-center border-collapse text-[42px]">
|
||||
<thead className="bg-gradient-to-br from-[#212121] to-[#333333]">
|
||||
<tr>
|
||||
<th className="p-5 border border-[#3e4446] text-[48px]"/>
|
||||
<th className="p-2 border border-[#3e4446] text-[48px]">
|
||||
Name
|
||||
</th>
|
||||
<th className="p-2 border border-[#3e4446] text-[48px]">
|
||||
Status
|
||||
</th>
|
||||
<th className="p-2 border border-[#3e4446] text-[48px]">
|
||||
Updated At
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{employees.map((employee) => (
|
||||
<tr className="even:bg-gradient-to-bl from-[#222222] to-[#232323]" key={employee.id}>
|
||||
<td className="p-1 border border-[#3e4446]">
|
||||
<input type="checkbox"/>
|
||||
</td>
|
||||
<td className="p-1 border border-[#3e4446]">{employee.name}</td>
|
||||
<td className="p-1 border border-[#3e4446]">{employee.status}</td>
|
||||
<td className="p-1 border border-[#3e4446]">{formatTime(employee.updatedAt)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<div>
|
||||
<table className="w-5/6 m-auto text-center border-collapse text-[42px]">
|
||||
<thead className="bg-gradient-to-br from-[#212121] to-[#333333]">
|
||||
<tr>
|
||||
<th className="p-5 border border-[#3e4446] text-[48px]"/>
|
||||
<th className="p-2 border border-[#3e4446] text-[48px]">
|
||||
Name
|
||||
</th>
|
||||
<th className="p-2 border border-[#3e4446] text-[48px]">
|
||||
Status
|
||||
</th>
|
||||
<th className="p-2 border border-[#3e4446] text-[48px]">
|
||||
Updated At
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{employees.map((employee) => (
|
||||
<tr className="even:bg-gradient-to-bl from-[#222222] to-[#232323]" key={employee.id}>
|
||||
<td className="p-1 border border-[#3e4446]">
|
||||
<input type="checkbox"
|
||||
className="m-0 cursor-pointer transform scale-150"
|
||||
//checked={}
|
||||
/>
|
||||
</td>
|
||||
<td className="p-1 border border-[#3e4446]">{employee.name}</td>
|
||||
<td className="p-1 border border-[#3e4446]">{employee.status}</td>
|
||||
<td className="p-1 border border-[#3e4446]">{formatTime(employee.updatedAt)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<div className="m-auto flex flex-row items-center justify-center">
|
||||
<input type="text" placeholder="New Status"
|
||||
className="w-1/5 p-2 border-none rounded-md"
|
||||
//value={}
|
||||
/>
|
||||
<button type="submit"
|
||||
className="m-2 px-2 py-5 border-none rounded-md text-center bg-gradient-to-br from-[#484848] to-[#333333]"
|
||||
>
|
||||
Update
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@@ -13,8 +13,8 @@ export const users = createTable(
|
||||
"users",
|
||||
{
|
||||
id: bigint("id", {mode: "number"}).primaryKey().autoincrement(),
|
||||
name: varchar("name", { length: 256 }),
|
||||
status: varchar("status", { length: 256 }),
|
||||
name: varchar("name", { length: 256 }).notNull(),
|
||||
status: varchar("status", { length: 256 }).notNull(),
|
||||
updatedAt: timestamp("updated_at")
|
||||
.default(sql`CURRENT_TIMESTAMP`)
|
||||
.notNull(),
|
||||
@@ -26,7 +26,7 @@ export const history = createTable(
|
||||
{
|
||||
id: bigint("id", {mode: "number"}).primaryKey().autoincrement(),
|
||||
user_id: bigint("user_id", {mode: "number"}).references(() => users.id),
|
||||
status: varchar("status", { length: 256 }),
|
||||
status: varchar("status", { length: 256 }).notNull(),
|
||||
updatedAt: timestamp("updated_at").notNull(),
|
||||
},
|
||||
);
|
||||
|
11
src/server/functions.ts
Normal file
11
src/server/functions.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import "server-only";
|
||||
import { db } from "~/server/db";
|
||||
//import * as schema from "~/server/db/schema";
|
||||
|
||||
export const getEmployees = async () => {
|
||||
return await db.query.users.findMany({
|
||||
orderBy: (model, { desc }) => desc(model.id),
|
||||
});
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user