Feature/rename Order to activities in account database schema (#4577)
* Rename Order to activities * Update changelog
This commit is contained in:
parent
8df9667979
commit
8fbdcac66c
@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- Renamed `Order` to `activities` in the `Account` database schema
|
||||||
- Improved the language localization for German (`de`)
|
- Improved the language localization for German (`de`)
|
||||||
|
|
||||||
## 2.157.1 - 2025-04-29
|
## 2.157.1 - 2025-04-29
|
||||||
|
@ -57,17 +57,17 @@ export class AccountController {
|
|||||||
@HasPermission(permissions.deleteAccount)
|
@HasPermission(permissions.deleteAccount)
|
||||||
@UseGuards(AuthGuard('jwt'), HasPermissionGuard)
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard)
|
||||||
public async deleteAccount(@Param('id') id: string): Promise<AccountModel> {
|
public async deleteAccount(@Param('id') id: string): Promise<AccountModel> {
|
||||||
const account = await this.accountService.accountWithOrders(
|
const account = await this.accountService.accountWithActivities(
|
||||||
{
|
{
|
||||||
id_userId: {
|
id_userId: {
|
||||||
id,
|
id,
|
||||||
userId: this.request.user.id
|
userId: this.request.user.id
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ Order: true }
|
{ activities: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!account || account?.Order.length > 0) {
|
if (!account || account?.activities.length > 0) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
getReasonPhrase(StatusCodes.FORBIDDEN),
|
getReasonPhrase(StatusCodes.FORBIDDEN),
|
||||||
StatusCodes.FORBIDDEN
|
StatusCodes.FORBIDDEN
|
||||||
|
@ -39,12 +39,12 @@ export class AccountService {
|
|||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async accountWithOrders(
|
public async accountWithActivities(
|
||||||
accountWhereUniqueInput: Prisma.AccountWhereUniqueInput,
|
accountWhereUniqueInput: Prisma.AccountWhereUniqueInput,
|
||||||
accountInclude: Prisma.AccountInclude
|
accountInclude: Prisma.AccountInclude
|
||||||
): Promise<
|
): Promise<
|
||||||
Account & {
|
Account & {
|
||||||
Order?: Order[];
|
activities?: Order[];
|
||||||
}
|
}
|
||||||
> {
|
> {
|
||||||
return this.prismaService.account.findUnique({
|
return this.prismaService.account.findUnique({
|
||||||
@ -62,8 +62,8 @@ export class AccountService {
|
|||||||
orderBy?: Prisma.AccountOrderByWithRelationInput;
|
orderBy?: Prisma.AccountOrderByWithRelationInput;
|
||||||
}): Promise<
|
}): Promise<
|
||||||
(Account & {
|
(Account & {
|
||||||
|
activities?: Order[];
|
||||||
balances?: AccountBalance[];
|
balances?: AccountBalance[];
|
||||||
Order?: Order[];
|
|
||||||
Platform?: Platform;
|
Platform?: Platform;
|
||||||
})[]
|
})[]
|
||||||
> {
|
> {
|
||||||
@ -140,7 +140,7 @@ export class AccountService {
|
|||||||
|
|
||||||
public async getAccounts(aUserId: string): Promise<Account[]> {
|
public async getAccounts(aUserId: string): Promise<Account[]> {
|
||||||
const accounts = await this.accounts({
|
const accounts = await this.accounts({
|
||||||
include: { Order: true, Platform: true },
|
include: { activities: true, Platform: true },
|
||||||
orderBy: { name: 'asc' },
|
orderBy: { name: 'asc' },
|
||||||
where: { userId: aUserId }
|
where: { userId: aUserId }
|
||||||
});
|
});
|
||||||
@ -148,15 +148,15 @@ export class AccountService {
|
|||||||
return accounts.map((account) => {
|
return accounts.map((account) => {
|
||||||
let transactionCount = 0;
|
let transactionCount = 0;
|
||||||
|
|
||||||
for (const order of account.Order) {
|
for (const { isDraft } of account.activities) {
|
||||||
if (!order.isDraft) {
|
if (!isDraft) {
|
||||||
transactionCount += 1;
|
transactionCount += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = { ...account, transactionCount };
|
const result = { ...account, transactionCount };
|
||||||
|
|
||||||
delete result.Order;
|
delete result.activities;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
@ -100,7 +100,7 @@ export class OrderService {
|
|||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
): Promise<Order> {
|
): Promise<Order> {
|
||||||
let Account: Prisma.AccountCreateNestedOneWithoutOrderInput;
|
let Account: Prisma.AccountCreateNestedOneWithoutActivitiesInput;
|
||||||
|
|
||||||
if (data.accountId) {
|
if (data.accountId) {
|
||||||
Account = {
|
Account = {
|
||||||
|
@ -139,7 +139,7 @@ export class PortfolioService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (filterByDataSource && filterBySymbol) {
|
if (filterByDataSource && filterBySymbol) {
|
||||||
where.Order = {
|
where.activities = {
|
||||||
some: {
|
some: {
|
||||||
SymbolProfile: {
|
SymbolProfile: {
|
||||||
AND: [
|
AND: [
|
||||||
@ -154,7 +154,7 @@ export class PortfolioService {
|
|||||||
const [accounts, details] = await Promise.all([
|
const [accounts, details] = await Promise.all([
|
||||||
this.accountService.accounts({
|
this.accountService.accounts({
|
||||||
where,
|
where,
|
||||||
include: { Order: true, Platform: true },
|
include: { activities: true, Platform: true },
|
||||||
orderBy: { name: 'asc' }
|
orderBy: { name: 'asc' }
|
||||||
}),
|
}),
|
||||||
this.getDetails({
|
this.getDetails({
|
||||||
@ -170,8 +170,8 @@ export class PortfolioService {
|
|||||||
return accounts.map((account) => {
|
return accounts.map((account) => {
|
||||||
let transactionCount = 0;
|
let transactionCount = 0;
|
||||||
|
|
||||||
for (const order of account.Order) {
|
for (const { isDraft } of account.activities) {
|
||||||
if (!order.isDraft) {
|
if (!isDraft) {
|
||||||
transactionCount += 1;
|
transactionCount += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,7 +195,7 @@ export class PortfolioService {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
delete result.Order;
|
delete result.activities;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
@ -26,6 +26,7 @@ model Access {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Account {
|
model Account {
|
||||||
|
activities Order[]
|
||||||
balance Float @default(0)
|
balance Float @default(0)
|
||||||
balances AccountBalance[]
|
balances AccountBalance[]
|
||||||
comment String?
|
comment String?
|
||||||
@ -39,7 +40,6 @@ model Account {
|
|||||||
userId String
|
userId String
|
||||||
Platform Platform? @relation(fields: [platformId], references: [id])
|
Platform Platform? @relation(fields: [platformId], references: [id])
|
||||||
User User @relation(fields: [userId], onDelete: Cascade, references: [id])
|
User User @relation(fields: [userId], onDelete: Cascade, references: [id])
|
||||||
Order Order[]
|
|
||||||
|
|
||||||
@@id([id, userId])
|
@@id([id, userId])
|
||||||
@@index([currency])
|
@@index([currency])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user