Skip to content

Commit

Permalink
Define initial data schemas; fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pjborowiecki committed Jan 7, 2024
1 parent 5d879fc commit 86caf3b
Show file tree
Hide file tree
Showing 13 changed files with 595 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/actions/inventory/brands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { type brandSchema } from "@/validations/inventory"
import type { z } from "zod"

export async function addNewBrand(input: z.infer<typeof brandSchema>) {
export async function addBrand(input: z.infer<typeof brandSchema>) {
console.log(input.name)
console.log("Adding brand to the database...")
return new Promise((resolve) => {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/inventory/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { unitSchema } from "@/validations/inventory"
import type { z } from "zod"

export async function addNewUnit(input: z.infer<typeof unitSchema>) {
export async function addUnit(input: z.infer<typeof unitSchema>) {
console.log(input.name, input.abbreviation)
console.log("Adding unit to the database...")
return new Promise((resolve) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/forms/inventory/brands/add-brand-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import React from "react"
import Link from "next/link"
import { useRouter } from "next/navigation"
import { addNewBrand } from "@/actions/inventory/brands"
import { addBrand } from "@/actions/inventory/brands"
import { brandSchema } from "@/validations/inventory"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
Expand Down Expand Up @@ -40,7 +40,7 @@ export function AddBrandForm(): JSX.Element {
function onSubmit(formData: AddBrandFormInputs) {
startTransition(async () => {
try {
const response = await addNewBrand(formData)
const response = await addBrand(formData)

if (response === "success") {
toast({ title: "Success!", description: "New category added" })
Expand Down
10 changes: 5 additions & 5 deletions src/components/forms/inventory/categories/add-category-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import React from "react"
import Link from "next/link"
import { useRouter } from "next/navigation"
import { addNewCategory } from "@/actions/inventory/categories"
import { addCategorySchema } from "@/validations/inventory"
import { addCategory } from "@/actions/inventory/categories"
import { categorySchema } from "@/validations/inventory"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import type { z } from "zod"
Expand All @@ -24,15 +24,15 @@ import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
import { Icons } from "@/components/icons"

type AddCategoryFormInputs = z.infer<typeof addCategorySchema>
type AddCategoryFormInputs = z.infer<typeof categorySchema>

export function AddCategoryForm(): JSX.Element {
const { toast } = useToast()
const router = useRouter()
const [isPending, startTransition] = React.useTransition()

const form = useForm<AddCategoryFormInputs>({
resolver: zodResolver(addCategorySchema),
resolver: zodResolver(categorySchema),
defaultValues: {
name: "",
description: "",
Expand All @@ -42,7 +42,7 @@ export function AddCategoryForm(): JSX.Element {
function onSubmit(formData: AddCategoryFormInputs) {
startTransition(async () => {
try {
const response = await addNewCategory({
const response = await addCategory({
name: formData.name,
description: formData.description,
})
Expand Down
10 changes: 5 additions & 5 deletions src/components/forms/inventory/units/add-unit-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import React from "react"
import Link from "next/link"
import { useRouter } from "next/navigation"
import { addNewUnit } from "@/actions/inventory/units"
import { addUnitSchema } from "@/validations/inventory"
import { addUnit } from "@/actions/inventory/units"
import { unitSchema } from "@/validations/inventory"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import type { z } from "zod"
Expand All @@ -23,15 +23,15 @@ import {
import { Input } from "@/components/ui/input"
import { Icons } from "@/components/icons"

type AddUnitFormInputs = z.infer<typeof addUnitSchema>
type AddUnitFormInputs = z.infer<typeof unitSchema>

export function AddUnitForm(): JSX.Element {
const { toast } = useToast()
const router = useRouter()
const [isPending, startTransition] = React.useTransition()

const form = useForm<AddUnitFormInputs>({
resolver: zodResolver(addUnitSchema),
resolver: zodResolver(unitSchema),
defaultValues: {
name: "",
abbreviation: "",
Expand All @@ -41,7 +41,7 @@ export function AddUnitForm(): JSX.Element {
function onSubmit(formData: AddUnitFormInputs) {
startTransition(async () => {
try {
const response = await addNewUnit({
const response = await addUnit({
name: formData.name,
abbreviation: formData.abbreviation,
})
Expand Down
10 changes: 5 additions & 5 deletions src/components/forms/warehouses/add-warehouse-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import React from "react"
import Link from "next/link"
import { useRouter } from "next/navigation"
import { addNewWarehouse } from "@/actions/warehouses"
import { addWarehouseSchema } from "@/validations/warehouses"
import { addWarehouse } from "@/actions/warehouses"
import { warehouseSchema } from "@/validations/warehouses"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import type { z } from "zod"
Expand Down Expand Up @@ -32,15 +32,15 @@ import {
import { Textarea } from "@/components/ui/textarea"
import { Icons } from "@/components/icons"

type AddWarehouseFormInputs = z.infer<typeof addWarehouseSchema>
type AddWarehouseFormInputs = z.infer<typeof warehouseSchema>

export function AddWarehouseForm(): JSX.Element {
const { toast } = useToast()
const router = useRouter()
const [isPending, startTransition] = React.useTransition()

const form = useForm<AddWarehouseFormInputs>({
resolver: zodResolver(addWarehouseSchema),
resolver: zodResolver(warehouseSchema),
defaultValues: {
name: "",
type: "branch",
Expand All @@ -52,7 +52,7 @@ export function AddWarehouseForm(): JSX.Element {
function onSubmit(formData: AddWarehouseFormInputs) {
startTransition(async () => {
try {
const response = await addNewWarehouse(formData)
const response = await addWarehouse(formData)

if (response === "success") {
toast({ title: "Success!", description: "New category added" })
Expand Down
9 changes: 9 additions & 0 deletions src/db/migrations/0001_friendly_silver_samurai.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ALTER TABLE "items" ADD COLUMN "category" varchar(63) NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "brand" varchar(63) NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "barcode" varchar(63) NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "description" text;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "selling_price" numeric(10, 2) DEFAULT '0' NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "purchase_price" numeric(10, 2) DEFAULT '0' NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "images" json DEFAULT 'null'::json;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "created_at" timestamp DEFAULT now() NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "updated_at" timestamp DEFAULT now();
46 changes: 46 additions & 0 deletions src/db/migrations/0002_spooky_thor.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
CREATE TABLE IF NOT EXISTS "brands" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar(32) NOT NULL,
CONSTRAINT "brands_name_unique" UNIQUE("name")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "categories" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar(32) NOT NULL,
"description" text,
CONSTRAINT "categories_name_unique" UNIQUE("name")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "units" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar(24) NOT NULL,
"abbreviation" varchar(8) NOT NULL,
CONSTRAINT "units_name_unique" UNIQUE("name"),
CONSTRAINT "units_abbreviation_unique" UNIQUE("abbreviation")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "warehouses" (
"id" serial PRIMARY KEY NOT NULL,
"name" varchar(32) NOT NULL,
"type" varchar(32) NOT NULL,
"description" text,
"location" varchar(32) NOT NULL
);
--> statement-breakpoint
ALTER TABLE "items" ALTER COLUMN "name" SET DATA TYPE varchar(128);--> statement-breakpoint
ALTER TABLE "items" ALTER COLUMN "category" SET DATA TYPE varchar(64);--> statement-breakpoint
ALTER TABLE "items" ALTER COLUMN "brand" SET DATA TYPE varchar(64);--> statement-breakpoint
ALTER TABLE "items" ALTER COLUMN "barcode" SET DATA TYPE varchar(64);--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "tax_rate" numeric(3, 1) DEFAULT '0' NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "width" numeric(10, 2) DEFAULT '0' NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "height" numeric(10, 2) DEFAULT '0' NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "depth" numeric(10, 2) DEFAULT '0' NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "dimensions_unit" varchar(8) NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "weight" numeric(10, 2) DEFAULT '0' NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "warehouse" varchar NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "sku" varchar(128) NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "quantity" integer NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "unit" varchar(8) NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "reorder_point" integer NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "supplier" varchar(64) NOT NULL;--> statement-breakpoint
ALTER TABLE "items" ADD COLUMN "notes" text;
96 changes: 96 additions & 0 deletions src/db/migrations/meta/0001_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"id": "c94e65e8-8faf-4c7e-90ea-9b7040f619f1",
"prevId": "354d536f-c455-42b5-be06-72c96dbab27f",
"version": "5",
"dialect": "pg",
"tables": {
"items": {
"name": "items",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "varchar(127)",
"primaryKey": false,
"notNull": true
},
"category": {
"name": "category",
"type": "varchar(63)",
"primaryKey": false,
"notNull": true
},
"brand": {
"name": "brand",
"type": "varchar(63)",
"primaryKey": false,
"notNull": true
},
"barcode": {
"name": "barcode",
"type": "varchar(63)",
"primaryKey": false,
"notNull": true
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"selling_price": {
"name": "selling_price",
"type": "numeric(10, 2)",
"primaryKey": false,
"notNull": true,
"default": "'0'"
},
"purchase_price": {
"name": "purchase_price",
"type": "numeric(10, 2)",
"primaryKey": false,
"notNull": true,
"default": "'0'"
},
"images": {
"name": "images",
"type": "json",
"primaryKey": false,
"notNull": false,
"default": "'null'::json"
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"schemas": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
Loading

0 comments on commit 86caf3b

Please sign in to comment.