feat: add company management and manager role support
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
parent
409cbea7b9
commit
854887f499
16 changed files with 955 additions and 126 deletions
|
|
@ -30,12 +30,13 @@ async function main() {
|
|||
process.exit(1)
|
||||
}
|
||||
|
||||
const [users, queues, tickets] = await Promise.all([
|
||||
const [users, queues, tickets, companies] = await Promise.all([
|
||||
prisma.user.findMany({
|
||||
include: {
|
||||
teams: {
|
||||
include: { team: true },
|
||||
},
|
||||
company: true,
|
||||
},
|
||||
}),
|
||||
prisma.queue.findMany(),
|
||||
|
|
@ -44,6 +45,7 @@ async function main() {
|
|||
requester: true,
|
||||
assignee: true,
|
||||
queue: true,
|
||||
company: true,
|
||||
comments: {
|
||||
include: {
|
||||
author: true,
|
||||
|
|
@ -53,6 +55,7 @@ async function main() {
|
|||
},
|
||||
orderBy: { createdAt: "asc" },
|
||||
}),
|
||||
prisma.company.findMany(),
|
||||
])
|
||||
|
||||
const userSnapshot = users.map((user) => ({
|
||||
|
|
@ -63,6 +66,7 @@ async function main() {
|
|||
teams: user.teams
|
||||
.map((membership) => membership.team?.name)
|
||||
.filter((name) => Boolean(name) && typeof name === "string"),
|
||||
companySlug: user.company?.slug ?? undefined,
|
||||
}))
|
||||
|
||||
const queueSnapshot = queues.map((queue) => ({
|
||||
|
|
@ -78,6 +82,7 @@ async function main() {
|
|||
const requesterEmail = ticket.requester?.email ?? userSnapshot[0]?.email ?? "unknown@example.com"
|
||||
const assigneeEmail = ticket.assignee?.email ?? undefined
|
||||
const queueSlug = ticket.queue?.slug ?? slugify(ticket.queue?.name)
|
||||
const companySlug = ticket.company?.slug ?? ticket.requester?.company?.slug ?? undefined
|
||||
|
||||
return {
|
||||
reference,
|
||||
|
|
@ -89,6 +94,7 @@ async function main() {
|
|||
queueSlug: queueSlug ?? undefined,
|
||||
requesterEmail,
|
||||
assigneeEmail,
|
||||
companySlug,
|
||||
dueAt: toMillis(ticket.dueAt) ?? undefined,
|
||||
firstResponseAt: toMillis(ticket.firstResponseAt) ?? undefined,
|
||||
resolvedAt: toMillis(ticket.resolvedAt) ?? undefined,
|
||||
|
|
@ -111,12 +117,25 @@ async function main() {
|
|||
}
|
||||
})
|
||||
|
||||
const companySnapshot = companies.map((company) => ({
|
||||
slug: company.slug ?? slugify(company.name),
|
||||
name: company.name,
|
||||
cnpj: company.cnpj ?? undefined,
|
||||
domain: company.domain ?? undefined,
|
||||
phone: company.phone ?? undefined,
|
||||
description: company.description ?? undefined,
|
||||
address: company.address ?? undefined,
|
||||
createdAt: toMillis(company.createdAt) ?? Date.now(),
|
||||
updatedAt: toMillis(company.updatedAt) ?? Date.now(),
|
||||
}))
|
||||
|
||||
const client = new ConvexHttpClient(convexUrl)
|
||||
|
||||
const result = await client.mutation("migrations:importPrismaSnapshot", {
|
||||
secret,
|
||||
snapshot: {
|
||||
tenantId,
|
||||
companies: companySnapshot,
|
||||
users: userSnapshot,
|
||||
queues: queueSnapshot,
|
||||
tickets: ticketSnapshot,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue