mirror of
https://gitea.gofwd.group/dstrawsb/ballistic-builder.git
synced 2025-12-06 02:36:44 -05:00
more, more, more
This commit is contained in:
@@ -7,15 +7,19 @@ export const getData = async () => {
|
|||||||
const data = await db.select().from(brand).orderBy(asc(brand.name));
|
const data = await db.select().from(brand).orderBy(asc(brand.name));
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addBrand = async ( name: string) => {
|
export const addBrand = async ( name: string) => {
|
||||||
await db.insert(brand).values({
|
await db.insert(brand).values({
|
||||||
name: name,
|
name: name,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteBrand = async (id: number) => {
|
export const deleteBrand = async (id: number) => {
|
||||||
|
"use server";
|
||||||
await db.delete(brand).where(eq(brand.id, id));
|
await db.delete(brand).where(eq(brand.id, id));
|
||||||
revalidatePath("/");
|
revalidatePath("/Brands");
|
||||||
};
|
};
|
||||||
|
|
||||||
export const editBrand = async (id: number, name: string) => {
|
export const editBrand = async (id: number, name: string) => {
|
||||||
await db
|
await db
|
||||||
.update(brand)
|
.update(brand)
|
||||||
|
|||||||
10
src/actions/manufacturerActions.ts
Normal file
10
src/actions/manufacturerActions.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
"use server";
|
||||||
|
import { eq, not , asc} from "drizzle-orm";
|
||||||
|
import { revalidatePath } from "next/cache";
|
||||||
|
import { db } from "../db";
|
||||||
|
import { manufacturer } from "@/db/schema/Manufacturer";
|
||||||
|
export const getData = async () => {
|
||||||
|
const data = await db.select().from(manufacturer).orderBy(asc(manufacturer.name));
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Account } from "@/db/schema/Account";
|
import { Account } from "@/db/schema/Account";
|
||||||
import { getData } from "../../actions/accountActions";
|
import { getData } from "../../actions/accountActions";
|
||||||
import Brands from "../../components/Brand/brands";
|
import Brands from "../../components/Brand/BrandsList";
|
||||||
|
|
||||||
export default async function AccountsPage() {
|
export default async function AccountsPage() {
|
||||||
const data = await getData();
|
const data = await getData();
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { getData } from "../../actions/brandActions";
|
import { getData } from "../../actions/brandActions";
|
||||||
import Brands from "../../components/Brand/brands";
|
import BrandsList from "../../components/Brand/BrandsList";
|
||||||
|
|
||||||
export default async function BrandsPage() {
|
export default async function BrandsPage() {
|
||||||
const data = await getData();
|
const data = await getData();
|
||||||
return (
|
return (
|
||||||
<div className="bg-gray-100 min-h-screen flex flex-col">
|
<div className="bg-gray-100 min-h-screen flex flex-col">
|
||||||
<Brands brands={data} />
|
<BrandsList brands={data} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,18 @@ import { addBrand, deleteBrand, editBrand } from "../../actions/brandActions";
|
|||||||
interface Props {
|
interface Props {
|
||||||
brands: brandType[];
|
brands: brandType[];
|
||||||
}
|
}
|
||||||
const Brands: FC<Props> = ({ brands }) => {
|
|
||||||
|
const BrandsList: FC<Props> = ({ brands }) => {
|
||||||
// State to manage the list of brand items
|
// State to manage the list of brand items
|
||||||
const [brandItems, setBrandItems] = useState<brandType[]>(brands);
|
const [brandItems, setBrandItems] = useState<brandType[]>(brands);
|
||||||
|
|
||||||
// Function to create a new brand item
|
// Function to create a new brand item
|
||||||
const createBrand = (name: string) => {
|
const createBrand = (name: string) => {
|
||||||
const id = (brandItems.at(-1)?.id || 0) + 1;
|
const id = (brandItems.at(-1)?.id || 0) + 1;
|
||||||
addBrand(name);
|
addBrand(name);
|
||||||
setBrandItems((prev) => [...prev, { id: id, name: name }]);
|
setBrandItems((prev) => [...prev, { id: id, name: name }]);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to change the text of a brand item
|
// Function to change the text of a brand item
|
||||||
const changeBrandName = (id: number, name: string) => {
|
const changeBrandName = (id: number, name: string) => {
|
||||||
setBrandItems((prev) =>
|
setBrandItems((prev) =>
|
||||||
@@ -25,10 +28,11 @@ const Brands: FC<Props> = ({ brands }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Function to delete a brand item
|
// Function to delete a brand item
|
||||||
const deleteTodoItem = (id: number) => {
|
const deleteBrandItem = (id: number) => {
|
||||||
setBrandItems((prev) => prev.filter((brand) => brand.id !== id));
|
setBrandItems((prev) => prev.filter((brand) => brand.id !== id));
|
||||||
deleteBrand(id);
|
deleteBrand(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Rendering the brand List component
|
// Rendering the brand List component
|
||||||
return (
|
return (
|
||||||
<main className="flex mx-auto max-w-xl w-full min-h-screen flex-col items-center p-16">
|
<main className="flex mx-auto max-w-xl w-full min-h-screen flex-col items-center p-16">
|
||||||
@@ -49,4 +53,4 @@ const Brands: FC<Props> = ({ brands }) => {
|
|||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default Brands;
|
export default BrandsList;
|
||||||
@@ -40,7 +40,7 @@ const Brand: FC<Props> = ({
|
|||||||
deleteBrand(brand.id);
|
deleteBrand(brand.id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Rendering the Todo component
|
// Rendering the Brands component
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-2 p-4 border-gray-200 border-solid border rounded-lg">
|
<div className="flex items-center gap-2 p-4 border-gray-200 border-solid border rounded-lg">
|
||||||
{/* Checkbox for marking the todo as done */}
|
{/* Checkbox for marking the todo as done */}
|
||||||
|
|||||||
9
src/db/schema/ComponentTypes.ts
Normal file
9
src/db/schema/ComponentTypes.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { pgTable, integer, varchar } from "drizzle-orm/pg-core";
|
||||||
|
import { sql } from "drizzle-orm";
|
||||||
|
import { timestamps } from "./helpers/columns.helpers";
|
||||||
|
|
||||||
|
export const ComponentType = pgTable("component_type", {
|
||||||
|
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "component_type_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||||
|
name: varchar({length: 100}).notNull(),
|
||||||
|
...timestamps
|
||||||
|
})
|
||||||
9
src/db/schema/Manufacturer.ts
Normal file
9
src/db/schema/Manufacturer.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { pgTable, integer, varchar } from "drizzle-orm/pg-core";
|
||||||
|
import { sql } from "drizzle-orm";
|
||||||
|
import { timestamps } from "./helpers/columns.helpers";
|
||||||
|
|
||||||
|
export const manufacturer = pgTable("manufacturer", {
|
||||||
|
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "manufacturer_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||||
|
name: varchar({length:100}).notNull(),
|
||||||
|
...timestamps
|
||||||
|
})
|
||||||
12
src/types/accountType.ts
Normal file
12
src/types/accountType.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
export type brandType = {
|
||||||
|
id: number;
|
||||||
|
first_name: string;
|
||||||
|
last_name: string;
|
||||||
|
username : string;
|
||||||
|
email: string;
|
||||||
|
password_hash: string;
|
||||||
|
updated_at: Date;
|
||||||
|
created_at: Date;
|
||||||
|
deleted_at: Date;
|
||||||
|
|
||||||
|
};
|
||||||
9
src/types/allTypes.ts
Normal file
9
src/types/allTypes.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export type brandType = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type manufacturerType = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
4
src/types/manufacturerType.ts
Normal file
4
src/types/manufacturerType.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export type manufacturerType = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user