Browse Source

Feature/automatic deletion of unused asset profiles (#3525)

* Automatic deletion of unused asset profiles

* Update changelog
pull/3529/head^2
Thomas Kaul 3 months ago
committed by GitHub
parent
commit
8386fec98a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      CHANGELOG.md
  2. 1
      apps/api/src/app/order/order.controller.ts
  3. 27
      apps/api/src/app/order/order.service.ts
  4. 2
      apps/api/src/app/user/user.module.ts
  5. 6
      apps/api/src/app/user/user.service.ts

4
CHANGELOG.md

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Changed
- Added support for automatic deletion of unused asset profiles when deleting activities
### Fixed
- Fixed an issue with the all time high in the benchmarks of the markets overview

1
apps/api/src/app/order/order.controller.ts

@ -66,7 +66,6 @@ export class OrderController {
return this.orderService.deleteOrders({
filters,
userCurrency: this.request.user.Settings.settings.baseCurrency,
userId: this.request.user.id
});
}

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

@ -184,7 +184,15 @@ export class OrderService {
where
});
if (['FEE', 'INTEREST', 'ITEM', 'LIABILITY'].includes(order.type)) {
const [symbolProfile] =
await this.symbolProfileService.getSymbolProfilesByIds([
order.symbolProfileId
]);
if (
['FEE', 'INTEREST', 'ITEM', 'LIABILITY'].includes(order.type) ||
symbolProfile.activitiesCount === 0
) {
await this.symbolProfileService.deleteById(order.symbolProfileId);
}
@ -200,18 +208,16 @@ export class OrderService {
public async deleteOrders({
filters,
userCurrency,
userId
}: {
filters?: Filter[];
userCurrency: string;
userId: string;
}): Promise<number> {
const { activities } = await this.getOrders({
filters,
userId,
userCurrency,
includeDrafts: true,
userCurrency: undefined,
withExcludedAccounts: true
});
@ -225,6 +231,19 @@ export class OrderService {
}
});
const symbolProfiles =
await this.symbolProfileService.getSymbolProfilesByIds(
activities.map(({ symbolProfileId }) => {
return symbolProfileId;
})
);
for (const { activitiesCount, id } of symbolProfiles) {
if (activitiesCount === 0) {
await this.symbolProfileService.deleteById(id);
}
}
this.eventEmitter.emit(
PortfolioChangedEvent.getName(),
new PortfolioChangedEvent({ userId })

2
apps/api/src/app/user/user.module.ts

@ -1,3 +1,4 @@
import { OrderModule } from '@ghostfolio/api/app/order/order.module';
import { SubscriptionModule } from '@ghostfolio/api/app/subscription/subscription.module';
import { ConfigurationModule } from '@ghostfolio/api/services/configuration/configuration.module';
import { PrismaModule } from '@ghostfolio/api/services/prisma/prisma.module';
@ -19,6 +20,7 @@ import { UserService } from './user.service';
secret: process.env.JWT_SECRET_KEY,
signOptions: { expiresIn: '30 days' }
}),
OrderModule,
PrismaModule,
PropertyModule,
SubscriptionModule,

6
apps/api/src/app/user/user.service.ts

@ -1,3 +1,4 @@
import { OrderService } from '@ghostfolio/api/app/order/order.service';
import { SubscriptionService } from '@ghostfolio/api/app/subscription/subscription.service';
import { environment } from '@ghostfolio/api/environments/environment';
import { PortfolioChangedEvent } from '@ghostfolio/api/events/portfolio-changed.event';
@ -40,6 +41,7 @@ export class UserService {
public constructor(
private readonly configurationService: ConfigurationService,
private readonly eventEmitter: EventEmitter2,
private readonly orderService: OrderService,
private readonly prismaService: PrismaService,
private readonly propertyService: PropertyService,
private readonly subscriptionService: SubscriptionService,
@ -398,8 +400,8 @@ export class UserService {
} catch {}
try {
await this.prismaService.order.deleteMany({
where: { userId: where.id }
await this.orderService.deleteOrders({
userId: where.id
});
} catch {}

Loading…
Cancel
Save