|
| 1 | +import { relations, sql } from "drizzle-orm"; |
| 2 | +import { pgTable, text, timestamp, uuid, varchar } from "drizzle-orm/pg-core"; |
| 3 | +import { createInsertSchema } from "drizzle-zod"; |
| 4 | +import { z } from "zod"; |
| 5 | + |
| 6 | +import { Industry, RequestStatus } from "./misc"; |
| 7 | + |
| 8 | +export const CompanyRequest = pgTable("company_request", { |
| 9 | + id: uuid("id").notNull().primaryKey().defaultRandom(), |
| 10 | + companyName: varchar("name").notNull(), |
| 11 | + companyDescription: text("description"), |
| 12 | + industry: varchar("industry").notNull(), |
| 13 | + location: varchar("location").notNull(), |
| 14 | + roleTitle: varchar("title").notNull(), |
| 15 | + roleDescription: text("description"), |
| 16 | + createdAt: timestamp("createdAt").defaultNow().notNull(), |
| 17 | + updatedAt: timestamp("updatedAt", { |
| 18 | + mode: "date", |
| 19 | + withTimezone: true, |
| 20 | + }).$onUpdateFn(() => sql`now()`), |
| 21 | + status: varchar("status", { |
| 22 | + enum: ["PENDING", "APPROVED", "REJECTED"], // Explicitly list the enum values |
| 23 | + }) |
| 24 | + .notNull() |
| 25 | + .default("PENDING"), |
| 26 | +}); |
| 27 | + |
| 28 | +export type CompanyRequestType = typeof CompanyRequest.$inferSelect; |
| 29 | + |
| 30 | +// export const RequestRelations = relations(Role, ({ one }) => ({ |
| 31 | +// company: one(Company, { |
| 32 | +// fields: [Role.companyId], |
| 33 | +// references: [Company.id], |
| 34 | +// }), |
| 35 | +// roles: one(Role), |
| 36 | +// })); |
| 37 | + |
| 38 | +// Zod validation schema for creating a company request |
| 39 | +export const CreateCompanyRequestSchema = createInsertSchema(CompanyRequest, { |
| 40 | + companyName: z.string(), |
| 41 | + companyDescription: z.string().optional(), |
| 42 | + industry: z.nativeEnum(Industry), |
| 43 | + location: z.string(), |
| 44 | + roleTitle: z.string(), |
| 45 | + roleDescription: z.string(), |
| 46 | + status: z.nativeEnum(RequestStatus), |
| 47 | +}).omit({ |
| 48 | + id: true, |
| 49 | + createdAt: true, |
| 50 | + updatedAt: true, |
| 51 | +}); |
| 52 | +// Example TypeScript type for the Company Request |
0 commit comments