mirror of https://github.com/ghostfolio/ghostfolio
Thomas Kaul
3 years ago
committed by
GitHub
18 changed files with 271 additions and 65 deletions
@ -0,0 +1,6 @@ |
|||
import { IsString } from 'class-validator'; |
|||
|
|||
export class PropertyDto { |
|||
@IsString() |
|||
value: string; |
|||
} |
@ -0,0 +1,11 @@ |
|||
import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; |
|||
import { Module } from '@nestjs/common'; |
|||
|
|||
import { PropertyService } from './property.service'; |
|||
|
|||
@Module({ |
|||
exports: [PropertyService], |
|||
imports: [PrismaModule], |
|||
providers: [PropertyService] |
|||
}) |
|||
export class PropertyModule {} |
@ -0,0 +1,43 @@ |
|||
import { PrismaService } from '@ghostfolio/api/services/prisma.service'; |
|||
import { PROPERTY_CURRENCIES } from '@ghostfolio/common/config'; |
|||
import { Injectable } from '@nestjs/common'; |
|||
|
|||
@Injectable() |
|||
export class PropertyService { |
|||
public constructor(private readonly prismaService: PrismaService) {} |
|||
|
|||
public async get() { |
|||
const response: { |
|||
[key: string]: object | string | string[]; |
|||
} = { |
|||
[PROPERTY_CURRENCIES]: [] |
|||
}; |
|||
|
|||
const properties = await this.prismaService.property.findMany(); |
|||
|
|||
for (const property of properties) { |
|||
let value = property.value; |
|||
|
|||
try { |
|||
value = JSON.parse(property.value); |
|||
} catch {} |
|||
|
|||
response[property.key] = value; |
|||
} |
|||
|
|||
return response; |
|||
} |
|||
|
|||
public async getByKey(aKey: string) { |
|||
const properties = await this.get(); |
|||
return properties?.[aKey]; |
|||
} |
|||
|
|||
public async put({ key, value }: { key: string; value: string }) { |
|||
return this.prismaService.property.upsert({ |
|||
create: { key, value }, |
|||
update: { value }, |
|||
where: { key } |
|||
}); |
|||
} |
|||
} |
Loading…
Reference in new issue