Browse Source

Refactoring

pull/4483/head
Thomas Kaul 3 weeks ago
parent
commit
520381d446
  1. 4
      apps/api/src/app/admin/admin.controller.ts
  2. 2
      apps/api/src/services/cron.service.ts
  3. 13
      apps/api/src/services/queues/data-gathering/data-gathering.service.ts
  4. 70
      apps/api/src/services/symbol-profile/symbol-profile.service.ts

4
apps/api/src/app/admin/admin.controller.ts

@ -83,7 +83,7 @@ export class AdminController {
@UseGuards(AuthGuard('jwt'), HasPermissionGuard)
public async gatherMax(): Promise<void> {
const assetProfileIdentifiers =
await this.dataGatheringService.getAllAssetProfileIdentifiers();
await this.dataGatheringService.getAllActiveAssetProfileIdentifiers();
await this.dataGatheringService.addJobsToQueue(
assetProfileIdentifiers.map(({ dataSource, symbol }) => {
@ -110,7 +110,7 @@ export class AdminController {
@UseGuards(AuthGuard('jwt'), HasPermissionGuard)
public async gatherProfileData(): Promise<void> {
const assetProfileIdentifiers =
await this.dataGatheringService.getAllAssetProfileIdentifiers();
await this.dataGatheringService.getAllActiveAssetProfileIdentifiers();
await this.dataGatheringService.addJobsToQueue(
assetProfileIdentifiers.map(({ dataSource, symbol }) => {

2
apps/api/src/services/cron.service.ts

@ -57,7 +57,7 @@ export class CronService {
public async runEverySundayAtTwelvePm() {
if (await this.isDataGatheringEnabled()) {
const assetProfileIdentifiers =
await this.dataGatheringService.getAllAssetProfileIdentifiers();
await this.dataGatheringService.getAllActiveAssetProfileIdentifiers();
await this.dataGatheringService.addJobsToQueue(
assetProfileIdentifiers.map(({ dataSource, symbol }) => {

13
apps/api/src/services/queues/data-gathering/data-gathering.service.ts

@ -159,7 +159,8 @@ export class DataGatheringService {
);
if (!assetProfileIdentifiers) {
assetProfileIdentifiers = await this.getAllAssetProfileIdentifiers();
assetProfileIdentifiers =
await this.getAllActiveAssetProfileIdentifiers();
}
if (assetProfileIdentifiers.length <= 0) {
@ -296,7 +297,7 @@ export class DataGatheringService {
);
}
public async getAllAssetProfileIdentifiers(): Promise<
public async getAllActiveAssetProfileIdentifiers(): Promise<
AssetProfileIdentifier[]
> {
const symbolProfiles = await this.prismaService.symbolProfile.findMany({
@ -373,9 +374,11 @@ export class DataGatheringService {
withUserSubscription?: boolean;
}): Promise<IDataGatheringItem[]> {
const symbolProfiles =
await this.symbolProfileService.getSymbolProfilesByUserSubscription({
withUserSubscription
});
await this.symbolProfileService.getActiveSymbolProfilesByUserSubscription(
{
withUserSubscription
}
);
const assetProfileIdentifiersWithCompleteMarketData =
await this.getAssetProfileIdentifiersWithCompleteMarketData();

70
apps/api/src/services/symbol-profile/symbol-profile.service.ts

@ -35,6 +35,41 @@ export class SymbolProfileService {
});
}
public async getActiveSymbolProfilesByUserSubscription({
withUserSubscription = false
}: {
withUserSubscription?: boolean;
}) {
return this.prismaService.symbolProfile.findMany({
include: {
Order: {
include: {
User: true
}
}
},
orderBy: [{ symbol: 'asc' }],
where: {
isActive: true,
Order: withUserSubscription
? {
some: {
User: {
Subscription: { some: { expiresAt: { gt: new Date() } } }
}
}
}
: {
every: {
User: {
Subscription: { none: { expiresAt: { gt: new Date() } } }
}
}
}
}
});
}
public async getSymbolProfiles(
aAssetProfileIdentifiers: AssetProfileIdentifier[]
): Promise<EnhancedSymbolProfile[]> {
@ -91,41 +126,6 @@ export class SymbolProfileService {
});
}
public async getSymbolProfilesByUserSubscription({
withUserSubscription = false
}: {
withUserSubscription?: boolean;
}) {
return this.prismaService.symbolProfile.findMany({
include: {
Order: {
include: {
User: true
}
}
},
orderBy: [{ symbol: 'asc' }],
where: {
isActive: true,
Order: withUserSubscription
? {
some: {
User: {
Subscription: { some: { expiresAt: { gt: new Date() } } }
}
}
}
: {
every: {
User: {
Subscription: { none: { expiresAt: { gt: new Date() } } }
}
}
}
}
});
}
public updateSymbolProfile({
assetClass,
assetSubClass,

Loading…
Cancel
Save