mirror of
https://github.com/R0m1k3/Regisflow.git
synced 2026-10-11 17:29:48 +02:00
Standardize naming conventions for photo fields in the sales table schema using Drizzle ORM. Replit-Commit-Author: Agent Replit-Commit-Session-Id: dec54137-d5a2-4406-8ad4-5f2f9fb110bf Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/0715008c-7244-40f4-befc-26c014852236/e8963daf-6ce4-40c7-aab9-e1134317a31e.jpg
146 lines
4.4 KiB
TypeScript
146 lines
4.4 KiB
TypeScript
import {
|
|
pgTable,
|
|
text,
|
|
varchar,
|
|
timestamp,
|
|
jsonb,
|
|
index,
|
|
serial,
|
|
integer,
|
|
boolean,
|
|
} from "drizzle-orm/pg-core";
|
|
import { relations } from "drizzle-orm";
|
|
import { createInsertSchema } from "drizzle-zod";
|
|
import { z } from "zod";
|
|
|
|
// Session storage table
|
|
export const sessions = pgTable(
|
|
"sessions",
|
|
{
|
|
sid: varchar("sid").primaryKey(),
|
|
sess: jsonb("sess").notNull(),
|
|
expire: timestamp("expire").notNull(),
|
|
},
|
|
(table) => [index("IDX_session_expire").on(table.expire)],
|
|
);
|
|
|
|
// Magasins table
|
|
export const stores = pgTable("stores", {
|
|
id: serial("id").primaryKey(),
|
|
name: varchar("name", { length: 255 }).notNull(),
|
|
address: text("address"),
|
|
phone: varchar("phone", { length: 20 }),
|
|
email: varchar("email", { length: 255 }),
|
|
isActive: boolean("is_active").default(true),
|
|
createdAt: timestamp("created_at").defaultNow(),
|
|
updatedAt: timestamp("updated_at").defaultNow(),
|
|
});
|
|
|
|
// Users table with authentication
|
|
export const users = pgTable("users", {
|
|
id: serial("id").primaryKey(),
|
|
username: varchar("username", { length: 50 }).unique().notNull(),
|
|
password: varchar("password", { length: 255 }).notNull(), // Will be hashed
|
|
email: varchar("email", { length: 255 }).unique(),
|
|
firstName: varchar("first_name", { length: 100 }),
|
|
lastName: varchar("last_name", { length: 100 }),
|
|
role: varchar("role", { length: 20 }).notNull().default("employee"), // admin, manager, employee
|
|
storeId: integer("store_id").references(() => stores.id),
|
|
isActive: boolean("is_active").default(true),
|
|
createdAt: timestamp("created_at").defaultNow(),
|
|
updatedAt: timestamp("updated_at").defaultNow(),
|
|
});
|
|
|
|
// Sales table
|
|
export const sales = pgTable("sales", {
|
|
id: serial("id").primaryKey(),
|
|
storeId: integer("store_id").references(() => stores.id).notNull(),
|
|
userId: integer("user_id").references(() => users.id).notNull(),
|
|
timestamp: timestamp("timestamp").defaultNow(),
|
|
|
|
// Vendeur
|
|
vendeur: varchar("vendeur", { length: 255 }).notNull(),
|
|
|
|
// Produit
|
|
typeArticle: varchar("type_article", { length: 255 }).notNull(),
|
|
categorie: varchar("categorie", { length: 2 }).notNull(),
|
|
quantite: integer("quantite").notNull(),
|
|
gencode: varchar("gencode", { length: 13 }).notNull(),
|
|
|
|
// Client
|
|
nom: varchar("nom", { length: 255 }).notNull(),
|
|
prenom: varchar("prenom", { length: 255 }).notNull(),
|
|
dateNaissance: varchar("date_naissance", { length: 10 }).notNull(),
|
|
lieuNaissance: varchar("lieu_naissance", { length: 255 }),
|
|
modePaiement: varchar("mode_paiement", { length: 50 }).notNull().default("Espèce"),
|
|
|
|
// Identité
|
|
typeIdentite: varchar("type_identite", { length: 50 }).notNull(),
|
|
numeroIdentite: varchar("numero_identite", { length: 100 }).notNull(),
|
|
autoriteDelivrance: varchar("autorite_delivrance", { length: 255 }).notNull(),
|
|
dateDelivrance: varchar("date_delivrance", { length: 10 }).notNull(),
|
|
|
|
// Photos
|
|
photo_recto: text("photo_recto"),
|
|
photo_verso: text("photo_verso"),
|
|
photo_ticket: text("photo_ticket"),
|
|
});
|
|
|
|
// Relations
|
|
export const storesRelations = relations(stores, ({ many }) => ({
|
|
users: many(users),
|
|
sales: many(sales),
|
|
}));
|
|
|
|
export const usersRelations = relations(users, ({ one, many }) => ({
|
|
store: one(stores, {
|
|
fields: [users.storeId],
|
|
references: [stores.id],
|
|
}),
|
|
sales: many(sales),
|
|
}));
|
|
|
|
export const salesRelations = relations(sales, ({ one }) => ({
|
|
store: one(stores, {
|
|
fields: [sales.storeId],
|
|
references: [stores.id],
|
|
}),
|
|
user: one(users, {
|
|
fields: [sales.userId],
|
|
references: [users.id],
|
|
}),
|
|
}));
|
|
|
|
// Insert schemas
|
|
export const insertUserSchema = createInsertSchema(users).omit({
|
|
id: true,
|
|
createdAt: true,
|
|
updatedAt: true,
|
|
});
|
|
|
|
export const insertStoreSchema = createInsertSchema(stores).omit({
|
|
id: true,
|
|
createdAt: true,
|
|
updatedAt: true,
|
|
});
|
|
|
|
export const insertSaleSchema = createInsertSchema(sales).omit({
|
|
id: true,
|
|
timestamp: true,
|
|
});
|
|
|
|
// Login schema
|
|
export const loginSchema = z.object({
|
|
username: z.string().min(1, "Nom d'utilisateur requis"),
|
|
password: z.string().min(1, "Mot de passe requis"),
|
|
});
|
|
|
|
// Types
|
|
export type User = typeof users.$inferSelect;
|
|
export type InsertUser = typeof users.$inferInsert;
|
|
export type Store = typeof stores.$inferSelect;
|
|
export type InsertStore = typeof stores.$inferInsert;
|
|
export type Sale = typeof sales.$inferSelect;
|
|
export type InsertSale = typeof sales.$inferInsert;
|
|
export type LoginData = z.infer<typeof loginSchema>;
|