Files
FEDEO/backend/db/schema/customers.ts
2026-02-21 21:21:27 +01:00

73 lines
2.1 KiB
TypeScript

import {
pgTable,
bigint,
text,
timestamp,
boolean,
jsonb,
smallint,
uuid,
} from "drizzle-orm/pg-core"
import { tenants } from "./tenants"
import { authUsers } from "./auth_users"
import { memberrelations } from "./memberrelations"
export const customers = pgTable(
"customers",
{
id: bigint("id", { mode: "number" })
.primaryKey()
.generatedByDefaultAsIdentity(),
createdAt: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
customerNumber: text("customerNumber").notNull(),
name: text("name").notNull(),
tenant: bigint("tenant", { mode: "number" }).notNull(),
infoData: jsonb("infoData").default({}),
active: boolean("active").notNull().default(true),
notes: text("notes"),
type: text("type").default("Privat"),
heroId: text("heroId"),
isCompany: boolean("isCompany").notNull().default(false),
profiles: jsonb("profiles").notNull().default([]),
customPaymentDays: smallint("customPaymentDays"),
firstname: text("firstname"),
lastname: text("lastname"),
archived: boolean("archived").notNull().default(false),
customSurchargePercentage: smallint("customSurchargePercentage")
.notNull()
.default(0),
salutation: text("salutation"),
title: text("title"),
nameAddition: text("nameAddition"),
availableInPortal: boolean("availableInPortal")
.notNull()
.default(false),
updatedAt: timestamp("updated_at", { withTimezone: true }),
updatedBy: uuid("updated_by").references(() => authUsers.id),
customPaymentType: text("custom_payment_type"), // ENUM payment_types separat?
customTaxType: text("customTaxType"),
memberrelation: bigint("memberrelation", { mode: "number" }).references(() => memberrelations.id),
}
)
export type Customer = typeof customers.$inferSelect
export type NewCustomer = typeof customers.$inferInsert