From 33e3dfaaa3e6578b77bdcabb63d4443a9f35a829 Mon Sep 17 00:00:00 2001 From: Stavros Rodiftsis Date: Tue, 30 Jul 2024 02:07:21 +0300 Subject: [PATCH 1/4] feat: add a deletedAt column in user code --- src/entities/user.entity.ts | 3 +++ src/user/user.interface.ts | 1 + src/utils/serialize.ts | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/entities/user.entity.ts b/src/entities/user.entity.ts index e88ad6f6..260203d4 100644 --- a/src/entities/user.entity.ts +++ b/src/entities/user.entity.ts @@ -43,6 +43,9 @@ export class UserEntity extends BaseBloomEntity { @Column({ type: 'timestamptz', nullable: true }) lastActiveAt: Date; // set each time user record is fetched + @Column({ type: 'timestamptz', nullable: true }) + deletedAt: Date; // set when the deleteUser method is called + @OneToMany(() => PartnerAccessEntity, (partnerAccess) => partnerAccess.user, { cascade: true }) partnerAccess: PartnerAccessEntity[]; diff --git a/src/user/user.interface.ts b/src/user/user.interface.ts index f9b7287b..56be5d28 100644 --- a/src/user/user.interface.ts +++ b/src/user/user.interface.ts @@ -4,6 +4,7 @@ export interface IUser { id: string; createdAt: Date | string; updatedAt: Date | string; + deletedAt: Date | string; firebaseUid?: string; name: string; email: string; diff --git a/src/utils/serialize.ts b/src/utils/serialize.ts index c30ec474..791ec8c8 100644 --- a/src/utils/serialize.ts +++ b/src/utils/serialize.ts @@ -94,6 +94,7 @@ export const formatUserObject = (userObject: UserEntity): GetUserDto => { id: userObject.id, createdAt: userObject.createdAt, updatedAt: userObject.updatedAt, + deletedAt: userObject.deletedAt, name: userObject.name, email: userObject.email, firebaseUid: userObject.firebaseUid, @@ -125,6 +126,7 @@ export const formatGetUsersObject = (userObject: UserEntity): GetUserDto => { id: userObject.id, createdAt: userObject.createdAt, updatedAt: userObject.updatedAt, + deletedAt: userObject.deletedAt, name: userObject.name, email: userObject.email, firebaseUid: userObject.firebaseUid, From 87010d53b53cea77f8606dd75a86ddd396605348 Mon Sep 17 00:00:00 2001 From: Stavros Rodiftsis Date: Tue, 30 Jul 2024 02:39:38 +0300 Subject: [PATCH 2/4] feat: add typeorm database migration --- src/migrations/1722295564731-bloom-backend.ts | 14 ++++++++++++++ src/typeorm.config.ts | 2 ++ 2 files changed, 16 insertions(+) create mode 100644 src/migrations/1722295564731-bloom-backend.ts diff --git a/src/migrations/1722295564731-bloom-backend.ts b/src/migrations/1722295564731-bloom-backend.ts new file mode 100644 index 00000000..19101dfb --- /dev/null +++ b/src/migrations/1722295564731-bloom-backend.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class BloomBackend1722295564731 implements MigrationInterface { + name = 'BloomBackend1722295564731' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "user" ADD "deletedAt" TIMESTAMP WITH TIME ZONE`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "deletedAt"`); + } + +} diff --git a/src/typeorm.config.ts b/src/typeorm.config.ts index c1482034..2a1dab8f 100644 --- a/src/typeorm.config.ts +++ b/src/typeorm.config.ts @@ -48,6 +48,7 @@ import { bloomBackend1706174260018 } from './migrations/1706174260018-bloom-back import { BloomBackend1718300621138 } from './migrations/1718300621138-bloom-backend'; import { BloomBackend1718728423454 } from './migrations/1718728423454-bloom-backend'; import { BloomBackend1719668310816 } from './migrations/1719668310816-bloom-backend'; +import { BloomBackend1722295564731 } from './migrations/1722295564731-bloom-backend'; config(); const configService = new ConfigService(); @@ -118,6 +119,7 @@ export const dataSourceOptions = { BloomBackend1718300621138, BloomBackend1718728423454, BloomBackend1719668310816, + BloomBackend1722295564731, ], subscribers: [], ssl: isProduction || isStaging, From 5e61be43dce02ed29894b95ab0219642abfb4ae7 Mon Sep 17 00:00:00 2001 From: Stavros Rodiftsis Date: Tue, 30 Jul 2024 03:04:47 +0300 Subject: [PATCH 3/4] feat: add null deletedAt field in mock user testing data --- test/utils/mockData.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/utils/mockData.ts b/test/utils/mockData.ts index a4e5177b..277c0cce 100644 --- a/test/utils/mockData.ts +++ b/test/utils/mockData.ts @@ -135,6 +135,7 @@ export const mockUserEntity: UserEntity = { lastActiveAt: new Date(), createdAt: new Date(), updatedAt: new Date(), + deletedAt: null, partnerAccess: [], partnerAdmin: null, courseUser: [], From 479b778d29f20cc9e3a7d9354ed44b2719faa85c Mon Sep 17 00:00:00 2001 From: srodif Date: Thu, 15 Aug 2024 18:23:57 +0300 Subject: [PATCH 4/4] fix: Add deletedAt field in admin-auth.guard.spec --- src/partner-admin/partner-admin-auth.guard.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/partner-admin/partner-admin-auth.guard.spec.ts b/src/partner-admin/partner-admin-auth.guard.spec.ts index e3df4955..11f42bad 100644 --- a/src/partner-admin/partner-admin-auth.guard.spec.ts +++ b/src/partner-admin/partner-admin-auth.guard.spec.ts @@ -11,6 +11,7 @@ import { PartnerAdminAuthGuard } from './partner-admin-auth.guard'; const userEntity: UserEntity = { updatedAt: null, + deletedAt: null, createdAt: new Date(), firebaseUid: '123', id: 'userid',