Prepare for multi accounts support (#42)
This commit is contained in:
parent
d268de3e12
commit
954224401d
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Extended the support for feature flags to simplify the initial project setup
|
- Extended the support for feature flags to simplify the initial project setup
|
||||||
|
- Prepared for multi accounts support
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
@ -116,7 +116,15 @@ export class UserService {
|
|||||||
|
|
||||||
public async createUser(data?: Prisma.UserCreateInput): Promise<User> {
|
public async createUser(data?: Prisma.UserCreateInput): Promise<User> {
|
||||||
let user = await this.prisma.user.create({
|
let user = await this.prisma.user.create({
|
||||||
data
|
data: {
|
||||||
|
...data,
|
||||||
|
Account: {
|
||||||
|
create: {
|
||||||
|
isDefault: true,
|
||||||
|
name: 'Default Account'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data.provider === Provider.ANONYMOUS) {
|
if (data.provider === Provider.ANONYMOUS) {
|
||||||
|
@ -2,7 +2,8 @@ import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
|||||||
import { PrismaClient } from '@prisma/client';
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PrismaService extends PrismaClient
|
export class PrismaService
|
||||||
|
extends PrismaClient
|
||||||
implements OnModuleInit, OnModuleDestroy {
|
implements OnModuleInit, OnModuleDestroy {
|
||||||
async onModuleInit() {
|
async onModuleInit() {
|
||||||
await this.$connect();
|
await this.$connect();
|
||||||
|
@ -15,6 +15,9 @@
|
|||||||
"angular": "node --max_old_space_size=32768 ./node_modules/@angular/cli/bin/ng",
|
"angular": "node --max_old_space_size=32768 ./node_modules/@angular/cli/bin/ng",
|
||||||
"build:all": "ng build --prod api && ng build --prod client && yarn replace-placeholders-in-build",
|
"build:all": "ng build --prod api && ng build --prod client && yarn replace-placeholders-in-build",
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
|
"database:format-schema": "prisma format",
|
||||||
|
"database:generate-typings": "prisma generate",
|
||||||
|
"database:gui": "prisma studio",
|
||||||
"database:push": "prisma db push --preview-feature",
|
"database:push": "prisma db push --preview-feature",
|
||||||
"database:seed": "prisma db seed --preview-feature",
|
"database:seed": "prisma db seed --preview-feature",
|
||||||
"dep-graph": "nx dep-graph",
|
"dep-graph": "nx dep-graph",
|
||||||
|
@ -24,6 +24,22 @@ model Access {
|
|||||||
@@id([id, userId])
|
@@id([id, userId])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model Account {
|
||||||
|
accountType AccountType @default(SECURITIES)
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
id String @default(uuid())
|
||||||
|
isDefault Boolean @default(false)
|
||||||
|
name String?
|
||||||
|
Order Order[]
|
||||||
|
Platform Platform? @relation(fields: [platformId], references: [id])
|
||||||
|
platformId String?
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
User User @relation(fields: [userId], references: [id])
|
||||||
|
userId String
|
||||||
|
|
||||||
|
@@id([id, userId])
|
||||||
|
}
|
||||||
|
|
||||||
model Analytics {
|
model Analytics {
|
||||||
activityCount Int @default(0)
|
activityCount Int @default(0)
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
@ -43,29 +59,33 @@ model MarketData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Order {
|
model Order {
|
||||||
createdAt DateTime @default(now())
|
Account Account? @relation(fields: [accountId, accountUserId], references: [id, userId])
|
||||||
currency Currency
|
accountId String?
|
||||||
date DateTime
|
accountUserId String?
|
||||||
fee Float
|
createdAt DateTime @default(now())
|
||||||
id String @default(uuid())
|
currency Currency
|
||||||
Platform Platform? @relation(fields: [platformId], references: [id])
|
date DateTime
|
||||||
platformId String?
|
fee Float
|
||||||
quantity Float
|
id String @default(uuid())
|
||||||
symbol String
|
Platform Platform? @relation(fields: [platformId], references: [id])
|
||||||
type Type
|
platformId String?
|
||||||
unitPrice Float
|
quantity Float
|
||||||
updatedAt DateTime @updatedAt
|
symbol String
|
||||||
User User @relation(fields: [userId], references: [id])
|
type Type
|
||||||
userId String
|
unitPrice Float
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
User User @relation(fields: [userId], references: [id])
|
||||||
|
userId String
|
||||||
|
|
||||||
@@id([id, userId])
|
@@id([id, userId])
|
||||||
}
|
}
|
||||||
|
|
||||||
model Platform {
|
model Platform {
|
||||||
id String @id @default(uuid())
|
Account Account[]
|
||||||
name String?
|
id String @id @default(uuid())
|
||||||
url String @unique
|
name String?
|
||||||
Order Order[]
|
Order Order[]
|
||||||
|
url String @unique
|
||||||
}
|
}
|
||||||
|
|
||||||
model Property {
|
model Property {
|
||||||
@ -84,6 +104,7 @@ model User {
|
|||||||
Access Access[] @relation("accessGet")
|
Access Access[] @relation("accessGet")
|
||||||
AccessGive Access[] @relation(name: "accessGive")
|
AccessGive Access[] @relation(name: "accessGive")
|
||||||
accessToken String?
|
accessToken String?
|
||||||
|
Account Account[]
|
||||||
alias String?
|
alias String?
|
||||||
Analytics Analytics?
|
Analytics Analytics?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
@ -96,6 +117,10 @@ model User {
|
|||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum AccountType {
|
||||||
|
SECURITIES
|
||||||
|
}
|
||||||
|
|
||||||
enum Currency {
|
enum Currency {
|
||||||
CHF
|
CHF
|
||||||
EUR
|
EUR
|
||||||
|
231
prisma/seed.ts
231
prisma/seed.ts
@ -1,4 +1,10 @@
|
|||||||
import { Currency, PrismaClient, Role, Type } from '@prisma/client';
|
import {
|
||||||
|
AccountType,
|
||||||
|
Currency,
|
||||||
|
PrismaClient,
|
||||||
|
Role,
|
||||||
|
Type
|
||||||
|
} from '@prisma/client';
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
@ -88,106 +94,155 @@ async function main() {
|
|||||||
create: {
|
create: {
|
||||||
accessToken:
|
accessToken:
|
||||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjliMTEyYjRkLTNiN2QtNGJhZC05YmRkLTNiMGY3YjRkYWMyZiIsImlhdCI6MTYxODUxMjAxNCwiZXhwIjoxNjIxMTA0MDE0fQ.l3WUxpI0hxuQtdPrD0kd7sem6S2kx_7CrdNvkmlKuWw',
|
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjliMTEyYjRkLTNiN2QtNGJhZC05YmRkLTNiMGY3YjRkYWMyZiIsImlhdCI6MTYxODUxMjAxNCwiZXhwIjoxNjIxMTA0MDE0fQ.l3WUxpI0hxuQtdPrD0kd7sem6S2kx_7CrdNvkmlKuWw',
|
||||||
alias: 'Demo',
|
Account: {
|
||||||
id: '9b112b4d-3b7d-4bad-9bdd-3b0f7b4dac2f',
|
|
||||||
role: Role.DEMO,
|
|
||||||
Order: {
|
|
||||||
create: [
|
create: [
|
||||||
{
|
{
|
||||||
currency: Currency.USD,
|
accountType: AccountType.SECURITIES,
|
||||||
date: new Date(Date.UTC(2017, 0, 3, 0, 0, 0)),
|
id: 'd804de69-0429-42dc-b6ca-b308fd7dd926',
|
||||||
fee: 30,
|
name: 'Coinbase Account',
|
||||||
id: 'cf7c0418-8535-4089-ae3d-5dbfa0aec2e1',
|
platformId: platformCoinbase.id
|
||||||
platformId: platformDegiro.id,
|
|
||||||
quantity: 50,
|
|
||||||
symbol: 'TSLA',
|
|
||||||
type: Type.BUY,
|
|
||||||
unitPrice: 42.97
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
currency: Currency.USD,
|
accountType: AccountType.SECURITIES,
|
||||||
date: new Date(Date.UTC(2017, 7, 16, 0, 0, 0)),
|
id: '65cfb79d-b6c7-4591-9d46-73426bc62094',
|
||||||
fee: 29.9,
|
name: 'DEGIRO Account',
|
||||||
id: 'a1c5d73a-8631-44e5-ac44-356827a5212c',
|
platformId: platformDegiro.id
|
||||||
platformId: platformCoinbase.id,
|
|
||||||
quantity: 0.5614682,
|
|
||||||
symbol: 'BTCUSD',
|
|
||||||
type: Type.BUY,
|
|
||||||
unitPrice: 3562.089535970158
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
currency: Currency.USD,
|
accountType: AccountType.SECURITIES,
|
||||||
date: new Date(Date.UTC(2018, 9, 1, 0, 0, 0)),
|
id: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
|
||||||
fee: 80.79,
|
isDefault: true,
|
||||||
id: '71c08e2a-4a86-44ae-a890-c337de5d5f9b',
|
name: 'Interactive Brokers Account',
|
||||||
platformId: platformInteractiveBrokers.id,
|
platformId: platformInteractiveBrokers.id
|
||||||
quantity: 5,
|
|
||||||
symbol: 'AMZN',
|
|
||||||
type: Type.BUY,
|
|
||||||
unitPrice: 2021.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
currency: Currency.USD,
|
|
||||||
date: new Date(Date.UTC(2019, 2, 1, 0, 0, 0)),
|
|
||||||
fee: 19.9,
|
|
||||||
id: '385f2c2c-d53e-4937-b0e5-e92ef6020d4e',
|
|
||||||
platformId: platformInteractiveBrokers.id,
|
|
||||||
quantity: 10,
|
|
||||||
symbol: 'VTI',
|
|
||||||
type: Type.BUY,
|
|
||||||
unitPrice: 144.38
|
|
||||||
},
|
|
||||||
{
|
|
||||||
currency: Currency.USD,
|
|
||||||
date: new Date(Date.UTC(2019, 8, 3, 0, 0, 0)),
|
|
||||||
fee: 19.9,
|
|
||||||
id: '185f2c2c-d53e-4937-b0e5-a93ef6020d4e',
|
|
||||||
platformId: platformInteractiveBrokers.id,
|
|
||||||
quantity: 10,
|
|
||||||
symbol: 'VTI',
|
|
||||||
type: Type.BUY,
|
|
||||||
unitPrice: 147.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
currency: Currency.USD,
|
|
||||||
date: new Date(Date.UTC(2020, 2, 2, 0, 0, 0)),
|
|
||||||
fee: 19.9,
|
|
||||||
id: '347b0430-a84f-4031-a0f9-390399066ad6',
|
|
||||||
platformId: platformInteractiveBrokers.id,
|
|
||||||
quantity: 10,
|
|
||||||
symbol: 'VTI',
|
|
||||||
type: Type.BUY,
|
|
||||||
unitPrice: 151.41
|
|
||||||
},
|
|
||||||
{
|
|
||||||
currency: Currency.USD,
|
|
||||||
date: new Date(Date.UTC(2020, 8, 1, 0, 0, 0)),
|
|
||||||
fee: 19.9,
|
|
||||||
id: '67ec3f47-3189-4b63-ba05-60d3a06b302f',
|
|
||||||
platformId: platformInteractiveBrokers.id,
|
|
||||||
quantity: 10,
|
|
||||||
symbol: 'VTI',
|
|
||||||
type: Type.BUY,
|
|
||||||
unitPrice: 177.69
|
|
||||||
},
|
|
||||||
{
|
|
||||||
currency: Currency.USD,
|
|
||||||
date: new Date(Date.UTC(2020, 2, 1, 0, 0, 0)),
|
|
||||||
fee: 19.9,
|
|
||||||
id: 'd01c6fbc-fa8d-47e6-8e80-66f882d2bfd2',
|
|
||||||
platformId: platformInteractiveBrokers.id,
|
|
||||||
quantity: 10,
|
|
||||||
symbol: 'VTI',
|
|
||||||
type: Type.BUY,
|
|
||||||
unitPrice: 203.15
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
alias: 'Demo',
|
||||||
|
id: '9b112b4d-3b7d-4bad-9bdd-3b0f7b4dac2f',
|
||||||
|
role: Role.DEMO
|
||||||
},
|
},
|
||||||
update: {},
|
update: {},
|
||||||
where: { id: '9b112b4d-3b7d-4bad-9bdd-3b0f7b4dac2f' }
|
where: { id: '9b112b4d-3b7d-4bad-9bdd-3b0f7b4dac2f' }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await prisma.order.createMany({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
accountId: '65cfb79d-b6c7-4591-9d46-73426bc62094',
|
||||||
|
accountUserId: userDemo.id,
|
||||||
|
currency: Currency.USD,
|
||||||
|
date: new Date(Date.UTC(2017, 0, 3, 0, 0, 0)),
|
||||||
|
fee: 30,
|
||||||
|
id: 'cf7c0418-8535-4089-ae3d-5dbfa0aec2e1',
|
||||||
|
platformId: platformDegiro.id,
|
||||||
|
quantity: 50,
|
||||||
|
symbol: 'TSLA',
|
||||||
|
type: Type.BUY,
|
||||||
|
unitPrice: 42.97,
|
||||||
|
userId: userDemo.id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accountId: 'd804de69-0429-42dc-b6ca-b308fd7dd926',
|
||||||
|
accountUserId: userDemo.id,
|
||||||
|
currency: Currency.USD,
|
||||||
|
date: new Date(Date.UTC(2017, 7, 16, 0, 0, 0)),
|
||||||
|
fee: 29.9,
|
||||||
|
id: 'a1c5d73a-8631-44e5-ac44-356827a5212c',
|
||||||
|
platformId: platformCoinbase.id,
|
||||||
|
quantity: 0.5614682,
|
||||||
|
symbol: 'BTCUSD',
|
||||||
|
type: Type.BUY,
|
||||||
|
unitPrice: 3562.089535970158,
|
||||||
|
userId: userDemo.id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
|
||||||
|
accountUserId: userDemo.id,
|
||||||
|
currency: Currency.USD,
|
||||||
|
date: new Date(Date.UTC(2018, 9, 1, 0, 0, 0)),
|
||||||
|
fee: 80.79,
|
||||||
|
id: '71c08e2a-4a86-44ae-a890-c337de5d5f9b',
|
||||||
|
platformId: platformInteractiveBrokers.id,
|
||||||
|
quantity: 5,
|
||||||
|
symbol: 'AMZN',
|
||||||
|
type: Type.BUY,
|
||||||
|
unitPrice: 2021.99,
|
||||||
|
userId: userDemo.id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
|
||||||
|
accountUserId: userDemo.id,
|
||||||
|
currency: Currency.USD,
|
||||||
|
date: new Date(Date.UTC(2019, 2, 1, 0, 0, 0)),
|
||||||
|
fee: 19.9,
|
||||||
|
id: '385f2c2c-d53e-4937-b0e5-e92ef6020d4e',
|
||||||
|
platformId: platformInteractiveBrokers.id,
|
||||||
|
quantity: 10,
|
||||||
|
symbol: 'VTI',
|
||||||
|
type: Type.BUY,
|
||||||
|
unitPrice: 144.38,
|
||||||
|
userId: userDemo.id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
|
||||||
|
accountUserId: userDemo.id,
|
||||||
|
currency: Currency.USD,
|
||||||
|
date: new Date(Date.UTC(2019, 8, 3, 0, 0, 0)),
|
||||||
|
fee: 19.9,
|
||||||
|
id: '185f2c2c-d53e-4937-b0e5-a93ef6020d4e',
|
||||||
|
platformId: platformInteractiveBrokers.id,
|
||||||
|
quantity: 10,
|
||||||
|
symbol: 'VTI',
|
||||||
|
type: Type.BUY,
|
||||||
|
unitPrice: 147.99,
|
||||||
|
userId: userDemo.id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
|
||||||
|
accountUserId: userDemo.id,
|
||||||
|
currency: Currency.USD,
|
||||||
|
date: new Date(Date.UTC(2020, 2, 2, 0, 0, 0)),
|
||||||
|
fee: 19.9,
|
||||||
|
id: '347b0430-a84f-4031-a0f9-390399066ad6',
|
||||||
|
platformId: platformInteractiveBrokers.id,
|
||||||
|
quantity: 10,
|
||||||
|
symbol: 'VTI',
|
||||||
|
type: Type.BUY,
|
||||||
|
unitPrice: 151.41,
|
||||||
|
userId: userDemo.id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
|
||||||
|
accountUserId: userDemo.id,
|
||||||
|
currency: Currency.USD,
|
||||||
|
date: new Date(Date.UTC(2020, 8, 1, 0, 0, 0)),
|
||||||
|
fee: 19.9,
|
||||||
|
id: '67ec3f47-3189-4b63-ba05-60d3a06b302f',
|
||||||
|
platformId: platformInteractiveBrokers.id,
|
||||||
|
quantity: 10,
|
||||||
|
symbol: 'VTI',
|
||||||
|
type: Type.BUY,
|
||||||
|
unitPrice: 177.69,
|
||||||
|
userId: userDemo.id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
|
||||||
|
accountUserId: userDemo.id,
|
||||||
|
currency: Currency.USD,
|
||||||
|
date: new Date(Date.UTC(2020, 2, 1, 0, 0, 0)),
|
||||||
|
fee: 19.9,
|
||||||
|
id: 'd01c6fbc-fa8d-47e6-8e80-66f882d2bfd2',
|
||||||
|
platformId: platformInteractiveBrokers.id,
|
||||||
|
quantity: 10,
|
||||||
|
symbol: 'VTI',
|
||||||
|
type: Type.BUY,
|
||||||
|
unitPrice: 203.15,
|
||||||
|
userId: userDemo.id
|
||||||
|
}
|
||||||
|
],
|
||||||
|
skipDuplicates: true
|
||||||
|
});
|
||||||
|
|
||||||
console.log({
|
console.log({
|
||||||
platformBitcoinSuisse,
|
platformBitcoinSuisse,
|
||||||
platformBitpanda,
|
platformBitpanda,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user