mirror of https://github.com/ghostfolio/ghostfolio
5 changed files with 184 additions and 31 deletions
@ -0,0 +1,11 @@ |
|||
import { PrismaModule } from '@ghostfolio/api/services/prisma/prisma.module'; |
|||
import { Module } from '@nestjs/common'; |
|||
|
|||
import { SymbolProfileOverwriteService } from './symbol-profile-overwrite.service'; |
|||
|
|||
@Module({ |
|||
imports: [PrismaModule], |
|||
providers: [SymbolProfileOverwriteService], |
|||
exports: [SymbolProfileOverwriteService] |
|||
}) |
|||
export class SymbolProfileOverwriteModule {} |
@ -0,0 +1,68 @@ |
|||
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; |
|||
import { Injectable } from '@nestjs/common'; |
|||
import { DataSource, Prisma, SymbolProfileOverrides } from '@prisma/client'; |
|||
|
|||
@Injectable() |
|||
export class SymbolProfileOverwriteService { |
|||
public constructor(private readonly prismaService: PrismaService) {} |
|||
|
|||
public async add( |
|||
assetProfileOverwrite: Prisma.SymbolProfileOverridesCreateInput |
|||
): Promise<SymbolProfileOverrides | never> { |
|||
return this.prismaService.symbolProfileOverrides.create({ |
|||
data: assetProfileOverwrite |
|||
}); |
|||
} |
|||
|
|||
public async delete(symbolProfileId: string) { |
|||
return this.prismaService.symbolProfileOverrides.delete({ |
|||
where: { symbolProfileId: symbolProfileId } |
|||
}); |
|||
} |
|||
|
|||
public updateSymbolProfileOverrides({ |
|||
assetClass, |
|||
assetSubClass, |
|||
name, |
|||
countries, |
|||
sectors, |
|||
url, |
|||
symbolProfileId |
|||
}: Prisma.SymbolProfileOverridesUpdateInput & { symbolProfileId: string }) { |
|||
return this.prismaService.symbolProfileOverrides.update({ |
|||
data: { |
|||
assetClass, |
|||
assetSubClass, |
|||
name, |
|||
countries, |
|||
sectors, |
|||
url |
|||
}, |
|||
where: { symbolProfileId: symbolProfileId } |
|||
}); |
|||
} |
|||
|
|||
public async GetSymbolProfileId( |
|||
Symbol: string, |
|||
datasource: DataSource |
|||
): Promise<string> { |
|||
let SymbolProfileId = await this.prismaService.symbolProfile |
|||
.findFirst({ |
|||
where: { |
|||
symbol: Symbol, |
|||
dataSource: datasource |
|||
} |
|||
}) |
|||
.then((s) => s.id); |
|||
|
|||
let symbolProfileIdSaved = await this.prismaService.symbolProfileOverrides |
|||
.findFirst({ |
|||
where: { |
|||
symbolProfileId: SymbolProfileId |
|||
} |
|||
}) |
|||
.then((s) => s?.symbolProfileId); |
|||
|
|||
return symbolProfileIdSaved; |
|||
} |
|||
} |
Loading…
Reference in new issue