Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Feature/add user id to symbol profile database schema (#4122)
Thomas Kaulde6884184388
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 42f400bccf..9aebc76a4f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).+## Unreleased++### Added++- Added `userId` to the `SymbolProfile` database schema+## 2.128.0 - 2024-12-12### Changeddiff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.tsindex e51696b56c..3b7290b432 100644--- a/apps/api/src/app/import/import.service.ts+++ b/apps/api/src/app/import/import.service.ts@@ -224,7 +224,7 @@ export class ImportService {for (const activity of activitiesDto) {if (!activity.dataSource) {- if (activity.type === 'ITEM' || activity.type === 'LIABILITY') {+ if (['FEE', 'INTEREST', 'ITEM', 'LIABILITY'].includes(activity.type)) {activity.dataSource = DataSource.MANUAL;} else {activity.dataSource =@@ -356,6 +356,7 @@ export class ImportService {quantity,type,unitPrice,+ Account: validatedAccount,accountId: validatedAccount?.id,accountUserId: undefined,createdAt: new Date(),@@ -380,10 +381,10 @@ export class ImportService {symbolMapping,updatedAt,url,+ comment: assetProfile.comment,currency: assetProfile.currency,- comment: assetProfile.comment+ userId: dataSource === 'MANUAL' ? user.id : undefined},- Account: validatedAccount,symbolProfileId: undefined,updatedAt: new Date(),userId: user.id@@ -406,7 +407,8 @@ export class ImportService {create: {dataSource,symbol,- currency: assetProfile.currency+ currency: assetProfile.currency,+ userId: dataSource === 'MANUAL' ? user.id : undefined},where: {dataSource_symbol: {diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.tsindex 5613adc5c0..129f3d8a99 100644--- a/apps/api/src/app/order/order.service.ts+++ b/apps/api/src/app/order/order.service.ts@@ -93,7 +93,7 @@ export class OrderService {userId: string;}): Promise<Order> {- let Account;+ let Account: Prisma.AccountCreateNestedOneWithoutOrderInput;if (data.accountId) {Account = {@@ -124,6 +124,7 @@ export class OrderService {data.SymbolProfile.connectOrCreate.create.dataSource = dataSource;data.SymbolProfile.connectOrCreate.create.name = name;data.SymbolProfile.connectOrCreate.create.symbol = id;+ data.SymbolProfile.connectOrCreate.create.userId = userId;data.SymbolProfile.connectOrCreate.where.dataSource_symbol = {dataSource,symbol: iddiff --git a/prisma/migrations/20241214091912_added_user_to_symbol_profile/migration.sql b/prisma/migrations/20241214091912_added_user_to_symbol_profile/migration.sqlnew file mode 100644index 0000000000..cbacd405a5--- /dev/null+++ b/prisma/migrations/20241214091912_added_user_to_symbol_profile/migration.sql@@ -0,0 +1,15 @@+-- AlterTable+ALTER TABLE "SymbolProfile" ADD COLUMN "userId" TEXT;++-- AddForeignKey+ALTER TABLE "SymbolProfile" ADD CONSTRAINT "SymbolProfile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;++-- Set userIds in SymbolProfile for 'MANUAL' data source+UPDATE "SymbolProfile"+SET "userId" = (+ SELECT "userId"+ FROM "Order"+ WHERE "Order"."symbolProfileId" = "SymbolProfile"."id"+ LIMIT 1+)+WHERE "dataSource" = 'MANUAL';diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 7df28d6944..af9acebafd 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -188,8 +188,10 @@ model SymbolProfile {symbol StringsymbolMapping Json?url String?+ userId String?Order Order[]SymbolProfileOverrides SymbolProfileOverrides?+ User User? @relation(fields: [userId], onDelete: Cascade, references: [id])@@unique([dataSource, symbol])@@index([assetClass])@@ -239,14 +241,14 @@ model Tag {model User {accessToken String?authChallenge String?- createdAt DateTime @default(now())- id String @id @default(uuid())- provider Provider @default(ANONYMOUS)- role Role @default(USER)+ createdAt DateTime @default(now())+ id String @id @default(uuid())+ provider Provider @default(ANONYMOUS)+ role Role @default(USER)thirdPartyId String?- updatedAt DateTime @updatedAt- Access Access[] @relation("accessGet")- AccessGive Access[] @relation("accessGive")+ updatedAt DateTime @updatedAt+ Access Access[] @relation("accessGet")+ AccessGive Access[] @relation("accessGive")Account Account[]Analytics Analytics?ApiKey ApiKey[]@@ -254,6 +256,7 @@ model User {Order Order[]Settings Settings?Subscription Subscription[]+ SymbolProfile SymbolProfile[]Tag Tag[]@@index([accessToken])