Update Next.js and dependencies
This commit is contained in:
parent
c79ba4638c
commit
2c975edd09
10 changed files with 96 additions and 41 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import { NextResponse } from "next/server"
|
||||
import { ZodError } from "zod"
|
||||
import { Prisma } from "@prisma/client"
|
||||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library"
|
||||
|
||||
import { prisma } from "@/lib/prisma"
|
||||
import { assertStaffSession } from "@/lib/auth-server"
|
||||
|
|
@ -113,7 +112,7 @@ export async function PATCH(
|
|||
if (error instanceof ZodError) {
|
||||
return NextResponse.json({ error: "Dados inválidos", issues: formatZodError(error) }, { status: 422 })
|
||||
}
|
||||
if (error instanceof PrismaClientKnownRequestError && error.code === "P2002") {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002") {
|
||||
return NextResponse.json({ error: "Já existe uma empresa com este slug." }, { status: 409 })
|
||||
}
|
||||
console.error("Failed to update company", error)
|
||||
|
|
@ -168,7 +167,7 @@ export async function DELETE(
|
|||
|
||||
return NextResponse.json({ ok: true, ...result })
|
||||
} catch (error) {
|
||||
if (error instanceof PrismaClientKnownRequestError && error.code === "P2003") {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2003") {
|
||||
return NextResponse.json(
|
||||
{ error: "Não é possível remover esta empresa pois existem registros vinculados." },
|
||||
{ status: 409 }
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { NextResponse } from "next/server"
|
||||
import { randomBytes } from "crypto"
|
||||
import { ZodError } from "zod"
|
||||
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library"
|
||||
import { Prisma } from "@prisma/client"
|
||||
|
||||
import { prisma } from "@/lib/prisma"
|
||||
import { assertStaffSession } from "@/lib/auth-server"
|
||||
|
|
@ -67,7 +67,7 @@ export async function POST(request: Request) {
|
|||
if (error instanceof ZodError) {
|
||||
return NextResponse.json({ error: "Dados inválidos", issues: formatZodError(error) }, { status: 422 })
|
||||
}
|
||||
if (error instanceof PrismaClientKnownRequestError && error.code === "P2002") {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002") {
|
||||
return NextResponse.json(
|
||||
{ error: "Já existe uma empresa com este slug ou código de provisionamento." },
|
||||
{ status: 409 }
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ type InvitePayload = {
|
|||
reason?: string
|
||||
}
|
||||
|
||||
const JSON_NULL = Prisma.JsonNull as Prisma.NullableJsonNullValueInput
|
||||
|
||||
async function syncInvite(invite: NormalizedInvite) {
|
||||
const convexUrl = env.NEXT_PUBLIC_CONVEX_URL
|
||||
if (!convexUrl) return
|
||||
|
|
@ -97,7 +99,7 @@ export async function PATCH(request: Request, context: { params: Promise<{ id: s
|
|||
data: {
|
||||
inviteId: invite.id,
|
||||
type: "reactivated",
|
||||
payload: Prisma.JsonNull,
|
||||
payload: JSON_NULL,
|
||||
actorId: session.user.id ?? null,
|
||||
},
|
||||
})
|
||||
|
|
@ -127,7 +129,7 @@ export async function PATCH(request: Request, context: { params: Promise<{ id: s
|
|||
data: {
|
||||
inviteId: invite.id,
|
||||
type: "revoked",
|
||||
payload: reason ? { reason } : Prisma.JsonNull,
|
||||
payload: reason ? { reason } : JSON_NULL,
|
||||
actorId: session.user.id ?? null,
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -13,10 +13,11 @@ import { prisma } from "@/lib/prisma"
|
|||
import { computeInviteStatus, normalizeInvite, type InviteWithEvents, type NormalizedInvite } from "@/server/invite-utils"
|
||||
|
||||
const DEFAULT_EXPIRATION_DAYS = 7
|
||||
const JSON_NULL = Prisma.JsonNull as Prisma.NullableJsonNullValueInput
|
||||
|
||||
function toJsonPayload(payload: unknown): Prisma.InputJsonValue | Prisma.NullableJsonNullValueInput {
|
||||
if (payload === null || payload === undefined) {
|
||||
return Prisma.JsonNull
|
||||
return JSON_NULL
|
||||
}
|
||||
return payload as Prisma.InputJsonValue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ type AcceptInvitePayload = {
|
|||
password: string
|
||||
}
|
||||
|
||||
const JSON_NULL = Prisma.JsonNull as Prisma.NullableJsonNullValueInput
|
||||
|
||||
function validatePassword(password: string) {
|
||||
return password.length >= 8
|
||||
}
|
||||
|
|
@ -66,7 +68,7 @@ export async function GET(_request: Request, context: { params: Promise<{ token:
|
|||
data: {
|
||||
inviteId: invite.id,
|
||||
type: status,
|
||||
payload: Prisma.JsonNull,
|
||||
payload: JSON_NULL,
|
||||
actorId: null,
|
||||
},
|
||||
})
|
||||
|
|
@ -109,7 +111,7 @@ export async function POST(request: Request, context: { params: Promise<{ token:
|
|||
data: {
|
||||
inviteId: invite.id,
|
||||
type: "expired",
|
||||
payload: Prisma.JsonNull,
|
||||
payload: JSON_NULL,
|
||||
actorId: null,
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { randomBytes } from "crypto"
|
||||
import { Prisma } from "@prisma/client"
|
||||
import type { Prisma } from "@prisma/client"
|
||||
import { DEFAULT_TENANT_ID } from "@/lib/constants"
|
||||
import { env } from "@/lib/env"
|
||||
import { normalizeSlug, slugify } from "@/lib/slug"
|
||||
|
|
@ -59,14 +59,14 @@ export async function GET(request: Request) {
|
|||
orFilters.push({
|
||||
name: {
|
||||
contains: search,
|
||||
mode: Prisma.QueryMode.insensitive,
|
||||
mode: "insensitive",
|
||||
} as unknown as Prisma.StringFilter<"Company">,
|
||||
})
|
||||
if (slugSearch) {
|
||||
orFilters.push({
|
||||
slug: {
|
||||
contains: slugSearch,
|
||||
mode: Prisma.QueryMode.insensitive,
|
||||
mode: "insensitive",
|
||||
} as unknown as Prisma.StringFilter<"Company">,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ import path from "node:path"
|
|||
|
||||
import { PrismaClient } from "@prisma/client"
|
||||
|
||||
if (!process.env.PRISMA_CLIENT_ENGINE_TYPE) {
|
||||
process.env.PRISMA_CLIENT_ENGINE_TYPE = "binary"
|
||||
}
|
||||
|
||||
declare global {
|
||||
var prisma: PrismaClient | undefined
|
||||
}
|
||||
|
|
@ -54,9 +58,9 @@ function normalizeDatasourceUrl(envUrl?: string | null) {
|
|||
}
|
||||
|
||||
const resolvedDatabaseUrl = normalizeDatasourceUrl(process.env.DATABASE_URL)
|
||||
process.env.DATABASE_URL = resolvedDatabaseUrl
|
||||
|
||||
export const prisma =
|
||||
global.prisma ?? new PrismaClient({ datasources: { db: { url: resolvedDatabaseUrl } } })
|
||||
export const prisma = global.prisma ?? new PrismaClient({})
|
||||
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
global.prisma = prisma
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { Prisma, type Company } from "@prisma/client"
|
||||
import { prisma } from "@/lib/prisma"
|
||||
import { ZodError } from "zod"
|
||||
|
||||
import { prisma } from "@/lib/prisma"
|
||||
|
||||
import {
|
||||
companyFormSchema,
|
||||
companyInputSchema,
|
||||
|
|
@ -72,6 +73,8 @@ const STATE_REGISTRATION_TYPE_FROM_PRISMA: Record<
|
|||
SIMPLES: "simples",
|
||||
}
|
||||
|
||||
const JSON_NULL_VALUE = Prisma.JsonNull as unknown as Prisma.InputJsonValue
|
||||
|
||||
const COMPANY_LEGACY_SELECT = {
|
||||
id: true,
|
||||
tenantId: true,
|
||||
|
|
@ -343,7 +346,7 @@ export function buildCompanyData(payload: CompanyFormValues, tenantId: string):
|
|||
stateRegistrationType,
|
||||
primaryCnae: payload.primaryCnae ?? null,
|
||||
timezone: payload.businessHours?.timezone ?? null,
|
||||
businessHours: payload.businessHours ?? Prisma.JsonNull,
|
||||
businessHours: payload.businessHours ?? JSON_NULL_VALUE,
|
||||
supportEmail: payload.supportEmail ?? null,
|
||||
billingEmail: payload.billingEmail ?? null,
|
||||
contactPreferences:
|
||||
|
|
@ -353,21 +356,21 @@ export function buildCompanyData(payload: CompanyFormValues, tenantId: string):
|
|||
supportEmail: payload.supportEmail ?? null,
|
||||
billingEmail: payload.billingEmail ?? null,
|
||||
} satisfies Prisma.InputJsonValue)
|
||||
: Prisma.JsonNull,
|
||||
: JSON_NULL_VALUE,
|
||||
clientDomains: payload.clientDomains,
|
||||
communicationChannels,
|
||||
fiscalAddress: payload.fiscalAddress ?? Prisma.JsonNull,
|
||||
fiscalAddress: payload.fiscalAddress ?? JSON_NULL_VALUE,
|
||||
hasBranches: payload.hasBranches ?? false,
|
||||
regulatedEnvironments: payload.regulatedEnvironments,
|
||||
privacyPolicyAccepted: payload.privacyPolicy?.accepted ?? false,
|
||||
privacyPolicyReference: payload.privacyPolicy?.reference ?? null,
|
||||
privacyPolicyMetadata: privacyPolicyMetadata
|
||||
? (privacyPolicyMetadata as Prisma.InputJsonValue)
|
||||
: Prisma.JsonNull,
|
||||
: JSON_NULL_VALUE,
|
||||
contacts: payload.contacts,
|
||||
locations: payload.locations,
|
||||
contracts: payload.contracts,
|
||||
sla: payload.sla ?? Prisma.JsonNull,
|
||||
sla: payload.sla ?? JSON_NULL_VALUE,
|
||||
tags: payload.tags,
|
||||
customFields: payload.customFields,
|
||||
notes: payload.notes ?? null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue