Feature/simplify ids in database schema (#861)
* Simplify ids in database schema * Access * Order * Subscription * Update changelog
This commit is contained in:
parent
8f61f7c169
commit
ea89ca5734
@ -11,8 +11,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
- Extracted the activities table filter to a dedicated component
|
- Extracted the activities table filter to a dedicated component
|
||||||
- Changed the url of the _Get Started_ link to `https://ghostfol.io` on the public page
|
- Changed the url of the _Get Started_ link to `https://ghostfol.io` on the public page
|
||||||
|
- Simplified `@@id` using multiple fields with `@id` in the database schema of (`Access`, `Order`, `Subscription`)
|
||||||
- Upgraded `prisma` from version `3.11.1` to `3.12.0`
|
- Upgraded `prisma` from version `3.11.1` to `3.12.0`
|
||||||
|
|
||||||
|
### Todo
|
||||||
|
|
||||||
|
- Apply data migration (`yarn database:migrate`)
|
||||||
|
|
||||||
## 1.140.2 - 22.04.2022
|
## 1.140.2 - 22.04.2022
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -78,8 +78,12 @@ export class AccessController {
|
|||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@UseGuards(AuthGuard('jwt'))
|
@UseGuards(AuthGuard('jwt'))
|
||||||
public async deleteAccess(@Param('id') id: string): Promise<AccessModule> {
|
public async deleteAccess(@Param('id') id: string): Promise<AccessModule> {
|
||||||
|
const access = await this.accessService.access({ id });
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!hasPermission(this.request.user.permissions, permissions.deleteAccess)
|
!hasPermission(this.request.user.permissions, permissions.deleteAccess) ||
|
||||||
|
!access ||
|
||||||
|
access.userId !== this.request.user.id
|
||||||
) {
|
) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
getReasonPhrase(StatusCodes.FORBIDDEN),
|
getReasonPhrase(StatusCodes.FORBIDDEN),
|
||||||
@ -88,10 +92,7 @@ export class AccessController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this.accessService.deleteAccess({
|
return this.accessService.deleteAccess({
|
||||||
id_userId: {
|
id
|
||||||
id,
|
|
||||||
userId: this.request.user.id
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,12 @@ export class OrderController {
|
|||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@UseGuards(AuthGuard('jwt'))
|
@UseGuards(AuthGuard('jwt'))
|
||||||
public async deleteOrder(@Param('id') id: string): Promise<OrderModel> {
|
public async deleteOrder(@Param('id') id: string): Promise<OrderModel> {
|
||||||
|
const order = await this.orderService.order({ id });
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!hasPermission(this.request.user.permissions, permissions.deleteOrder)
|
!hasPermission(this.request.user.permissions, permissions.deleteOrder) ||
|
||||||
|
!order ||
|
||||||
|
order.userId !== this.request.user.id
|
||||||
) {
|
) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
getReasonPhrase(StatusCodes.FORBIDDEN),
|
getReasonPhrase(StatusCodes.FORBIDDEN),
|
||||||
@ -52,10 +56,7 @@ export class OrderController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this.orderService.deleteOrder({
|
return this.orderService.deleteOrder({
|
||||||
id_userId: {
|
id
|
||||||
id,
|
|
||||||
userId: this.request.user.id
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,23 +136,15 @@ export class OrderController {
|
|||||||
@UseGuards(AuthGuard('jwt'))
|
@UseGuards(AuthGuard('jwt'))
|
||||||
@UseInterceptors(TransformDataSourceInRequestInterceptor)
|
@UseInterceptors(TransformDataSourceInRequestInterceptor)
|
||||||
public async update(@Param('id') id: string, @Body() data: UpdateOrderDto) {
|
public async update(@Param('id') id: string, @Body() data: UpdateOrderDto) {
|
||||||
if (
|
|
||||||
!hasPermission(this.request.user.permissions, permissions.updateOrder)
|
|
||||||
) {
|
|
||||||
throw new HttpException(
|
|
||||||
getReasonPhrase(StatusCodes.FORBIDDEN),
|
|
||||||
StatusCodes.FORBIDDEN
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const originalOrder = await this.orderService.order({
|
const originalOrder = await this.orderService.order({
|
||||||
id_userId: {
|
id
|
||||||
id,
|
|
||||||
userId: this.request.user.id
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!originalOrder) {
|
if (
|
||||||
|
!hasPermission(this.request.user.permissions, permissions.updateOrder) ||
|
||||||
|
!originalOrder ||
|
||||||
|
originalOrder.userId !== this.request.user.id
|
||||||
|
) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
getReasonPhrase(StatusCodes.FORBIDDEN),
|
getReasonPhrase(StatusCodes.FORBIDDEN),
|
||||||
StatusCodes.FORBIDDEN
|
StatusCodes.FORBIDDEN
|
||||||
@ -183,10 +176,7 @@ export class OrderController {
|
|||||||
User: { connect: { id: this.request.user.id } }
|
User: { connect: { id: this.request.user.id } }
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
id_userId: {
|
id
|
||||||
id,
|
|
||||||
userId: this.request.user.id
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Access" DROP CONSTRAINT "Access_pkey",
|
||||||
|
ADD CONSTRAINT "Access_pkey" PRIMARY KEY ("id");
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "MarketData" ADD CONSTRAINT "MarketData_pkey" PRIMARY KEY ("id");
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Order" DROP CONSTRAINT "Order_pkey",
|
||||||
|
ADD CONSTRAINT "Order_pkey" PRIMARY KEY ("id");
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Subscription" DROP CONSTRAINT "Subscription_pkey",
|
||||||
|
ADD CONSTRAINT "Subscription_pkey" PRIMARY KEY ("id");
|
@ -13,12 +13,10 @@ model Access {
|
|||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
GranteeUser User? @relation(fields: [granteeUserId], name: "accessGet", references: [id])
|
GranteeUser User? @relation(fields: [granteeUserId], name: "accessGet", references: [id])
|
||||||
granteeUserId String?
|
granteeUserId String?
|
||||||
id String @default(uuid())
|
id String @id @default(uuid())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
User User @relation(fields: [userId], name: "accessGive", references: [id])
|
User User @relation(fields: [userId], name: "accessGive", references: [id])
|
||||||
userId String
|
userId String
|
||||||
|
|
||||||
@@id([id, userId])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model Account {
|
model Account {
|
||||||
@ -61,7 +59,7 @@ model MarketData {
|
|||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
dataSource DataSource
|
dataSource DataSource
|
||||||
date DateTime
|
date DateTime
|
||||||
id String @default(uuid())
|
id String @id @default(uuid())
|
||||||
symbol String
|
symbol String
|
||||||
marketPrice Float
|
marketPrice Float
|
||||||
|
|
||||||
@ -76,7 +74,7 @@ model Order {
|
|||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
date DateTime
|
date DateTime
|
||||||
fee Float
|
fee Float
|
||||||
id String @default(uuid())
|
id String @id @default(uuid())
|
||||||
isDraft Boolean @default(false)
|
isDraft Boolean @default(false)
|
||||||
quantity Float
|
quantity Float
|
||||||
SymbolProfile SymbolProfile @relation(fields: [symbolProfileId], references: [id])
|
SymbolProfile SymbolProfile @relation(fields: [symbolProfileId], references: [id])
|
||||||
@ -86,8 +84,6 @@ model Order {
|
|||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
User User @relation(fields: [userId], references: [id])
|
User User @relation(fields: [userId], references: [id])
|
||||||
userId String
|
userId String
|
||||||
|
|
||||||
@@id([id, userId])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model Platform {
|
model Platform {
|
||||||
@ -138,20 +134,18 @@ model SymbolProfileOverrides {
|
|||||||
countries Json?
|
countries Json?
|
||||||
name String?
|
name String?
|
||||||
sectors Json?
|
sectors Json?
|
||||||
SymbolProfile SymbolProfile @relation(fields: [symbolProfileId], references: [id])
|
SymbolProfile SymbolProfile @relation(fields: [symbolProfileId], references: [id])
|
||||||
symbolProfileId String @id
|
symbolProfileId String @id
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
model Subscription {
|
model Subscription {
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
expiresAt DateTime
|
expiresAt DateTime
|
||||||
id String @default(uuid())
|
id String @id @default(uuid())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
User User @relation(fields: [userId], references: [id])
|
User User @relation(fields: [userId], references: [id])
|
||||||
userId String
|
userId String
|
||||||
|
|
||||||
@@id([id, userId])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model User {
|
model User {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user