Browse Source

Refactoring

pull/6981/head
Thomas Kaul 3 months ago
parent
commit
4182d1684e
  1. 15
      apps/api/src/app/admin/admin.service.ts
  2. 16
      apps/api/src/app/endpoints/asset-profiles/asset-profiles.service.ts
  3. 27
      apps/api/src/services/symbol-profile/symbol-profile.service.ts
  4. 21
      libs/common/src/lib/dtos/update-asset-profile-data.dto.ts
  5. 4
      libs/common/src/lib/dtos/update-asset-profile.dto.ts
  6. 21
      package-lock.json
  7. 1
      package.json

15
apps/api/src/app/admin/admin.service.ts

@ -603,21 +603,14 @@ export class AdminService {
comment, comment,
currency, currency,
dataSource, dataSource,
holdings,
isActive, isActive,
scraperConfiguration, scraperConfiguration,
symbol, symbol,
symbolMapping, symbolMapping,
...(dataSource === 'MANUAL' ...this.symbolProfileService.getAssetProfileUpdateInput(
? { assetClass, assetSubClass, countries, name, sectors, url } { dataSource, symbol },
: { symbolProfileOverrides
SymbolProfileOverrides: { )
upsert: {
create: symbolProfileOverrides,
update: symbolProfileOverrides
}
}
})
}; };
await this.symbolProfileService.updateSymbolProfile( await this.symbolProfileService.updateSymbolProfile(

16
apps/api/src/app/endpoints/asset-profiles/asset-profiles.service.ts

@ -6,7 +6,7 @@ import {
} from '@ghostfolio/common/interfaces'; } from '@ghostfolio/common/interfaces';
import { Injectable, NotFoundException } from '@nestjs/common'; import { Injectable, NotFoundException } from '@nestjs/common';
import { DataSource, Prisma } from '@prisma/client'; import { Prisma } from '@prisma/client';
@Injectable() @Injectable()
export class AssetProfilesService { export class AssetProfilesService {
@ -42,16 +42,10 @@ export class AssetProfilesService {
dataSource, dataSource,
symbol symbol
}, },
dataSource === DataSource.MANUAL this.symbolProfileService.getAssetProfileUpdateInput(
? data { dataSource, symbol },
: { data
SymbolProfileOverrides: { )
upsert: {
create: data,
update: data
}
}
}
); );
const [updatedAssetProfile] = const [updatedAssetProfile] =

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

@ -11,7 +11,12 @@ import { Country } from '@ghostfolio/common/interfaces/country.interface';
import { Sector } from '@ghostfolio/common/interfaces/sector.interface'; import { Sector } from '@ghostfolio/common/interfaces/sector.interface';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { Prisma, SymbolProfile, SymbolProfileOverrides } from '@prisma/client'; import {
DataSource,
Prisma,
SymbolProfile,
SymbolProfileOverrides
} from '@prisma/client';
import { continents, countries } from 'countries-list'; import { continents, countries } from 'countries-list';
@Injectable() @Injectable()
@ -71,6 +76,26 @@ export class SymbolProfileService {
}); });
} }
public getAssetProfileUpdateInput(
{ dataSource }: AssetProfileIdentifier,
data: Prisma.SymbolProfileUpdateInput
): Prisma.SymbolProfileUpdateInput {
if (dataSource === DataSource.MANUAL) {
return data;
}
return {
SymbolProfileOverrides: {
upsert: {
create:
data as Prisma.SymbolProfileOverridesCreateWithoutSymbolProfileInput,
update:
data as Prisma.SymbolProfileOverridesUpdateWithoutSymbolProfileInput
}
}
};
}
public async getSymbolProfiles( public async getSymbolProfiles(
aAssetProfileIdentifiers: AssetProfileIdentifier[] aAssetProfileIdentifiers: AssetProfileIdentifier[]
): Promise<EnhancedSymbolProfile[]> { ): Promise<EnhancedSymbolProfile[]> {

21
libs/common/src/lib/dtos/update-asset-profile-data.dto.ts

@ -1,16 +1,9 @@
import { Prisma } from '@prisma/client'; import { PickType } from '@nestjs/mapped-types';
import { IsArray, IsOptional } from 'class-validator';
export class UpdateAssetProfileDataDto { import { UpdateAssetProfileDto } from './update-asset-profile.dto';
@IsArray()
@IsOptional()
countries?: Prisma.InputJsonArray;
@IsArray() export class UpdateAssetProfileDataDto extends PickType(UpdateAssetProfileDto, [
@IsOptional() 'countries',
holdings?: Prisma.InputJsonArray; 'holdings',
'sectors'
@IsArray() ]) {}
@IsOptional()
sectors?: Prisma.InputJsonArray;
}

4
libs/common/src/lib/dtos/update-asset-profile.dto.ts

@ -36,6 +36,10 @@ export class UpdateAssetProfileDto {
@IsOptional() @IsOptional()
dataSource?: DataSource; dataSource?: DataSource;
@IsArray()
@IsOptional()
holdings?: Prisma.InputJsonArray;
@IsBoolean() @IsBoolean()
@IsOptional() @IsOptional()
isActive?: boolean; isActive?: boolean;

21
package-lock.json

@ -36,6 +36,7 @@
"@nestjs/core": "11.1.21", "@nestjs/core": "11.1.21",
"@nestjs/event-emitter": "3.1.0", "@nestjs/event-emitter": "3.1.0",
"@nestjs/jwt": "11.0.2", "@nestjs/jwt": "11.0.2",
"@nestjs/mapped-types": "2.1.1",
"@nestjs/passport": "11.0.5", "@nestjs/passport": "11.0.5",
"@nestjs/platform-express": "11.1.21", "@nestjs/platform-express": "11.1.21",
"@nestjs/schedule": "6.1.3", "@nestjs/schedule": "6.1.3",
@ -8279,6 +8280,26 @@
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0" "@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0"
} }
}, },
"node_modules/@nestjs/mapped-types": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/@nestjs/mapped-types/-/mapped-types-2.1.1.tgz",
"integrity": "sha512-SCCoMEJ6jdeI5h/N+KCVF1+pmg/hmEkNA5nHTS8Gvww7T/LCl4o1gFLinw2iQ60w7slFkszHcGLKGdazVI4F8A==",
"license": "MIT",
"peerDependencies": {
"@nestjs/common": "^10.0.0 || ^11.0.0",
"class-transformer": "^0.4.0 || ^0.5.0",
"class-validator": "^0.13.0 || ^0.14.0 || ^0.15.0",
"reflect-metadata": "^0.1.12 || ^0.2.0"
},
"peerDependenciesMeta": {
"class-transformer": {
"optional": true
},
"class-validator": {
"optional": true
}
}
},
"node_modules/@nestjs/passport": { "node_modules/@nestjs/passport": {
"version": "11.0.5", "version": "11.0.5",
"resolved": "https://registry.npmjs.org/@nestjs/passport/-/passport-11.0.5.tgz", "resolved": "https://registry.npmjs.org/@nestjs/passport/-/passport-11.0.5.tgz",

1
package.json

@ -80,6 +80,7 @@
"@nestjs/core": "11.1.21", "@nestjs/core": "11.1.21",
"@nestjs/event-emitter": "3.1.0", "@nestjs/event-emitter": "3.1.0",
"@nestjs/jwt": "11.0.2", "@nestjs/jwt": "11.0.2",
"@nestjs/mapped-types": "2.1.1",
"@nestjs/passport": "11.0.5", "@nestjs/passport": "11.0.5",
"@nestjs/platform-express": "11.1.21", "@nestjs/platform-express": "11.1.21",
"@nestjs/schedule": "6.1.3", "@nestjs/schedule": "6.1.3",

Loading…
Cancel
Save