Browse Source

Add userId to SymbolProfile database schema

pull/4122/head
Thomas Kaul 8 months ago
parent
commit
af8457e36d
  1. 10
      apps/api/src/app/import/import.service.ts
  2. 3
      apps/api/src/app/order/order.service.ts
  3. 3
      prisma/schema.prisma

10
apps/api/src/app/import/import.service.ts

@ -224,7 +224,7 @@ export class ImportService {
for (const activity of activitiesDto) { for (const activity of activitiesDto) {
if (!activity.dataSource) { if (!activity.dataSource) {
if (activity.type === 'ITEM' || activity.type === 'LIABILITY') { if (['FEE', 'INTEREST', 'ITEM', 'LIABILITY'].includes(activity.type)) {
activity.dataSource = DataSource.MANUAL; activity.dataSource = DataSource.MANUAL;
} else { } else {
activity.dataSource = activity.dataSource =
@ -356,6 +356,7 @@ export class ImportService {
quantity, quantity,
type, type,
unitPrice, unitPrice,
Account: validatedAccount,
accountId: validatedAccount?.id, accountId: validatedAccount?.id,
accountUserId: undefined, accountUserId: undefined,
createdAt: new Date(), createdAt: new Date(),
@ -380,10 +381,10 @@ export class ImportService {
symbolMapping, symbolMapping,
updatedAt, updatedAt,
url, url,
comment: assetProfile.comment,
currency: assetProfile.currency, currency: assetProfile.currency,
comment: assetProfile.comment userId: dataSource === 'MANUAL' ? user.id : undefined
}, },
Account: validatedAccount,
symbolProfileId: undefined, symbolProfileId: undefined,
updatedAt: new Date(), updatedAt: new Date(),
userId: user.id userId: user.id
@ -406,7 +407,8 @@ export class ImportService {
create: { create: {
dataSource, dataSource,
symbol, symbol,
currency: assetProfile.currency currency: assetProfile.currency,
userId: dataSource === 'MANUAL' ? user.id : undefined
}, },
where: { where: {
dataSource_symbol: { dataSource_symbol: {

3
apps/api/src/app/order/order.service.ts

@ -93,7 +93,7 @@ export class OrderService {
userId: string; userId: string;
} }
): Promise<Order> { ): Promise<Order> {
let Account; let Account: Prisma.AccountCreateNestedOneWithoutOrderInput;
if (data.accountId) { if (data.accountId) {
Account = { Account = {
@ -124,6 +124,7 @@ export class OrderService {
data.SymbolProfile.connectOrCreate.create.dataSource = dataSource; data.SymbolProfile.connectOrCreate.create.dataSource = dataSource;
data.SymbolProfile.connectOrCreate.create.name = name; data.SymbolProfile.connectOrCreate.create.name = name;
data.SymbolProfile.connectOrCreate.create.symbol = id; data.SymbolProfile.connectOrCreate.create.symbol = id;
data.SymbolProfile.connectOrCreate.create.userId = userId;
data.SymbolProfile.connectOrCreate.where.dataSource_symbol = { data.SymbolProfile.connectOrCreate.where.dataSource_symbol = {
dataSource, dataSource,
symbol: id symbol: id

3
prisma/schema.prisma

@ -188,8 +188,10 @@ model SymbolProfile {
symbol String symbol String
symbolMapping Json? symbolMapping Json?
url String? url String?
userId String?
Order Order[] Order Order[]
SymbolProfileOverrides SymbolProfileOverrides? SymbolProfileOverrides SymbolProfileOverrides?
User User? @relation(fields: [userId], onDelete: Cascade, references: [id])
@@unique([dataSource, symbol]) @@unique([dataSource, symbol])
@@index([assetClass]) @@index([assetClass])
@ -254,6 +256,7 @@ model User {
Order Order[] Order Order[]
Settings Settings? Settings Settings?
Subscription Subscription[] Subscription Subscription[]
SymbolProfile SymbolProfile[]
Tag Tag[] Tag Tag[]
@@index([accessToken]) @@index([accessToken])

Loading…
Cancel
Save