mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-22 11:29:22 -05:00
fixes
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { NextRequest, userAgent } from "next/server";
|
||||
import { userAgent } from "next/server";
|
||||
import { logger } from "@formbricks/logger";
|
||||
import { TContactAttributesInput } from "@formbricks/types/contact-attribute";
|
||||
import { ZEnvironmentId } from "@formbricks/types/environment";
|
||||
import { ResourceNotFoundError, ValidationError } from "@formbricks/types/errors";
|
||||
import { TJsPersonState } from "@formbricks/types/js";
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { withV1ApiWrapper } from "@/app/lib/api/with-api-logging";
|
||||
import { THandlerParams, withV1ApiWrapper } from "@/app/lib/api/with-api-logging";
|
||||
import { getIsContactsEnabled } from "@/modules/ee/license-check/lib/utils";
|
||||
import { updateUser } from "./lib/update-user";
|
||||
|
||||
@@ -33,13 +33,7 @@ export const OPTIONS = async (): Promise<Response> => {
|
||||
};
|
||||
|
||||
export const POST = withV1ApiWrapper({
|
||||
handler: async ({
|
||||
req,
|
||||
props,
|
||||
}: {
|
||||
req: NextRequest;
|
||||
props: { params: Promise<{ environmentId: string }> };
|
||||
}) => {
|
||||
handler: async ({ req, props }: THandlerParams<{ params: Promise<{ environmentId: string }> }>) => {
|
||||
const params = await props.params;
|
||||
|
||||
try {
|
||||
|
||||
+19
-27
@@ -1,14 +1,8 @@
|
||||
import { NextRequest } from "next/server";
|
||||
import { logger } from "@formbricks/logger";
|
||||
import { handleErrorResponse } from "@/app/api/v1/auth";
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { transformErrorToDetails } from "@/app/lib/api/validator";
|
||||
import {
|
||||
TApiAuditLog,
|
||||
TApiKeyAuthentication,
|
||||
TApiV1Authentication,
|
||||
withV1ApiWrapper,
|
||||
} from "@/app/lib/api/with-api-logging";
|
||||
import { TApiKeyAuthentication, THandlerParams, withV1ApiWrapper } from "@/app/lib/api/with-api-logging";
|
||||
import { hasPermission } from "@/modules/organization/settings/api-keys/lib/utils";
|
||||
import {
|
||||
deleteContactAttributeKey,
|
||||
@@ -37,10 +31,7 @@ export const GET = withV1ApiWrapper({
|
||||
handler: async ({
|
||||
props,
|
||||
authentication,
|
||||
}: {
|
||||
props: { params: Promise<{ contactAttributeKeyId: string }> };
|
||||
authentication?: TApiV1Authentication;
|
||||
}) => {
|
||||
}: THandlerParams<{ params: Promise<{ contactAttributeKeyId: string }> }>) => {
|
||||
if (!authentication || !("apiKeyId" in authentication)) {
|
||||
return { response: responses.notAuthenticatedResponse() };
|
||||
}
|
||||
@@ -83,17 +74,15 @@ export const DELETE = withV1ApiWrapper({
|
||||
props,
|
||||
auditLog,
|
||||
authentication,
|
||||
}: {
|
||||
props: { params: Promise<{ contactAttributeKeyId: string }> };
|
||||
auditLog?: TApiAuditLog;
|
||||
authentication?: TApiV1Authentication;
|
||||
}) => {
|
||||
}: THandlerParams<{ params: Promise<{ contactAttributeKeyId: string }> }>) => {
|
||||
if (!authentication || !("apiKeyId" in authentication)) {
|
||||
return { response: responses.notAuthenticatedResponse() };
|
||||
}
|
||||
|
||||
const params = await props.params;
|
||||
auditLog!.targetId = params.contactAttributeKeyId;
|
||||
if (auditLog) {
|
||||
auditLog.targetId = params.contactAttributeKeyId;
|
||||
}
|
||||
try {
|
||||
const result = await fetchAndAuthorizeContactAttributeKey(
|
||||
params.contactAttributeKeyId,
|
||||
@@ -106,7 +95,9 @@ export const DELETE = withV1ApiWrapper({
|
||||
response: result.error,
|
||||
};
|
||||
}
|
||||
auditLog!.oldObject = result.attributeKey;
|
||||
if (auditLog) {
|
||||
auditLog.oldObject = result.attributeKey;
|
||||
}
|
||||
if (result.attributeKey.type === "default") {
|
||||
return {
|
||||
response: responses.badRequestResponse("Default Contact Attribute Keys cannot be deleted"),
|
||||
@@ -132,18 +123,15 @@ export const PUT = withV1ApiWrapper({
|
||||
props,
|
||||
auditLog,
|
||||
authentication,
|
||||
}: {
|
||||
req: NextRequest;
|
||||
props: { params: Promise<{ contactAttributeKeyId: string }> };
|
||||
auditLog?: TApiAuditLog;
|
||||
authentication?: TApiV1Authentication;
|
||||
}) => {
|
||||
}: THandlerParams<{ params: Promise<{ contactAttributeKeyId: string }> }>) => {
|
||||
if (!authentication || !("apiKeyId" in authentication)) {
|
||||
return { response: responses.notAuthenticatedResponse() };
|
||||
}
|
||||
|
||||
const params = await props.params;
|
||||
auditLog!.targetId = params.contactAttributeKeyId;
|
||||
if (auditLog) {
|
||||
auditLog.targetId = params.contactAttributeKeyId;
|
||||
}
|
||||
try {
|
||||
const result = await fetchAndAuthorizeContactAttributeKey(
|
||||
params.contactAttributeKeyId,
|
||||
@@ -155,7 +143,9 @@ export const PUT = withV1ApiWrapper({
|
||||
response: result.error,
|
||||
};
|
||||
}
|
||||
auditLog!.oldObject = result.attributeKey;
|
||||
if (auditLog) {
|
||||
auditLog.oldObject = result.attributeKey;
|
||||
}
|
||||
|
||||
let contactAttributeKeyUpdate;
|
||||
try {
|
||||
@@ -181,7 +171,9 @@ export const PUT = withV1ApiWrapper({
|
||||
inputValidation.data
|
||||
);
|
||||
if (updatedAttributeClass) {
|
||||
auditLog!.newObject = updatedAttributeClass;
|
||||
if (auditLog) {
|
||||
auditLog.newObject = updatedAttributeClass;
|
||||
}
|
||||
return {
|
||||
response: responses.successResponse(updatedAttributeClass),
|
||||
};
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { NextRequest } from "next/server";
|
||||
import { logger } from "@formbricks/logger";
|
||||
import { DatabaseError } from "@formbricks/types/errors";
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { transformErrorToDetails } from "@/app/lib/api/validator";
|
||||
import { TApiAuditLog, TApiV1Authentication, withV1ApiWrapper } from "@/app/lib/api/with-api-logging";
|
||||
import { THandlerParams, withV1ApiWrapper } from "@/app/lib/api/with-api-logging";
|
||||
import { getIsContactsEnabled } from "@/modules/ee/license-check/lib/utils";
|
||||
import { hasPermission } from "@/modules/organization/settings/api-keys/lib/utils";
|
||||
import { ZContactAttributeKeyCreateInput } from "./[contactAttributeKeyId]/types/contact-attribute-keys";
|
||||
@@ -46,15 +45,7 @@ export const GET = withV1ApiWrapper({
|
||||
});
|
||||
|
||||
export const POST = withV1ApiWrapper({
|
||||
handler: async ({
|
||||
req,
|
||||
auditLog,
|
||||
authentication,
|
||||
}: {
|
||||
req: NextRequest;
|
||||
auditLog?: TApiAuditLog;
|
||||
authentication?: TApiV1Authentication;
|
||||
}) => {
|
||||
handler: async ({ req, auditLog, authentication }: THandlerParams) => {
|
||||
if (!authentication || !("apiKeyId" in authentication)) {
|
||||
return { response: responses.notAuthenticatedResponse() };
|
||||
}
|
||||
@@ -105,8 +96,12 @@ export const POST = withV1ApiWrapper({
|
||||
response: responses.internalServerErrorResponse("Failed creating attribute class"),
|
||||
};
|
||||
}
|
||||
auditLog!.targetId = contactAttributeKey.id;
|
||||
auditLog!.newObject = contactAttributeKey;
|
||||
if (auditLog) {
|
||||
auditLog.targetId = contactAttributeKey.id;
|
||||
}
|
||||
if (auditLog) {
|
||||
auditLog.newObject = contactAttributeKey;
|
||||
}
|
||||
return {
|
||||
response: responses.successResponse(contactAttributeKey),
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { DatabaseError } from "@formbricks/types/errors";
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { TApiV1Authentication, withV1ApiWrapper } from "@/app/lib/api/with-api-logging";
|
||||
import { THandlerParams, withV1ApiWrapper } from "@/app/lib/api/with-api-logging";
|
||||
import { getIsContactsEnabled } from "@/modules/ee/license-check/lib/utils";
|
||||
import { getContactAttributes } from "./lib/contact-attributes";
|
||||
|
||||
export const GET = withV1ApiWrapper({
|
||||
handler: async ({ authentication }: { authentication?: TApiV1Authentication }) => {
|
||||
handler: async ({ authentication }: THandlerParams) => {
|
||||
if (!authentication || !("apiKeyId" in authentication)) {
|
||||
return { response: responses.notAuthenticatedResponse() };
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { handleErrorResponse } from "@/app/api/v1/auth";
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import {
|
||||
TApiAuditLog,
|
||||
TApiKeyAuthentication,
|
||||
TApiV1Authentication,
|
||||
withV1ApiWrapper,
|
||||
} from "@/app/lib/api/with-api-logging";
|
||||
import { TApiKeyAuthentication, THandlerParams, withV1ApiWrapper } from "@/app/lib/api/with-api-logging";
|
||||
import { getIsContactsEnabled } from "@/modules/ee/license-check/lib/utils";
|
||||
import { hasPermission } from "@/modules/organization/settings/api-keys/lib/utils";
|
||||
import { deleteContact, getContact } from "./lib/contact";
|
||||
@@ -31,13 +26,7 @@ const fetchAndAuthorizeContact = async (
|
||||
};
|
||||
|
||||
export const GET = withV1ApiWrapper({
|
||||
handler: async ({
|
||||
props,
|
||||
authentication,
|
||||
}: {
|
||||
props: { params: Promise<{ contactId: string }> };
|
||||
authentication?: TApiV1Authentication;
|
||||
}) => {
|
||||
handler: async ({ props, authentication }: THandlerParams<{ params: Promise<{ contactId: string }> }>) => {
|
||||
if (!authentication || !("apiKeyId" in authentication)) {
|
||||
return { response: responses.notAuthenticatedResponse() };
|
||||
}
|
||||
@@ -81,17 +70,15 @@ export const DELETE = withV1ApiWrapper({
|
||||
props,
|
||||
auditLog,
|
||||
authentication,
|
||||
}: {
|
||||
props: { params: Promise<{ contactId: string }> };
|
||||
auditLog?: TApiAuditLog;
|
||||
authentication?: TApiV1Authentication;
|
||||
}) => {
|
||||
}: THandlerParams<{ params: Promise<{ contactId: string }> }>) => {
|
||||
if (!authentication || !("apiKeyId" in authentication)) {
|
||||
return { response: responses.notAuthenticatedResponse() };
|
||||
}
|
||||
|
||||
const params = await props.params;
|
||||
auditLog!.targetId = params.contactId;
|
||||
if (auditLog) {
|
||||
auditLog.targetId = params.contactId;
|
||||
}
|
||||
|
||||
try {
|
||||
const isContactsEnabled = await getIsContactsEnabled();
|
||||
@@ -113,7 +100,9 @@ export const DELETE = withV1ApiWrapper({
|
||||
response: result.error,
|
||||
};
|
||||
}
|
||||
auditLog!.oldObject = result.contact;
|
||||
if (auditLog) {
|
||||
auditLog.oldObject = result.contact;
|
||||
}
|
||||
|
||||
await deleteContact(params.contactId);
|
||||
return {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { DatabaseError } from "@formbricks/types/errors";
|
||||
import { responses } from "@/app/lib/api/response";
|
||||
import { TApiV1Authentication, withV1ApiWrapper } from "@/app/lib/api/with-api-logging";
|
||||
import { withV1ApiWrapper } from "@/app/lib/api/with-api-logging";
|
||||
import { getIsContactsEnabled } from "@/modules/ee/license-check/lib/utils";
|
||||
import { getContacts } from "./lib/contacts";
|
||||
|
||||
export const GET = withV1ApiWrapper({
|
||||
handler: async ({ authentication }: { authentication?: TApiV1Authentication }) => {
|
||||
handler: async ({ authentication }) => {
|
||||
if (!authentication || !("apiKeyId" in authentication)) {
|
||||
return { response: responses.notAuthenticatedResponse() };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user