Browse Source

Refactoring

pull/4483/head
Thomas Kaul 4 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. 11
      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) @UseGuards(AuthGuard('jwt'), HasPermissionGuard)
public async gatherMax(): Promise<void> { public async gatherMax(): Promise<void> {
const assetProfileIdentifiers = const assetProfileIdentifiers =
await this.dataGatheringService.getAllAssetProfileIdentifiers(); await this.dataGatheringService.getAllActiveAssetProfileIdentifiers();
await this.dataGatheringService.addJobsToQueue( await this.dataGatheringService.addJobsToQueue(
assetProfileIdentifiers.map(({ dataSource, symbol }) => { assetProfileIdentifiers.map(({ dataSource, symbol }) => {
@ -110,7 +110,7 @@ export class AdminController {
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) @UseGuards(AuthGuard('jwt'), HasPermissionGuard)
public async gatherProfileData(): Promise<void> { public async gatherProfileData(): Promise<void> {
const assetProfileIdentifiers = const assetProfileIdentifiers =
await this.dataGatheringService.getAllAssetProfileIdentifiers(); await this.dataGatheringService.getAllActiveAssetProfileIdentifiers();
await this.dataGatheringService.addJobsToQueue( await this.dataGatheringService.addJobsToQueue(
assetProfileIdentifiers.map(({ dataSource, symbol }) => { assetProfileIdentifiers.map(({ dataSource, symbol }) => {

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

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

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

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

Loading…
Cancel
Save