diff --git a/.agents/skills/verify-suni/features/customers.md b/.agents/skills/verify-suni/features/customers.md index 27ca44b..95ca26b 100644 --- a/.agents/skills/verify-suni/features/customers.md +++ b/.agents/skills/verify-suni/features/customers.md @@ -1,13 +1,13 @@ # Customers -Customers (`Clientes`) is the reference domain module. A signed-in user lists customers and filters them by name, type and status. They create a customer with an address filled from the postal code, open its detail page, edit it, and archive or unarchive it. There is no delete. +Customers (`Clientes`) is the reference domain module. A signed-in user lists customers and filters them by name and status. They create a customer with an address filled from the postal code, open its detail page, edit it, and archive or unarchive it. There is no delete. ## Sub-features - `customers-list` shows active customers as cards, with loading, empty and error states. -- `customers-filter` filters by name (`?name=`, accents ignored), type (`?type=`) and status (`?status=active|archived|all`). +- `customers-filter` filters by name (`?name=`, accents ignored) and status (`?status=active|archived|all`). - `customers-create` validates with the shared Zod schema, looks up the postal code, saves, and opens the detail page. -- `customers-detail` shows the name, RFC, type, acquisition, seller (admins only), address and phone. +- `customers-detail` shows the name, RFC, acquisition, seller (admins only), address and phone. - `customers-edit` changes a customer and returns to its detail page. - `customers-archive` archives from the card menu after a confirmation dialog, and unarchives the same way. @@ -30,7 +30,7 @@ Preconditions: - **General data.** Run `$V ab find label "Razón social" fill "$N"`, `$V ab find label "RFC" fill "VSU010101AB1"` and `$V ab find label "Teléfono" fill "8112345678"`. Then pick the acquisition channel by keyboard: `$V ab find label "Medio de adquisición" click`, `$V ab keyboard type "Página web"` and `$V ab press Enter`. - **Postal code lookup.** Run `$V ab find label "Código postal" fill "64000"` and `$V ab wait --fn 'document.querySelector("#city")?.value !== ""'`. `Municipio` is `Monterrey`, `Estado` is `Nuevo León`, both read-only, and a `Colonia *` combobox appears. Run `$V ab find label "Colonia" click`, `$V ab keyboard type "Monterrey Centro"` and `$V ab press Enter`. - **Street.** Run `$V ab find label "Calle" fill "Av. Constitución"` and `$V ab find label "Número exterior" fill "100"`. Run `$V shot customers create-filled`. -- **Save.** Run `$V ab find role button click --name "Crear"` and `$V ab wait --text "VSU010101AB1"`. `$V ab get url` is `/customers/`, and the page shows `$N`, `Cliente`, `Página web` and `Av. Constitución, No. Ext. 100, Colonia Monterrey Centro`. Run `$V shot customers create-detail`. +- **Save.** Run `$V ab find role button click --name "Crear"` and `$V ab wait --text "VSU010101AB1"`. `$V ab get url` is `/customers/`, and the page shows `$N`, `Página web` and `Av. Constitución, No. Ext. 100, Colonia Monterrey Centro`. Run `$V shot customers create-detail`. - **Stored row.** `$V sql "select count(*), max(postal_code), max(suburb) from customer where name = '$N'"` returns `1 | 64000 | Monterrey Centro`. - **Filter.** Run `$V ab find role link click --name "Clientes"` and `$V ab find label "Buscar por nombre" fill "$N"`. The URL gains `?name=` and exactly one card has the heading `$N`. Run `$V shot customers list-after`. - **Archive.** Run `$V ab find role button click --name "Abrir menú"`, `$V ab find role menuitem click --name "Archivar"` and `$V ab wait --text "Esto archivará"`. Run `$V shot customers archive-dialog`, then `$V ab find role button click --name "Archivar"`. With the name filter still applied, `No se encontraron clientes` appears. `$V sql "select archived is not null from customer where name = '$N'"` returns `t`. @@ -41,11 +41,11 @@ Preconditions: ## Gotchas -- `Medio de adquisición`, `Tipo` and `Colonia` are react-select comboboxes. Pick options by typing and pressing `Enter`. `find role option click` can report success without selecting anything, and then `Crear` silently stays on `/customers/new` with `Selecciona un medio de adquisición`. Always assert that the URL left `/customers/new`. +- `Medio de adquisición` and `Colonia` are react-select comboboxes. Pick options by typing and pressing `Enter`. `find role option click` can report success without selecting anything, and then `Crear` silently stays on `/customers/new` with `Selecciona un medio de adquisición`. Always assert that the URL left `/customers/new`. - The postal code lookup calls the real SEPOMEX service. On a miss or an error, the status says `No encontramos ese código postal` or `No se pudo consultar el código postal`, and `Municipio` and `Estado` unlock for manual entry. -- `Tipo` only renders for admins. A user-role customer always gets `Cliente`, and the seller line on cards only appears for admins. +- The seller line on cards only appears for admins. - The RFC must match `^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$` and is not unique, so reusing `VSU010101AB1` is fine. - Card menus are hidden until hover on pointer devices. `find role button --name "Abrir menú"` still reaches them. With several cards, filter by name first so only one menu matches. -- The name search is bound to `?name=`. A second `fill` appends to the current value instead of replacing it. Click `Limpiar` first, which also resets the type and status filters. +- The name search is bound to `?name=`. A second `fill` appends to the current value instead of replacing it. Click `Limpiar búsqueda` first. - On the detail page `Editar` is a `link`. In a card's menu it is a `menuitem`. - Archived customers stay in the shared database. Report the names you left. diff --git a/apps/web/src/components/customers/customer-filters.tsx b/apps/web/src/components/customers/customer-filters.tsx index 7f51b8c..7b852eb 100644 --- a/apps/web/src/components/customers/customer-filters.tsx +++ b/apps/web/src/components/customers/customer-filters.tsx @@ -1,51 +1,23 @@ -import type { AppRouterOutputs } from "@suni/api/routers/index"; -import { CUSTOMER_TYPES } from "@suni/db/schema/customer-enums"; import { getRouteApi } from "@tanstack/react-router"; import { FilterBar } from "@/components/customers/shared/filter-bar"; -import { SegmentedControl } from "@/components/customers/shared/segmented-control"; const routeApi = getRouteApi("/_auth/customers/"); -type TypeFilter = "all" | (typeof CUSTOMER_TYPES)[number]; - -const TYPE_OPTIONS: { value: TypeFilter; label: string }[] = [ - { value: "all", label: "Todos" }, - ...CUSTOMER_TYPES.map((value) => ({ value, label: value })), -]; - -interface CustomerFiltersProps { - /** Customers in the current tab and search, before the type filter, for the counts. */ - customers: AppRouterOutputs["customers"]["list"][number][]; -} - -export default function CustomerFilters({ customers }: CustomerFiltersProps) { - const { name, type } = routeApi.useSearch(); +export default function CustomerFilters() { + const { name } = routeApi.useSearch(); const navigate = routeApi.useNavigate(); - const setFilters = (filters: { name?: string; type?: TypeFilter }) => - navigate({ search: (prev) => ({ ...prev, ...filters }), replace: true }); - - const countOf = (value: TypeFilter) => - value === "all" - ? customers.length - : customers.filter((customer) => customer.type === value).length; - return ( setFilters({ name: value })} + onSearchChange={(next) => + navigate({ + search: (prev) => ({ ...prev, name: next }), + replace: true, + }) + } search={name} searchLabel="Buscar por nombre" - > - setFilters({ type: value })} - options={TYPE_OPTIONS.map((option) => ({ - ...option, - count: countOf(option.value), - }))} - value={type} - /> - + /> ); } diff --git a/apps/web/src/components/customers/customer-form.tsx b/apps/web/src/components/customers/customer-form.tsx index 8c60df6..7b52d39 100644 --- a/apps/web/src/components/customers/customer-form.tsx +++ b/apps/web/src/components/customers/customer-form.tsx @@ -1,8 +1,5 @@ import type { AppRouterOutputs } from "@suni/api/routers/index"; -import { - ACQUISITION_CHANNELS, - CUSTOMER_TYPES, -} from "@suni/db/schema/customer-enums"; +import { ACQUISITION_CHANNELS } from "@suni/db/schema/customer-enums"; import { customerSchema } from "@suni/db/validation/customers"; import { Button } from "@suni/ui/components/button"; import { revalidateLogic, useSelector } from "@tanstack/react-form"; @@ -12,7 +9,6 @@ import type { z } from "zod"; import { useAppForm } from "@/components/form/use-app-form"; import { useCreateCustomer, useUpdateCustomer } from "@/hooks/use-customers"; -import { useIsAdmin } from "@/hooks/use-is-admin"; import { POSTAL_CODE_LENGTH, useAddressLookup } from "@/hooks/use-postal-code"; type FormValues = Omit, "acquisition"> & { @@ -35,7 +31,6 @@ const EMPTY_VALUES: FormValues = { phone: "", phoneExtension: "", acquisition: "", - type: "Cliente", postalCode: "", suburb: "", city: "", @@ -56,7 +51,6 @@ function toFormValues(customer?: CustomerFormProps["customer"]): FormValues { phone: customer.phone, phoneExtension: customer.phoneExtension, acquisition: customer.acquisition, - type: customer.type, postalCode: customer.postalCode, suburb: customer.suburb, city: customer.city, @@ -72,11 +66,8 @@ const ACQUISITION_OPTIONS = ACQUISITION_CHANNELS.map((value) => ({ label: value, })); -const TYPE_OPTIONS = CUSTOMER_TYPES.map((value) => ({ value, label: value })); - export function CustomerForm({ customer }: CustomerFormProps) { const navigate = useNavigate(); - const isAdmin = useIsAdmin(); const createCustomer = useCreateCustomer(); const updateCustomer = useUpdateCustomer(); @@ -166,17 +157,6 @@ export function CustomerForm({ customer }: CustomerFormProps) { /> )} - {isAdmin ? ( - - {(field) => ( - - )} - - ) : null} diff --git a/apps/web/src/routes/_auth/customers/$customerId/index.tsx b/apps/web/src/routes/_auth/customers/$customerId/index.tsx index 58f1fdb..90261d0 100644 --- a/apps/web/src/routes/_auth/customers/$customerId/index.tsx +++ b/apps/web/src/routes/_auth/customers/$customerId/index.tsx @@ -104,14 +104,7 @@ function RouteComponent() { } - description={ -
- {customer.rfc} - - {customer.type} - -
- } + description={{customer.rfc}} icon={ContactRound} title={customer.name} /> diff --git a/apps/web/src/routes/_auth/customers/index.tsx b/apps/web/src/routes/_auth/customers/index.tsx index a074adb..0b26d55 100644 --- a/apps/web/src/routes/_auth/customers/index.tsx +++ b/apps/web/src/routes/_auth/customers/index.tsx @@ -1,7 +1,4 @@ -import { - CUSTOMER_STATUSES, - CUSTOMER_TYPES, -} from "@suni/db/schema/customer-enums"; +import { CUSTOMER_STATUSES } from "@suni/db/schema/customer-enums"; import { Button } from "@suni/ui/components/button"; import { Link, @@ -25,10 +22,6 @@ import { useListCustomers } from "@/hooks/use-customers"; /* oxlint-disable promise/prefer-await-to-then, github/no-then -- zod `.catch()` is not Promise.catch */ const searchSchema = z.object({ name: z.string().default("").catch(""), - type: z - .enum(["all", ...CUSTOMER_TYPES]) - .default("all") - .catch("all"), status: z.enum(CUSTOMER_STATUSES).default("active").catch("active"), }); /* oxlint-enable promise/prefer-await-to-then, github/no-then */ @@ -42,7 +35,7 @@ export const Route = createFileRoute("/_auth/customers/")({ }); function RouteComponent() { - const { name, type, status } = Route.useSearch(); + const { name, status } = Route.useSearch(); const navigate = Route.useNavigate(); // Fetch every status once so each tab shows its count and switching is instant. @@ -54,12 +47,7 @@ function RouteComponent() { const rowsByStatus = byStatus(matchingName(customers ?? [], name)); - const inTab = rowsByStatus[status]; - - const visibleCustomers = - type === "all" ? inTab : inTab.filter((customer) => customer.type === type); - - const hasFilters = name.trim() !== "" || type !== "all"; + const hasFilters = name.trim() !== ""; return (
@@ -89,9 +77,9 @@ function RouteComponent() { } value={status} > - + { const { userId } = context; - const type = context.admin ? input.type : "Cliente"; - const [created] = await context.db .insert(customer) - .values({ ...input, type, sellerId: userId, modifiedBy: userId }) + .values({ ...input, sellerId: userId, modifiedBy: userId }) .returning({ id: customer.id }); return created; diff --git a/packages/api/src/routers/customers/update.ts b/packages/api/src/routers/customers/update.ts index dff7b8b..3dfb2a9 100644 --- a/packages/api/src/routers/customers/update.ts +++ b/packages/api/src/routers/customers/update.ts @@ -10,15 +10,13 @@ export const update = scopedProcedure .route({ method: "PATCH", path: "/{id}" }) .input(customerSchema.extend({ id: z.string() })) .handler(async ({ input, context, errors }) => { - const { id, type, ...fields } = input; + const { id, ...fields } = input; const { userId } = context; - const data = context.admin ? { ...fields, type } : fields; - const [updated] = await context.db .update(customer) - .set({ ...data, modifiedBy: userId }) + .set({ ...fields, modifiedBy: userId }) // Archived customers are read-only until restored. .where( and( diff --git a/packages/db/src/migrations/20261120172705_salty_korath/migration.sql b/packages/db/src/migrations/20261120172705_salty_korath/migration.sql new file mode 100644 index 0000000..0b852dc --- /dev/null +++ b/packages/db/src/migrations/20261120172705_salty_korath/migration.sql @@ -0,0 +1,2 @@ +ALTER TABLE "customer" DROP COLUMN "type";--> statement-breakpoint +DROP TYPE "customer_type"; \ No newline at end of file diff --git a/packages/db/src/migrations/20261120172705_salty_korath/snapshot.json b/packages/db/src/migrations/20261120172705_salty_korath/snapshot.json new file mode 100644 index 0000000..f05c407 --- /dev/null +++ b/packages/db/src/migrations/20261120172705_salty_korath/snapshot.json @@ -0,0 +1,1510 @@ +{ + "version": "8", + "dialect": "postgres", + "id": "fe2a732b-fb16-4519-abc5-629e424b62ed", + "prevIds": [ + "fd2a056e-c876-4ed0-98c6-3cdeb4d77ab1" + ], + "ddl": [ + { + "values": [ + "Redes sociales", + "Recomendación", + "Prospección", + "Teléfono", + "Correo", + "Página web", + "Díptico" + ], + "name": "acquisition", + "entityType": "enums", + "schema": "public" + }, + { + "isRlsEnabled": false, + "name": "account", + "entityType": "tables", + "schema": "public" + }, + { + "isRlsEnabled": false, + "name": "session", + "entityType": "tables", + "schema": "public" + }, + { + "isRlsEnabled": false, + "name": "user", + "entityType": "tables", + "schema": "public" + }, + { + "isRlsEnabled": false, + "name": "verification", + "entityType": "tables", + "schema": "public" + }, + { + "isRlsEnabled": false, + "name": "customer_branches", + "entityType": "tables", + "schema": "public" + }, + { + "isRlsEnabled": false, + "name": "contact", + "entityType": "tables", + "schema": "public" + }, + { + "isRlsEnabled": false, + "name": "customer", + "entityType": "tables", + "schema": "public" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "id", + "entityType": "columns", + "schema": "public", + "table": "account" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "account_id", + "entityType": "columns", + "schema": "public", + "table": "account" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "provider_id", + "entityType": "columns", + "schema": "public", + "table": "account" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "user_id", + "entityType": "columns", + "schema": "public", + "table": "account" + }, + { + "type": "text", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "access_token", + "entityType": "columns", + "schema": "public", + "table": "account" + }, + { + "type": "text", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "refresh_token", + "entityType": "columns", + "schema": "public", + "table": "account" + }, + { + "type": "text", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "id_token", + "entityType": "columns", + "schema": "public", + "table": "account" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "access_token_expires_at", + "entityType": "columns", + "schema": "public", + "table": "account" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "refresh_token_expires_at", + "entityType": "columns", + "schema": "public", + "table": "account" + }, + { + "type": "text", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "scope", + "entityType": "columns", + "schema": "public", + "table": "account" + }, + { + "type": "text", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "password", + "entityType": "columns", + "schema": "public", + "table": "account" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "now()", + "generated": null, + "identity": null, + "name": "created_at", + "entityType": "columns", + "schema": "public", + "table": "account" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "updated_at", + "entityType": "columns", + "schema": "public", + "table": "account" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "id", + "entityType": "columns", + "schema": "public", + "table": "session" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "expires_at", + "entityType": "columns", + "schema": "public", + "table": "session" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "token", + "entityType": "columns", + "schema": "public", + "table": "session" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "now()", + "generated": null, + "identity": null, + "name": "created_at", + "entityType": "columns", + "schema": "public", + "table": "session" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "updated_at", + "entityType": "columns", + "schema": "public", + "table": "session" + }, + { + "type": "text", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "ip_address", + "entityType": "columns", + "schema": "public", + "table": "session" + }, + { + "type": "text", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "user_agent", + "entityType": "columns", + "schema": "public", + "table": "session" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "user_id", + "entityType": "columns", + "schema": "public", + "table": "session" + }, + { + "type": "text", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "impersonated_by", + "entityType": "columns", + "schema": "public", + "table": "session" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "id", + "entityType": "columns", + "schema": "public", + "table": "user" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "name", + "entityType": "columns", + "schema": "public", + "table": "user" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "email", + "entityType": "columns", + "schema": "public", + "table": "user" + }, + { + "type": "boolean", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "false", + "generated": null, + "identity": null, + "name": "email_verified", + "entityType": "columns", + "schema": "public", + "table": "user" + }, + { + "type": "text", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "image", + "entityType": "columns", + "schema": "public", + "table": "user" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "now()", + "generated": null, + "identity": null, + "name": "created_at", + "entityType": "columns", + "schema": "public", + "table": "user" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "now()", + "generated": null, + "identity": null, + "name": "updated_at", + "entityType": "columns", + "schema": "public", + "table": "user" + }, + { + "type": "text", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "role", + "entityType": "columns", + "schema": "public", + "table": "user" + }, + { + "type": "boolean", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": "false", + "generated": null, + "identity": null, + "name": "banned", + "entityType": "columns", + "schema": "public", + "table": "user" + }, + { + "type": "text", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "ban_reason", + "entityType": "columns", + "schema": "public", + "table": "user" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "ban_expires", + "entityType": "columns", + "schema": "public", + "table": "user" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "id", + "entityType": "columns", + "schema": "public", + "table": "verification" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "identifier", + "entityType": "columns", + "schema": "public", + "table": "verification" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "value", + "entityType": "columns", + "schema": "public", + "table": "verification" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "expires_at", + "entityType": "columns", + "schema": "public", + "table": "verification" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "now()", + "generated": null, + "identity": null, + "name": "created_at", + "entityType": "columns", + "schema": "public", + "table": "verification" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "now()", + "generated": null, + "identity": null, + "name": "updated_at", + "entityType": "columns", + "schema": "public", + "table": "verification" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "id", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "name", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "street", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "''", + "generated": null, + "identity": null, + "name": "int_number", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "ext_number", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "city", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "suburb", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "state", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "postal_code", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "''", + "generated": null, + "identity": null, + "name": "phone", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "''", + "generated": null, + "identity": null, + "name": "front_image_url", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "customer_id", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "seller_id", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "modified_by", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "archived", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "now()", + "generated": null, + "identity": null, + "name": "created_at", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "now()", + "generated": null, + "identity": null, + "name": "updated_at", + "entityType": "columns", + "schema": "public", + "table": "customer_branches" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "id", + "entityType": "columns", + "schema": "public", + "table": "contact" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "name", + "entityType": "columns", + "schema": "public", + "table": "contact" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "email", + "entityType": "columns", + "schema": "public", + "table": "contact" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "phone", + "entityType": "columns", + "schema": "public", + "table": "contact" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "''", + "generated": null, + "identity": null, + "name": "phone_extension", + "entityType": "columns", + "schema": "public", + "table": "contact" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "''", + "generated": null, + "identity": null, + "name": "position", + "entityType": "columns", + "schema": "public", + "table": "contact" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "customer_id", + "entityType": "columns", + "schema": "public", + "table": "contact" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "branch_id", + "entityType": "columns", + "schema": "public", + "table": "contact" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "archived", + "entityType": "columns", + "schema": "public", + "table": "contact" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "modified_by", + "entityType": "columns", + "schema": "public", + "table": "contact" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "now()", + "generated": null, + "identity": null, + "name": "created_at", + "entityType": "columns", + "schema": "public", + "table": "contact" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "now()", + "generated": null, + "identity": null, + "name": "updated_at", + "entityType": "columns", + "schema": "public", + "table": "contact" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "id", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "name", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "rfc", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "street", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "''", + "generated": null, + "identity": null, + "name": "int_number", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "ext_number", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "city", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "suburb", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "state", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "postal_code", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "phone", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "''", + "generated": null, + "identity": null, + "name": "phone_extension", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "acquisition", + "typeSchema": "public", + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "acquisition", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "seller_id", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "text", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "modified_by", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "now()", + "generated": null, + "identity": null, + "name": "created_at", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": true, + "dimensions": 0, + "default": "now()", + "generated": null, + "identity": null, + "name": "updated_at", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "type": "timestamp", + "typeSchema": null, + "notNull": false, + "dimensions": 0, + "default": null, + "generated": null, + "identity": null, + "name": "archived", + "entityType": "columns", + "schema": "public", + "table": "customer" + }, + { + "nameExplicit": true, + "columns": [ + { + "value": "user_id", + "isExpression": false, + "asc": true, + "nullsFirst": false, + "opclass": null + } + ], + "isUnique": false, + "where": null, + "with": "", + "method": "btree", + "concurrently": false, + "name": "account_userId_idx", + "entityType": "indexes", + "schema": "public", + "table": "account" + }, + { + "nameExplicit": true, + "columns": [ + { + "value": "user_id", + "isExpression": false, + "asc": true, + "nullsFirst": false, + "opclass": null + } + ], + "isUnique": false, + "where": null, + "with": "", + "method": "btree", + "concurrently": false, + "name": "session_userId_idx", + "entityType": "indexes", + "schema": "public", + "table": "session" + }, + { + "nameExplicit": true, + "columns": [ + { + "value": "identifier", + "isExpression": false, + "asc": true, + "nullsFirst": false, + "opclass": null + } + ], + "isUnique": false, + "where": null, + "with": "", + "method": "btree", + "concurrently": false, + "name": "verification_identifier_idx", + "entityType": "indexes", + "schema": "public", + "table": "verification" + }, + { + "nameExplicit": false, + "columns": [ + "user_id" + ], + "schemaTo": "public", + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "NO ACTION", + "onDelete": "CASCADE", + "name": "account_user_id_user_id_fkey", + "entityType": "fks", + "schema": "public", + "table": "account" + }, + { + "nameExplicit": false, + "columns": [ + "user_id" + ], + "schemaTo": "public", + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "NO ACTION", + "onDelete": "CASCADE", + "name": "session_user_id_user_id_fkey", + "entityType": "fks", + "schema": "public", + "table": "session" + }, + { + "nameExplicit": false, + "columns": [ + "customer_id" + ], + "schemaTo": "public", + "tableTo": "customer", + "columnsTo": [ + "id" + ], + "onUpdate": "NO ACTION", + "onDelete": "NO ACTION", + "name": "customer_branches_customer_id_customer_id_fkey", + "entityType": "fks", + "schema": "public", + "table": "customer_branches" + }, + { + "nameExplicit": false, + "columns": [ + "seller_id" + ], + "schemaTo": "public", + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "NO ACTION", + "onDelete": "NO ACTION", + "name": "customer_branches_seller_id_user_id_fkey", + "entityType": "fks", + "schema": "public", + "table": "customer_branches" + }, + { + "nameExplicit": false, + "columns": [ + "modified_by" + ], + "schemaTo": "public", + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "NO ACTION", + "onDelete": "NO ACTION", + "name": "customer_branches_modified_by_user_id_fkey", + "entityType": "fks", + "schema": "public", + "table": "customer_branches" + }, + { + "nameExplicit": false, + "columns": [ + "customer_id" + ], + "schemaTo": "public", + "tableTo": "customer", + "columnsTo": [ + "id" + ], + "onUpdate": "NO ACTION", + "onDelete": "NO ACTION", + "name": "contact_customer_id_customer_id_fkey", + "entityType": "fks", + "schema": "public", + "table": "contact" + }, + { + "nameExplicit": false, + "columns": [ + "branch_id" + ], + "schemaTo": "public", + "tableTo": "customer_branches", + "columnsTo": [ + "id" + ], + "onUpdate": "NO ACTION", + "onDelete": "NO ACTION", + "name": "contact_branch_id_customer_branches_id_fkey", + "entityType": "fks", + "schema": "public", + "table": "contact" + }, + { + "nameExplicit": false, + "columns": [ + "modified_by" + ], + "schemaTo": "public", + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "NO ACTION", + "onDelete": "NO ACTION", + "name": "contact_modified_by_user_id_fkey", + "entityType": "fks", + "schema": "public", + "table": "contact" + }, + { + "nameExplicit": false, + "columns": [ + "seller_id" + ], + "schemaTo": "public", + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "NO ACTION", + "onDelete": "NO ACTION", + "name": "customer_seller_id_user_id_fkey", + "entityType": "fks", + "schema": "public", + "table": "customer" + }, + { + "nameExplicit": false, + "columns": [ + "modified_by" + ], + "schemaTo": "public", + "tableTo": "user", + "columnsTo": [ + "id" + ], + "onUpdate": "NO ACTION", + "onDelete": "NO ACTION", + "name": "customer_modified_by_user_id_fkey", + "entityType": "fks", + "schema": "public", + "table": "customer" + }, + { + "columns": [ + "id" + ], + "nameExplicit": false, + "name": "account_pkey", + "schema": "public", + "table": "account", + "entityType": "pks" + }, + { + "columns": [ + "id" + ], + "nameExplicit": false, + "name": "session_pkey", + "schema": "public", + "table": "session", + "entityType": "pks" + }, + { + "columns": [ + "id" + ], + "nameExplicit": false, + "name": "user_pkey", + "schema": "public", + "table": "user", + "entityType": "pks" + }, + { + "columns": [ + "id" + ], + "nameExplicit": false, + "name": "verification_pkey", + "schema": "public", + "table": "verification", + "entityType": "pks" + }, + { + "columns": [ + "id" + ], + "nameExplicit": false, + "name": "customer_branches_pkey", + "schema": "public", + "table": "customer_branches", + "entityType": "pks" + }, + { + "columns": [ + "id" + ], + "nameExplicit": false, + "name": "contact_pkey", + "schema": "public", + "table": "contact", + "entityType": "pks" + }, + { + "columns": [ + "id" + ], + "nameExplicit": false, + "name": "customer_pkey", + "schema": "public", + "table": "customer", + "entityType": "pks" + }, + { + "nameExplicit": false, + "columns": [ + "token" + ], + "nullsNotDistinct": false, + "name": "session_token_key", + "schema": "public", + "table": "session", + "entityType": "uniques" + }, + { + "nameExplicit": false, + "columns": [ + "email" + ], + "nullsNotDistinct": false, + "name": "user_email_key", + "schema": "public", + "table": "user", + "entityType": "uniques" + } + ], + "renames": [] +} \ No newline at end of file diff --git a/packages/db/src/schema/customer-enums.ts b/packages/db/src/schema/customer-enums.ts index 8b60717..007b39e 100644 --- a/packages/db/src/schema/customer-enums.ts +++ b/packages/db/src/schema/customer-enums.ts @@ -9,7 +9,5 @@ export const ACQUISITION_CHANNELS = [ "Díptico", ] as const; -export const CUSTOMER_TYPES = ["Cliente", "Asesor"] as const; - // Derived from customer.archived, not a database column. export const CUSTOMER_STATUSES = ["active", "archived", "all"] as const; diff --git a/packages/db/src/schema/customers.ts b/packages/db/src/schema/customers.ts index e7506a7..526840c 100644 --- a/packages/db/src/schema/customers.ts +++ b/packages/db/src/schema/customers.ts @@ -2,12 +2,10 @@ import { createId } from "@paralleldrive/cuid2"; import { pgEnum, pgTable, text, timestamp } from "drizzle-orm/pg-core"; import { user } from "./auth"; -import { ACQUISITION_CHANNELS, CUSTOMER_TYPES } from "./customer-enums"; +import { ACQUISITION_CHANNELS } from "./customer-enums"; export const acquisitionEnum = pgEnum("acquisition", ACQUISITION_CHANNELS); -export const customerTypeEnum = pgEnum("customer_type", CUSTOMER_TYPES); - export const customer = pgTable("customer", { id: text("id") .primaryKey() @@ -24,7 +22,6 @@ export const customer = pgTable("customer", { phone: text("phone").notNull(), phoneExtension: text("phone_extension").notNull().default(""), acquisition: acquisitionEnum("acquisition").notNull(), - type: customerTypeEnum("type").notNull().default("Cliente"), sellerId: text("seller_id") .notNull() .references(() => user.id), diff --git a/packages/db/src/validation/customers.ts b/packages/db/src/validation/customers.ts index 9a98f2f..5ffec40 100644 --- a/packages/db/src/validation/customers.ts +++ b/packages/db/src/validation/customers.ts @@ -1,6 +1,6 @@ import { z } from "zod"; -import { ACQUISITION_CHANNELS, CUSTOMER_TYPES } from "../schema/customer-enums"; +import { ACQUISITION_CHANNELS } from "../schema/customer-enums"; // Shared by the web form and the API, so it must stay free of drizzle imports. export const customerSchema = z.object({ @@ -42,5 +42,4 @@ export const customerSchema = z.object({ acquisition: z.enum(ACQUISITION_CHANNELS, { message: "Selecciona un medio de adquisición", }), - type: z.enum(CUSTOMER_TYPES), });