Add categories and suppliers with CRUD routes
- category table with hierarchical parent_id, sort ordering, soft-delete - supplier table with contact info, account number, payment terms - CRUD routes for both with search on suppliers - Zod validation schemas in @forte/shared - Products will link to suppliers via join table (many-to-many) - 26 tests passing
This commit is contained in:
39
packages/backend/src/db/schema/inventory.ts
Normal file
39
packages/backend/src/db/schema/inventory.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { pgTable, uuid, varchar, text, timestamp, boolean, integer } from 'drizzle-orm/pg-core'
|
||||
import { companies } from './stores.js'
|
||||
|
||||
export const categories = pgTable('category', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
companyId: uuid('company_id')
|
||||
.notNull()
|
||||
.references(() => companies.id),
|
||||
parentId: uuid('parent_id'),
|
||||
name: varchar('name', { length: 255 }).notNull(),
|
||||
description: text('description'),
|
||||
sortOrder: integer('sort_order').notNull().default(0),
|
||||
isActive: boolean('is_active').notNull().default(true),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
})
|
||||
|
||||
export const suppliers = pgTable('supplier', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
companyId: uuid('company_id')
|
||||
.notNull()
|
||||
.references(() => companies.id),
|
||||
name: varchar('name', { length: 255 }).notNull(),
|
||||
contactName: varchar('contact_name', { length: 255 }),
|
||||
email: varchar('email', { length: 255 }),
|
||||
phone: varchar('phone', { length: 50 }),
|
||||
website: varchar('website', { length: 255 }),
|
||||
accountNumber: varchar('account_number', { length: 100 }),
|
||||
paymentTerms: varchar('payment_terms', { length: 100 }),
|
||||
notes: text('notes'),
|
||||
isActive: boolean('is_active').notNull().default(true),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
})
|
||||
|
||||
export type Category = typeof categories.$inferSelect
|
||||
export type CategoryInsert = typeof categories.$inferInsert
|
||||
export type Supplier = typeof suppliers.$inferSelect
|
||||
export type SupplierInsert = typeof suppliers.$inferInsert
|
||||
Reference in New Issue
Block a user