From 7f5580d93003ad12d11e9d2840f464d2e203d79e Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sun, 24 Apr 2022 08:25:19 +0200 Subject: [PATCH] Add schema --- apps/api/src/app/order/order.service.ts | 12 ++++++++++++ prisma/schema.prisma | 22 +++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index ee01b3092..5f545effc 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -152,11 +152,13 @@ export class OrderService { public async getOrders({ includeDrafts = false, + tags, types, userCurrency, userId }: { includeDrafts?: boolean; + tags?: string[]; types?: TypeOfOrder[]; userCurrency: string; userId: string; @@ -167,6 +169,16 @@ export class OrderService { where.isDraft = false; } + if (tags?.length > 0) { + where.tags = { + some: { + tag: { + name: tags[0] + } + } + }; + } + if (types) { where.OR = types.map((type) => { return { diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 7ffca1690..63f7e6d08 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -81,6 +81,7 @@ model Order { quantity Float SymbolProfile SymbolProfile @relation(fields: [symbolProfileId], references: [id]) symbolProfileId String + tags OrderTags[] type Type unitPrice Float updatedAt DateTime @updatedAt @@ -90,6 +91,15 @@ model Order { @@id([id, userId]) } +model OrderTags { + id String @id @default(uuid()) + order Order? @relation(fields: [orderId, orderUserId], references: [id, userId]) + orderId String? + orderUserId String? + tag Tag? @relation(fields: [tagId], references: [id]) + tagId String? +} + model Platform { Account Account[] id String @id @default(uuid()) @@ -138,9 +148,9 @@ model SymbolProfileOverrides { countries Json? name String? sectors Json? - SymbolProfile SymbolProfile @relation(fields: [symbolProfileId], references: [id]) - symbolProfileId String @id - updatedAt DateTime @updatedAt + SymbolProfile SymbolProfile @relation(fields: [symbolProfileId], references: [id]) + symbolProfileId String @id + updatedAt DateTime @updatedAt } model Subscription { @@ -154,6 +164,12 @@ model Subscription { @@id([id, userId]) } +model Tag { + id String @id @default(uuid()) + name String @unique + orders OrderTags[] +} + model User { Access Access[] @relation("accessGet") AccessGive Access[] @relation(name: "accessGive")