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:
Esdras Renan 2025-10-07 13:42:45 -03:00
parent addd4ce6e8
commit 3bafcc5a0a
45 changed files with 1401 additions and 256 deletions

View file

@ -26,7 +26,7 @@ if (!secret) {
process.exit(1)
}
const allowedRoles = new Set(["ADMIN", "MANAGER", "AGENT", "COLLABORATOR", "CUSTOMER"])
const allowedRoles = new Set(["ADMIN", "MANAGER", "AGENT", "COLLABORATOR"])
const client = new ConvexHttpClient(convexUrl)
@ -61,7 +61,7 @@ const STATUS_MAP = {
ON_HOLD: "PAUSED",
PAUSED: "PAUSED",
RESOLVED: "RESOLVED",
CLOSED: "CLOSED",
CLOSED: "RESOLVED",
}
function normalizeStatus(status) {
@ -84,6 +84,7 @@ async function upsertCompanies(snapshotCompanies) {
},
update: {
name: company.name,
isAvulso: Boolean(company.isAvulso ?? false),
cnpj: company.cnpj ?? null,
domain: company.domain ?? null,
phone: company.phone ?? null,
@ -94,6 +95,7 @@ async function upsertCompanies(snapshotCompanies) {
tenantId,
name: company.name,
slug,
isAvulso: Boolean(company.isAvulso ?? false),
cnpj: company.cnpj ?? null,
domain: company.domain ?? null,
phone: company.phone ?? null,
@ -117,8 +119,8 @@ async function upsertUsers(snapshotUsers, companyMap) {
const normalizedEmail = normalizeEmail(user.email)
if (!normalizedEmail) continue
const normalizedRole = (user.role ?? "CUSTOMER").toUpperCase()
const role = allowedRoles.has(normalizedRole) ? normalizedRole : "CUSTOMER"
const normalizedRole = (user.role ?? "MANAGER").toUpperCase()
const role = allowedRoles.has(normalizedRole) ? normalizedRole : "MANAGER"
const companyId = user.companySlug ? companyMap.get(user.companySlug) ?? null : null
const record = await prisma.user.upsert({
@ -195,7 +197,7 @@ async function upsertUsers(snapshotUsers, companyMap) {
await prisma.user.update({
where: { id: staff.id },
data: {
role: "CUSTOMER",
role: "MANAGER",
},
})
}