Area restrita - Questionario
This commit is contained in:
+109
@@ -0,0 +1,109 @@
|
||||
import {
|
||||
mysqlTable,
|
||||
mysqlEnum,
|
||||
serial,
|
||||
varchar,
|
||||
text,
|
||||
timestamp,
|
||||
// bigint,
|
||||
} from "drizzle-orm/mysql-core";
|
||||
|
||||
export const users = mysqlTable("users", {
|
||||
id: serial("id").primaryKey(),
|
||||
unionId: varchar("unionId", { length: 255 }).notNull().unique(),
|
||||
name: varchar("name", { length: 255 }),
|
||||
email: varchar("email", { length: 320 }),
|
||||
avatar: text("avatar"),
|
||||
role: mysqlEnum("role", ["user", "admin"]).default("user").notNull(),
|
||||
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updatedAt")
|
||||
.defaultNow()
|
||||
.notNull()
|
||||
.$onUpdate(() => new Date()),
|
||||
lastSignInAt: timestamp("lastSignInAt").defaultNow().notNull(),
|
||||
});
|
||||
|
||||
export type User = typeof users.$inferSelect;
|
||||
export type InsertUser = typeof users.$inferInsert;
|
||||
|
||||
// ============================================================================
|
||||
// SISTEMA DE FORMULARIOS - Area do Cliente Avanzato
|
||||
// ============================================================================
|
||||
|
||||
// Formularios criados pela Avanzato para clientes
|
||||
export const clientForms = mysqlTable("client_forms", {
|
||||
id: serial("id").primaryKey(),
|
||||
title: varchar("title", { length: 255 }).notNull(),
|
||||
description: text("description"),
|
||||
clientName: varchar("clientName", { length: 255 }).notNull(),
|
||||
clientEmail: varchar("clientEmail", { length: 320 }),
|
||||
status: mysqlEnum("status", ["active", "inactive", "archived"]).default("inactive").notNull(),
|
||||
accessCode: varchar("access_code", { length: 32 }).notNull().unique(),
|
||||
createdBy: varchar("created_by", { length: 255 }),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at").defaultNow().notNull().$onUpdate(() => new Date()),
|
||||
});
|
||||
|
||||
export type ClientForm = typeof clientForms.$inferSelect;
|
||||
export type InsertClientForm = typeof clientForms.$inferInsert;
|
||||
|
||||
// Secoes de cada formulario
|
||||
export const formSections = mysqlTable("form_sections", {
|
||||
id: serial("id").primaryKey(),
|
||||
formId: varchar("form_id", { length: 32 }).notNull(),
|
||||
title: varchar("title", { length: 255 }).notNull(),
|
||||
description: text("description"),
|
||||
orderNum: serial("order_num"),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
});
|
||||
|
||||
export type FormSection = typeof formSections.$inferSelect;
|
||||
|
||||
// Perguntas/Campos de cada secao
|
||||
export const formQuestions = mysqlTable("form_questions", {
|
||||
id: serial("id").primaryKey(),
|
||||
formId: varchar("form_id", { length: 32 }).notNull(),
|
||||
sectionId: varchar("section_id", { length: 32 }),
|
||||
question: text("question").notNull(),
|
||||
fieldType: mysqlEnum("field_type", ["text", "textarea", "number", "select", "multiselect", "date", "file"]).default("text").notNull(),
|
||||
options: text("options"), // JSON string para select/multiselect
|
||||
required: mysqlEnum("required", ["yes", "no"]).default("no").notNull(),
|
||||
orderNum: serial("order_num"),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
});
|
||||
|
||||
export type FormQuestion = typeof formQuestions.$inferSelect;
|
||||
|
||||
// Respostas submetidas pelos clientes
|
||||
export const formAnswers = mysqlTable("form_answers", {
|
||||
id: serial("id").primaryKey(),
|
||||
formId: varchar("form_id", { length: 32 }).notNull(),
|
||||
questionId: varchar("question_id", { length: 32 }).notNull(),
|
||||
answer: text("answer"),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
});
|
||||
|
||||
export type FormAnswer = typeof formAnswers.$inferSelect;
|
||||
|
||||
// Submissoes completas (uma por formulario preenchido)
|
||||
export const formSubmissions = mysqlTable("form_submissions", {
|
||||
id: serial("id").primaryKey(),
|
||||
formId: varchar("form_id", { length: 32 }).notNull(),
|
||||
submittedBy: varchar("submitted_by", { length: 255 }),
|
||||
submittedByEmail: varchar("submitted_by_email", { length: 320 }),
|
||||
notes: text("notes"),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
});
|
||||
|
||||
export type FormSubmission = typeof formSubmissions.$inferSelect;
|
||||
//
|
||||
// Example:
|
||||
// export const posts = mysqlTable("posts", {
|
||||
// id: serial("id").primaryKey(),
|
||||
// title: varchar("title", { length: 255 }).notNull(),
|
||||
// content: text("content"),
|
||||
// createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
// });
|
||||
//
|
||||
// Note: FK columns referencing a serial() PK must use:
|
||||
// bigint("columnName", { mode: "number", unsigned: true }).notNull()
|
||||
Reference in New Issue
Block a user