From 933ea87456e80b1c78380cc2d553b0825d22886b Mon Sep 17 00:00:00 2001 From: Shubham Palriwala Date: Mon, 15 Apr 2024 15:35:29 +0530 Subject: [PATCH 1/4] docs: fix S3_BUCKET_NAME env var in docs (#2448) --- .../app/docs/self-hosting/external-auth-providers/page.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/formbricks-com/app/docs/self-hosting/external-auth-providers/page.mdx b/apps/formbricks-com/app/docs/self-hosting/external-auth-providers/page.mdx index 605f42247c..28f6b1f29c 100644 --- a/apps/formbricks-com/app/docs/self-hosting/external-auth-providers/page.mdx +++ b/apps/formbricks-com/app/docs/self-hosting/external-auth-providers/page.mdx @@ -147,7 +147,7 @@ These variables can be provided at the runtime i.e. in your docker-compose file. | S3_ACCESS_KEY | Access key for S3. | optional | (resolved by the AWS SDK) | | S3_SECRET_KEY | Secret key for S3. | optional | (resolved by the AWS SDK) | | S3_REGION | Region for S3. | optional | (resolved by the AWS SDK) | -| S3_BUCKET | Bucket name for S3. | optional (required if S3 is enabled) | | +| S3_BUCKET_NAME | Bucket name for S3. | optional (required if S3 is enabled) | | | S3_ENDPOINT | Endpoint for S3. | optional | (resolved by the AWS SDK) | | PRIVACY_URL | URL for privacy policy. | optional | | | TERMS_URL | URL for terms of service. | optional | | From c2ea2716d32f0cbf5e04430687f3ee80b0bcfaf1 Mon Sep 17 00:00:00 2001 From: Piyush Gupta <56182734+gupta-piyush19@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:04:59 +0530 Subject: [PATCH 2/4] feat: Add load more button to MultipleChoiceSummary component (#2449) --- .../components/MultipleChoiceSummary.tsx | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/MultipleChoiceSummary.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/MultipleChoiceSummary.tsx index 7b4eac4066..37ec4fba6c 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/MultipleChoiceSummary.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/MultipleChoiceSummary.tsx @@ -1,8 +1,10 @@ import Link from "next/link"; +import { useState } from "react"; import { getPersonIdentifier } from "@formbricks/lib/person/util"; import { TSurveyQuestionSummaryMultipleChoice } from "@formbricks/types/surveys"; import { PersonAvatar } from "@formbricks/ui/Avatars"; +import { Button } from "@formbricks/ui/Button"; import { ProgressBar } from "@formbricks/ui/ProgressBar"; import { convertFloatToNDecimal } from "../lib/util"; @@ -19,15 +21,28 @@ export const MultipleChoiceSummary = ({ environmentId, surveyType, }: MultipleChoiceSummaryProps) => { + const [visibleOtherResponses, setVisibleOtherResponses] = useState(10); + // sort by count and transform to array const results = Object.values(questionSummary.choices).sort((a, b) => { if (a.others) return 1; // Always put a after b if a has 'others' if (b.others) return -1; // Always put b after a if b has 'others' - // Sort by count - return b.count - a.count; + return b.count - a.count; // Sort by count }); + const handleLoadMore = () => { + const lastChoice = results[results.length - 1]; + const hasOthers = lastChoice.others && lastChoice.others.length > 0; + + if (!hasOthers) return; // If there are no 'others' to show, don't increase the visible options + + // Increase the number of visible responses by 10, not exceeding the total number of responses + setVisibleOtherResponses((prevVisibleOptions) => + Math.min(prevVisibleOptions + 10, lastChoice.others?.length || 0) + ); + }; + return (
@@ -58,6 +73,7 @@ export const MultipleChoiceSummary = ({
{result.others .filter((otherValue) => otherValue.value !== "") + .slice(0, visibleOtherResponses) .map((otherValue, idx) => (
{surveyType === "link" && ( @@ -87,6 +103,13 @@ export const MultipleChoiceSummary = ({ )}
))} + {visibleOtherResponses < result.others.length && ( +
+ +
+ )} )} From 529144fe36c3aecb9030c1e953961ccaa61886da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20H=C3=B6benreich?= <64426524+jonas-hoebenreich@users.noreply.github.com> Date: Mon, 15 Apr 2024 14:47:51 +0200 Subject: [PATCH 3/4] chore: Improve Debug messages (#2451) --- .../[surveyId]/(analysis)/summary/components/CTASummary.tsx | 4 ++-- apps/web/playwright/js.spec.ts | 2 +- packages/js-core/src/lib/widget.ts | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/CTASummary.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/CTASummary.tsx index 09800e42a6..76dd63b118 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/CTASummary.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/CTASummary.tsx @@ -15,7 +15,7 @@ export const CTASummary = ({ questionSummary }: CTASummaryProps) => {
-

Clickthrough Rate (CTR)

+

Click-through rate (CTR)

{convertFloatToNDecimal(questionSummary.ctr.percentage, 1)}% @@ -23,7 +23,7 @@ export const CTASummary = ({ questionSummary }: CTASummaryProps) => {

- {questionSummary.ctr.count} {questionSummary.ctr.count === 1 ? "response" : "responses"} + {questionSummary.ctr.count} {questionSummary.ctr.count === 1 ? "click" : "clicks"}

diff --git a/apps/web/playwright/js.spec.ts b/apps/web/playwright/js.spec.ts index e1f0abd423..6c40460941 100644 --- a/apps/web/playwright/js.spec.ts +++ b/apps/web/playwright/js.spec.ts @@ -124,7 +124,7 @@ test.describe("JS Package Test", async () => { await page.waitForTimeout(1000); await expect(page.getByRole("button", { name: "Responses50%" })).toBeVisible(); await expect(page.getByText("1 Responses", { exact: true }).first()).toBeVisible(); - await expect(page.getByText("Clickthrough Rate (CTR)100%")).toBeVisible(); + await expect(page.getByText("Click-through rate (CTR)100%")).toBeVisible(); await expect(page.getByText("Somewhat disappointed100%")).toBeVisible(); await expect(page.getByText("Founder100%")).toBeVisible(); await expect(page.getByText("People who believe that PMF").first()).toBeVisible(); diff --git a/packages/js-core/src/lib/widget.ts b/packages/js-core/src/lib/widget.ts index 2576012d34..cd5286a301 100644 --- a/packages/js-core/src/lib/widget.ts +++ b/packages/js-core/src/lib/widget.ts @@ -35,7 +35,7 @@ export const triggerSurvey = async (survey: TSurvey, action?: string): Promise { setIsSurveyRunning(true); if (survey.delay) { - logger.debug(`Delaying survey by ${survey.delay} seconds.`); + logger.debug(`Delaying survey "${survey.name}" by ${survey.delay} seconds.`); } const product = config.get().state.product; @@ -63,7 +63,7 @@ const renderWidget = async (survey: TSurvey, action?: string) => { const displayLanguage = getLanguageCode(survey, attributes); //if survey is not available in selected language, survey wont be shown if (!displayLanguage) { - logger.debug("Survey not available in specified language."); + logger.debug(`Survey "${survey.name}" is not available in specified language.`); setIsSurveyRunning(true); return; } From 5add263e6f24f3c86f54c3cbe62c92c0b03db0db Mon Sep 17 00:00:00 2001 From: Anshuman Pandey <54475686+pandeymangg@users.noreply.github.com> Date: Mon, 15 Apr 2024 18:22:12 +0530 Subject: [PATCH 4/4] fix: data migration and cleanup for userId attribute (#2400) Co-authored-by: Dhruwang Jariwala <67850763+Dhruwang@users.noreply.github.com> Co-authored-by: Matti Nannt --- .../components/AttributesSection.tsx | 10 +- .../(peopleAndSegments)/people/page.tsx | 5 +- .../data-migration.ts | 0 .../data-migration-fix.ts | 0 .../data-migration-range-fix.ts | 0 .../data-migration.ts | 0 .../lib/i18n.ts | 0 .../data-migration.ts | 0 .../data-migration.ts | 69 +++++ .../data-migration.js | 293 ------------------ packages/database/package.json | 11 +- packages/lib/person/service.ts | 47 +-- packages/lib/strings.ts | 11 - 13 files changed, 80 insertions(+), 366 deletions(-) rename packages/database/{migrations => data-migrations}/20240207041922_advanced_targeting/data-migration.ts (100%) rename packages/database/{migrations => data-migrations}/20240318050527_add_languages_and_survey_languages/data-migration-fix.ts (100%) rename packages/database/{migrations => data-migrations}/20240318050527_add_languages_and_survey_languages/data-migration-range-fix.ts (100%) rename packages/database/{migrations => data-migrations}/20240318050527_add_languages_and_survey_languages/data-migration.ts (100%) rename packages/database/{migrations => data-migrations}/20240318050527_add_languages_and_survey_languages/lib/i18n.ts (100%) rename packages/database/{migrations => data-migrations}/20240320090315_add_form_styling/data-migration.ts (100%) create mode 100644 packages/database/data-migrations/20240408123456_userid_migration/data-migration.ts delete mode 100644 packages/database/migrations/20240207041922_advanced_targeting/data-migration.js diff --git a/apps/web/app/(app)/environments/[environmentId]/(peopleAndSegments)/people/[personId]/components/AttributesSection.tsx b/apps/web/app/(app)/environments/[environmentId]/(peopleAndSegments)/people/[personId]/components/AttributesSection.tsx index 581f3d9fa1..636b988494 100644 --- a/apps/web/app/(app)/environments/[environmentId]/(peopleAndSegments)/people/[personId]/components/AttributesSection.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/(peopleAndSegments)/people/[personId]/components/AttributesSection.tsx @@ -38,9 +38,7 @@ export default async function AttributesSection({ personId }: { personId: string
User Id
- {person.attributes.userId ? ( - {person.attributes.userId} - ) : person.userId ? ( + {person.userId ? ( {person.userId} ) : ( Not provided @@ -53,7 +51,7 @@ export default async function AttributesSection({ personId }: { personId: string
{Object.entries(person.attributes) - .filter(([key, _]) => key !== "email" && key !== "userId" && key !== "language") + .filter(([key, _]) => key !== "email" && key !== "language") .map(([key, value]) => (
{capitalizeFirstLetter(key.toString())}
@@ -62,10 +60,6 @@ export default async function AttributesSection({ personId }: { personId: string ))}
-
- {/*
Sessions
*/} - {/*
{numberOfSessions}
*/} -
Responses
{numberOfResponses}
diff --git a/apps/web/app/(app)/environments/[environmentId]/(peopleAndSegments)/people/page.tsx b/apps/web/app/(app)/environments/[environmentId]/(peopleAndSegments)/people/page.tsx index 896ae989bf..7ce5168403 100644 --- a/apps/web/app/(app)/environments/[environmentId]/(peopleAndSegments)/people/page.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/(peopleAndSegments)/people/page.tsx @@ -4,7 +4,6 @@ import Link from "next/link"; import { ITEMS_PER_PAGE } from "@formbricks/lib/constants"; import { getEnvironment } from "@formbricks/lib/environment/service"; import { getPeople, getPeopleCount } from "@formbricks/lib/person/service"; -import { truncateMiddle } from "@formbricks/lib/strings"; import { TPerson } from "@formbricks/types/people"; import { PersonAvatar } from "@formbricks/ui/Avatars"; import EmptySpaceFiller from "@formbricks/ui/EmptySpaceFiller"; @@ -83,9 +82,7 @@ export default async function PeoplePage({
-
- {truncateMiddle(getAttributeValue(person, "userId"), 24) || person.userId} -
+
{person.userId}
{getAttributeValue(person, "email")}
diff --git a/packages/database/migrations/20240207041922_advanced_targeting/data-migration.ts b/packages/database/data-migrations/20240207041922_advanced_targeting/data-migration.ts similarity index 100% rename from packages/database/migrations/20240207041922_advanced_targeting/data-migration.ts rename to packages/database/data-migrations/20240207041922_advanced_targeting/data-migration.ts diff --git a/packages/database/migrations/20240318050527_add_languages_and_survey_languages/data-migration-fix.ts b/packages/database/data-migrations/20240318050527_add_languages_and_survey_languages/data-migration-fix.ts similarity index 100% rename from packages/database/migrations/20240318050527_add_languages_and_survey_languages/data-migration-fix.ts rename to packages/database/data-migrations/20240318050527_add_languages_and_survey_languages/data-migration-fix.ts diff --git a/packages/database/migrations/20240318050527_add_languages_and_survey_languages/data-migration-range-fix.ts b/packages/database/data-migrations/20240318050527_add_languages_and_survey_languages/data-migration-range-fix.ts similarity index 100% rename from packages/database/migrations/20240318050527_add_languages_and_survey_languages/data-migration-range-fix.ts rename to packages/database/data-migrations/20240318050527_add_languages_and_survey_languages/data-migration-range-fix.ts diff --git a/packages/database/migrations/20240318050527_add_languages_and_survey_languages/data-migration.ts b/packages/database/data-migrations/20240318050527_add_languages_and_survey_languages/data-migration.ts similarity index 100% rename from packages/database/migrations/20240318050527_add_languages_and_survey_languages/data-migration.ts rename to packages/database/data-migrations/20240318050527_add_languages_and_survey_languages/data-migration.ts diff --git a/packages/database/migrations/20240318050527_add_languages_and_survey_languages/lib/i18n.ts b/packages/database/data-migrations/20240318050527_add_languages_and_survey_languages/lib/i18n.ts similarity index 100% rename from packages/database/migrations/20240318050527_add_languages_and_survey_languages/lib/i18n.ts rename to packages/database/data-migrations/20240318050527_add_languages_and_survey_languages/lib/i18n.ts diff --git a/packages/database/migrations/20240320090315_add_form_styling/data-migration.ts b/packages/database/data-migrations/20240320090315_add_form_styling/data-migration.ts similarity index 100% rename from packages/database/migrations/20240320090315_add_form_styling/data-migration.ts rename to packages/database/data-migrations/20240320090315_add_form_styling/data-migration.ts diff --git a/packages/database/data-migrations/20240408123456_userid_migration/data-migration.ts b/packages/database/data-migrations/20240408123456_userid_migration/data-migration.ts new file mode 100644 index 0000000000..af414ca3cf --- /dev/null +++ b/packages/database/data-migrations/20240408123456_userid_migration/data-migration.ts @@ -0,0 +1,69 @@ +import { PrismaClient } from "@prisma/client"; + +const prisma = new PrismaClient(); + +async function main() { + await prisma.$transaction( + async (tx) => { + // get all the persons that have an attribute class with the name "userId" + const personsWithUserIdAttribute = await tx.person.findMany({ + where: { + attributes: { + some: { + attributeClass: { + name: "userId", + }, + }, + }, + }, + include: { + attributes: { + include: { attributeClass: true }, + }, + }, + }); + + for (let person of personsWithUserIdAttribute) { + // If the person already has a userId, skip it + if (person.userId) { + continue; + } + + const userIdAttributeValue = person.attributes.find((attribute) => { + if (attribute.attributeClass.name === "userId") { + return attribute; + } + }); + + if (!userIdAttributeValue) { + continue; + } + + await tx.person.update({ + where: { + id: person.id, + }, + data: { + userId: userIdAttributeValue.value, + }, + }); + } + + // Delete all attributeClasses with the name "userId" + await tx.attributeClass.deleteMany({ + where: { + name: "userId", + }, + }); + }, + { + timeout: 60000 * 3, // 3 minutes + } + ); +} +main() + .catch(async (e) => { + console.error(e); + process.exit(1); + }) + .finally(async () => await prisma.$disconnect()); diff --git a/packages/database/migrations/20240207041922_advanced_targeting/data-migration.js b/packages/database/migrations/20240207041922_advanced_targeting/data-migration.js deleted file mode 100644 index e89dae4724..0000000000 --- a/packages/database/migrations/20240207041922_advanced_targeting/data-migration.js +++ /dev/null @@ -1,293 +0,0 @@ -"use strict"; -var __awaiter = - (this && this.__awaiter) || - function (thisArg, _arguments, P, generator) { - function adopt(value) { - return value instanceof P - ? value - : new P(function (resolve) { - resolve(value); - }); - } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { - try { - step(generator.next(value)); - } catch (e) { - reject(e); - } - } - function rejected(value) { - try { - step(generator["throw"](value)); - } catch (e) { - reject(e); - } - } - function step(result) { - result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); - } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); - }; -var __generator = - (this && this.__generator) || - function (thisArg, body) { - var _ = { - label: 0, - sent: function () { - if (t[0] & 1) throw t[1]; - return t[1]; - }, - trys: [], - ops: [], - }, - f, - y, - t, - g; - return ( - (g = { next: verb(0), throw: verb(1), return: verb(2) }), - typeof Symbol === "function" && - (g[Symbol.iterator] = function () { - return this; - }), - g - ); - function verb(n) { - return function (v) { - return step([n, v]); - }; - } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while ((g && ((g = 0), op[0] && (_ = 0)), _)) - try { - if ( - ((f = 1), - y && - (t = - op[0] & 2 - ? y["return"] - : op[0] - ? y["throw"] || ((t = y["return"]) && t.call(y), 0) - : y.next) && - !(t = t.call(y, op[1])).done) - ) - return t; - if (((y = 0), t)) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: - case 1: - t = op; - break; - case 4: - _.label++; - return { value: op[1], done: false }; - case 5: - _.label++; - y = op[1]; - op = [0]; - continue; - case 7: - op = _.ops.pop(); - _.trys.pop(); - continue; - default: - if (!((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && (op[0] === 6 || op[0] === 2)) { - _ = 0; - continue; - } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { - _.label = op[1]; - break; - } - if (op[0] === 6 && _.label < t[1]) { - _.label = t[1]; - t = op; - break; - } - if (t && _.label < t[2]) { - _.label = t[2]; - _.ops.push(op); - break; - } - if (t[2]) _.ops.pop(); - _.trys.pop(); - continue; - } - op = body.call(thisArg, _); - } catch (e) { - op = [6, e]; - y = 0; - } finally { - f = t = 0; - } - if (op[0] & 5) throw op[1]; - return { value: op[0] ? op[1] : void 0, done: true }; - } - }; -Object.defineProperty(exports, "__esModule", { value: true }); -var cuid2_1 = require("@paralleldrive/cuid2"); -var client_1 = require("@prisma/client"); -var prisma = new client_1.PrismaClient(); -function main() { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - return [ - 4 /*yield*/, - prisma.$transaction(function (tx) { - return __awaiter(_this, void 0, void 0, function () { - var allSurveysWithAttributeFilters; - var _this = this; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - return [ - 4 /*yield*/, - prisma.survey.findMany({ - where: { - attributeFilters: { - some: {}, - }, - }, - include: { - attributeFilters: { include: { attributeClass: true } }, - }, - }), - ]; - case 1: - allSurveysWithAttributeFilters = _a.sent(); - if ( - !(allSurveysWithAttributeFilters === null || allSurveysWithAttributeFilters === void 0 - ? void 0 - : allSurveysWithAttributeFilters.length) - ) { - // stop the migration if there are no surveys with attribute filters - return [2 /*return*/]; - } - allSurveysWithAttributeFilters.forEach(function (survey) { - return __awaiter(_this, void 0, void 0, function () { - var attributeFilters, filters; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - attributeFilters = survey.attributeFilters; - // if there are no attribute filters, we can skip this survey - if ( - !(attributeFilters === null || attributeFilters === void 0 - ? void 0 - : attributeFilters.length) - ) { - return [2 /*return*/]; - } - filters = attributeFilters.map(function (filter, idx) { - var attributeClass = filter.attributeClass; - var resource; - // if the attribute class is userId, we need to create a user segment with the person filter - if ( - attributeClass.name === "userId" && - attributeClass.type === "automatic" - ) { - resource = { - id: (0, cuid2_1.createId)(), - root: { - type: "person", - personIdentifier: "userId", - }, - qualifier: { - operator: filter.condition, - }, - value: filter.value, - }; - } else { - resource = { - id: (0, cuid2_1.createId)(), - root: { - type: "attribute", - attributeClassName: attributeClass.name, - }, - qualifier: { - operator: filter.condition, - }, - value: filter.value, - }; - } - var attributeSegment = { - id: filter.id, - connector: idx === 0 ? null : "and", - resource: resource, - }; - return attributeSegment; - }); - return [ - 4 /*yield*/, - tx.segment.create({ - data: { - title: "".concat(survey.id), - description: "", - isPrivate: true, - filters: filters, - surveys: { - connect: { - id: survey.id, - }, - }, - environment: { - connect: { - id: survey.environmentId, - }, - }, - }, - }), - ]; - case 1: - _a.sent(); - return [2 /*return*/]; - } - }); - }); - }); - // delete all attribute filters - return [4 /*yield*/, tx.surveyAttributeFilter.deleteMany({})]; - case 2: - // delete all attribute filters - _a.sent(); - return [2 /*return*/]; - } - }); - }); - }), - ]; - case 1: - _a.sent(); - return [2 /*return*/]; - } - }); - }); -} -main() - .catch(function (e) { - return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - console.error(e); - process.exit(1); - return [2 /*return*/]; - }); - }); - }) - .finally(function () { - return __awaiter(void 0, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - return [4 /*yield*/, prisma.$disconnect()]; - case 1: - return [2 /*return*/, _a.sent()]; - } - }); - }); - }); diff --git a/packages/database/package.json b/packages/database/package.json index 84ab852b86..2b2245d73d 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -23,12 +23,13 @@ "lint": "eslint ./src --fix", "post-install": "pnpm generate", "predev": "pnpm generate", - "data-migration:v1.6": "ts-node ./migrations/20240207041922_advanced_targeting/data-migration.ts", - "data-migration:styling": "ts-node ./migrations/20240320090315_add_form_styling/data-migration.ts", + "data-migration:v1.6": "ts-node ./data-migrations/20240207041922_advanced_targeting/data-migration.ts", + "data-migration:styling": "ts-node ./data-migrations/20240320090315_add_form_styling/data-migration.ts", "data-migration:v1.7": "pnpm data-migration:mls && pnpm data-migration:styling", - "data-migration:mls": "ts-node ./migrations/20240318050527_add_languages_and_survey_languages/data-migration.ts", - "data-migration:mls-fix": "ts-node ./migrations/20240318050527_add_languages_and_survey_languages/data-migration-fix.ts", - "data-migration:mls-range-fix": "ts-node ./migrations/20240318050527_add_languages_and_survey_languages/data-migration-range-fix.ts" + "data-migration:mls": "ts-node ./data-migrations/20240318050527_add_languages_and_survey_languages/data-migration.ts", + "data-migration:mls-fix": "ts-node ./data-migrations/20240318050527_add_languages_and_survey_languages/data-migration-fix.ts", + "data-migration:mls-range-fix": "ts-node ./data-migrations/20240318050527_add_languages_and_survey_languages/data-migration-range-fix.ts", + "data-migration:userId": "ts-node ./data-migrations/20240408123456_userid_migration/data-migration.ts" }, "dependencies": { "@prisma/client": "^5.12.1", diff --git a/packages/lib/person/service.ts b/packages/lib/person/service.ts index db31b9e13a..2e04a6691a 100644 --- a/packages/lib/person/service.ts +++ b/packages/lib/person/service.ts @@ -325,50 +325,7 @@ export const getPersonByUserId = async (environmentId: string, userId: string): return transformPrismaPerson(personWithUserId); } - // Check if a person with the userId attribute exists - let personWithUserIdAttribute = await prisma.person.findFirst({ - where: { - environmentId, - attributes: { - some: { - attributeClass: { - name: "userId", - }, - value: userId, - }, - }, - }, - select: selectPerson, - }); - - const userIdAttributeClassId = personWithUserIdAttribute?.attributes.find( - (attr) => attr.attributeClass.name === "userId" && attr.value === userId - )?.attributeClass.id; - - if (!personWithUserIdAttribute) { - return null; - } - - personWithUserIdAttribute = await prisma.person.update({ - where: { - id: personWithUserIdAttribute.id, - }, - data: { - userId, - attributes: { - deleteMany: { attributeClassId: userIdAttributeClassId }, - }, - }, - select: selectPerson, - }); - - personCache.revalidate({ - id: personWithUserIdAttribute.id, - environmentId, - userId, - }); - - return transformPrismaPerson(personWithUserIdAttribute); + return null; }, [`getPersonByUserId-${environmentId}-${userId}`], { @@ -380,7 +337,7 @@ export const getPersonByUserId = async (environmentId: string, userId: string): }; /** - * @deprecated This function is deprecated and only used in legacy endpoints. Use updatePerson instead. + * @deprecated This function is deprecated and only used in legacy endpoints. Use `updatePerson` instead. */ export const updatePersonAttribute = async ( personId: string, diff --git a/packages/lib/strings.ts b/packages/lib/strings.ts index b9f35a70b5..7197598291 100644 --- a/packages/lib/strings.ts +++ b/packages/lib/strings.ts @@ -14,17 +14,6 @@ export const truncate = (str: string, length: number) => { return str; }; -// write a function that takes a string and truncates the middle of it so that the beginning and ending are always visible -export const truncateMiddle = (str: string, length: number) => { - if (!str) return ""; - if (str.length > length) { - const start = str.substring(0, length / 2); - const end = str.substring(str.length - length / 2, str.length); - return start + " ... " + end; - } - return str; -}; - // write a function that takes a string and removes all characters that could cause issues with the url and truncates it to the specified length export const sanitizeString = (str: string, delimiter: string = "_", length: number = 255) => { return str.replace(/[^0-9a-zA-Z\-._]+/g, delimiter).substring(0, length);