From 6d367fd2cf796048c22aad3905e0fbc99a58e3f0 Mon Sep 17 00:00:00 2001 From: EJS00102 <52255287+EJS00102@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:35:02 +0200 Subject: [PATCH 1/4] Fixed error where track api route was not unsubscribing contacts --- CONTRIBUTING.md | 9 +++++++-- packages/api/.env.example | 2 +- packages/api/src/controllers/v1/index.ts | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 776500fe..a01b2bea 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,11 +8,16 @@ Support can be asked in the `#contributions` channel of the [Plunk Discord serve - Docker needs to be [installed](https://docs.docker.com/engine/install/) on your system. -### 2. Set your environment variables +### 2. Install dependencies + +- Run `yarn install` to install the dependencies. + +### 3. Set your environment variables - Copy the `.env.example` files in the `api`, `dashboard` and `prisma` folder to `.env` in their respective folders. +- Set AWS credentials in the `api` `.env` file. -### 3. Start resources +### 4. Start resources - Run `yarn services:up` to start a local database and a local redis server. - Run `yarn migrate` to apply the migrations to the database. diff --git a/packages/api/.env.example b/packages/api/.env.example index 1215bdb8..6d31462a 100644 --- a/packages/api/.env.example +++ b/packages/api/.env.example @@ -1,7 +1,7 @@ # ENV JWT_SECRET=mysupersecretJWTsecret REDIS_URL=redis://127.0.0.1:56379 -DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres +DATABASE_URL=postgresql://postgres:postgres@localhost:55432/postgres DISABLE_SIGNUPS=false # AWS diff --git a/packages/api/src/controllers/v1/index.ts b/packages/api/src/controllers/v1/index.ts index 7137b21d..70acd8e1 100644 --- a/packages/api/src/controllers/v1/index.ts +++ b/packages/api/src/controllers/v1/index.ts @@ -70,7 +70,7 @@ export class V1 { contact = await prisma.contact.create({ data: { email, - subscribed: subscribed ?? true, + subscribed: subscribed ?? false, projectId: project.id, }, }); @@ -78,7 +78,7 @@ export class V1 { redis.del(Keys.Contact.id(contact.id)); redis.del(Keys.Contact.email(project.id, contact.email)); } else { - if (subscribed && contact.subscribed !== subscribed) { + if (subscribed !== undefined && contact.subscribed !== subscribed) { contact = await prisma.contact.update({ where: { id: contact.id }, data: { subscribed }, From 17558909c1d948021a67d858ceed932cc4c9a487 Mon Sep 17 00:00:00 2001 From: EJS00102 <52255287+EJS00102@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:49:58 +0200 Subject: [PATCH 2/4] Removed breaking change + bumped version --- package.json | 2 +- packages/api/src/controllers/v1/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7ca2f972..61075155 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plunk", - "version": "1.0.7", + "version": "1.0.8", "private": true, "license": "agpl-3.0", "workspaces": { diff --git a/packages/api/src/controllers/v1/index.ts b/packages/api/src/controllers/v1/index.ts index 70acd8e1..6e9c247a 100644 --- a/packages/api/src/controllers/v1/index.ts +++ b/packages/api/src/controllers/v1/index.ts @@ -70,7 +70,7 @@ export class V1 { contact = await prisma.contact.create({ data: { email, - subscribed: subscribed ?? false, + subscribed: subscribed ?? true, projectId: project.id, }, }); From a0e119ec5bf1e9c7259ac610de06977152575f37 Mon Sep 17 00:00:00 2001 From: EJS00102 <52255287+EJS00102@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:59:54 +0200 Subject: [PATCH 3/4] Fixed case where subscried is null, defaulting to true --- packages/api/src/controllers/v1/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api/src/controllers/v1/index.ts b/packages/api/src/controllers/v1/index.ts index 6e9c247a..90978db2 100644 --- a/packages/api/src/controllers/v1/index.ts +++ b/packages/api/src/controllers/v1/index.ts @@ -81,7 +81,7 @@ export class V1 { if (subscribed !== undefined && contact.subscribed !== subscribed) { contact = await prisma.contact.update({ where: { id: contact.id }, - data: { subscribed }, + data: { subscribed: subscribed ?? true }, }); redis.del(Keys.Contact.id(contact.id)); From 52f4a3cfad1b56cfe46515ffba217b36b909209c Mon Sep 17 00:00:00 2001 From: EJS00102 <52255287+EJS00102@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:08:34 +0200 Subject: [PATCH 4/4] Made change as suggested --- packages/api/src/controllers/v1/index.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/api/src/controllers/v1/index.ts b/packages/api/src/controllers/v1/index.ts index 90978db2..9be09ffa 100644 --- a/packages/api/src/controllers/v1/index.ts +++ b/packages/api/src/controllers/v1/index.ts @@ -78,15 +78,12 @@ export class V1 { redis.del(Keys.Contact.id(contact.id)); redis.del(Keys.Contact.email(project.id, contact.email)); } else { - if (subscribed !== undefined && contact.subscribed !== subscribed) { - contact = await prisma.contact.update({ - where: { id: contact.id }, - data: { subscribed: subscribed ?? true }, - }); - + if (subscribed !== null && contact.subscribed !== subscribed) { + contact = await prisma.contact.update({where: {id: contact.id}, data: {subscribed}}); + redis.del(Keys.Contact.id(contact.id)); redis.del(Keys.Contact.email(project.id, contact.email)); - } + } } if (data) {