feat: CSV exports, PDF improvements, play internal/external with hour split, roles cleanup, admin companies with 'Cliente avulso', ticket list spacing/alignment fixes, status translations and mappings
This commit is contained in:
parent
addd4ce6e8
commit
3bafcc5a0a
45 changed files with 1401 additions and 256 deletions
|
|
@ -6,7 +6,7 @@ import type { MutationCtx, QueryCtx } from "./_generated/server"
|
|||
|
||||
const SECRET = process.env.CONVEX_SYNC_SECRET ?? "dev-sync-secret"
|
||||
|
||||
const VALID_ROLES = new Set(["ADMIN", "MANAGER", "AGENT", "COLLABORATOR", "CUSTOMER"])
|
||||
const VALID_ROLES = new Set(["ADMIN", "MANAGER", "AGENT", "COLLABORATOR"])
|
||||
const INTERNAL_STAFF_ROLES = new Set(["ADMIN", "AGENT", "COLLABORATOR"])
|
||||
|
||||
function normalizeEmail(value: string) {
|
||||
|
|
@ -30,6 +30,7 @@ type ImportedQueue = {
|
|||
type ImportedCompany = {
|
||||
slug: string
|
||||
name: string
|
||||
isAvulso?: boolean | null
|
||||
cnpj?: string | null
|
||||
domain?: string | null
|
||||
phone?: string | null
|
||||
|
|
@ -43,6 +44,8 @@ function normalizeRole(role: string | null | undefined) {
|
|||
if (!role) return "AGENT"
|
||||
const normalized = role.toUpperCase()
|
||||
if (VALID_ROLES.has(normalized)) return normalized
|
||||
// map legacy CUSTOMER to MANAGER
|
||||
if (normalized === "CUSTOMER") return "MANAGER"
|
||||
return "AGENT"
|
||||
}
|
||||
|
||||
|
|
@ -182,6 +185,7 @@ async function ensureCompany(
|
|||
tenantId,
|
||||
name: data.name,
|
||||
slug,
|
||||
isAvulso: data.isAvulso ?? undefined,
|
||||
cnpj: data.cnpj ?? undefined,
|
||||
domain: data.domain ?? undefined,
|
||||
phone: data.phone ?? undefined,
|
||||
|
|
@ -195,6 +199,7 @@ async function ensureCompany(
|
|||
if (existing) {
|
||||
const needsPatch =
|
||||
existing.name !== payload.name ||
|
||||
(existing as any).isAvulso !== (payload.isAvulso ?? (existing as any).isAvulso) ||
|
||||
existing.cnpj !== (payload.cnpj ?? undefined) ||
|
||||
existing.domain !== (payload.domain ?? undefined) ||
|
||||
existing.phone !== (payload.phone ?? undefined) ||
|
||||
|
|
@ -203,6 +208,7 @@ async function ensureCompany(
|
|||
if (needsPatch) {
|
||||
await ctx.db.patch(existing._id, {
|
||||
name: payload.name,
|
||||
isAvulso: payload.isAvulso,
|
||||
cnpj: payload.cnpj,
|
||||
domain: payload.domain,
|
||||
phone: payload.phone,
|
||||
|
|
@ -344,6 +350,7 @@ export const exportTenantSnapshot = query({
|
|||
companies: companies.map((company) => ({
|
||||
slug: company.slug,
|
||||
name: company.name,
|
||||
isAvulso: (company as any).isAvulso ?? false,
|
||||
cnpj: company.cnpj ?? null,
|
||||
domain: company.domain ?? null,
|
||||
phone: company.phone ?? null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue