Harmonize prisma service (#266)
This commit is contained in:
parent
e68aa1fa68
commit
3589e72aea
@ -5,7 +5,7 @@ import { Prisma } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class AccessService {
|
||||
public constructor(private prisma: PrismaService) {}
|
||||
public constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
public async accesses(params: {
|
||||
include?: Prisma.AccessInclude;
|
||||
@ -17,7 +17,7 @@ export class AccessService {
|
||||
}): Promise<AccessWithGranteeUser[]> {
|
||||
const { include, skip, take, cursor, where, orderBy } = params;
|
||||
|
||||
return this.prisma.access.findMany({
|
||||
return this.prismaService.access.findMany({
|
||||
cursor,
|
||||
include,
|
||||
orderBy,
|
||||
|
@ -3,21 +3,19 @@ import { PrismaService } from '@ghostfolio/api/services/prisma.service';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Account, Currency, Order, Prisma } from '@prisma/client';
|
||||
|
||||
import { RedisCacheService } from '../redis-cache/redis-cache.service';
|
||||
import { CashDetails } from './interfaces/cash-details.interface';
|
||||
|
||||
@Injectable()
|
||||
export class AccountService {
|
||||
public constructor(
|
||||
private exchangeRateDataService: ExchangeRateDataService,
|
||||
private readonly redisCacheService: RedisCacheService,
|
||||
private prisma: PrismaService
|
||||
private readonly exchangeRateDataService: ExchangeRateDataService,
|
||||
private readonly prismaService: PrismaService
|
||||
) {}
|
||||
|
||||
public async account(
|
||||
accountWhereUniqueInput: Prisma.AccountWhereUniqueInput
|
||||
): Promise<Account | null> {
|
||||
return this.prisma.account.findUnique({
|
||||
return this.prismaService.account.findUnique({
|
||||
where: accountWhereUniqueInput
|
||||
});
|
||||
}
|
||||
@ -30,7 +28,7 @@ export class AccountService {
|
||||
Order?: Order[];
|
||||
}
|
||||
> {
|
||||
return this.prisma.account.findUnique({
|
||||
return this.prismaService.account.findUnique({
|
||||
include: accountInclude,
|
||||
where: accountWhereUniqueInput
|
||||
});
|
||||
@ -46,7 +44,7 @@ export class AccountService {
|
||||
}): Promise<Account[]> {
|
||||
const { include, skip, take, cursor, where, orderBy } = params;
|
||||
|
||||
return this.prisma.account.findMany({
|
||||
return this.prismaService.account.findMany({
|
||||
cursor,
|
||||
include,
|
||||
orderBy,
|
||||
@ -60,7 +58,7 @@ export class AccountService {
|
||||
data: Prisma.AccountCreateInput,
|
||||
aUserId: string
|
||||
): Promise<Account> {
|
||||
return this.prisma.account.create({
|
||||
return this.prismaService.account.create({
|
||||
data
|
||||
});
|
||||
}
|
||||
@ -69,7 +67,7 @@ export class AccountService {
|
||||
where: Prisma.AccountWhereUniqueInput,
|
||||
aUserId: string
|
||||
): Promise<Account> {
|
||||
return this.prisma.account.delete({
|
||||
return this.prismaService.account.delete({
|
||||
where
|
||||
});
|
||||
}
|
||||
@ -103,7 +101,7 @@ export class AccountService {
|
||||
aUserId: string
|
||||
): Promise<Account> {
|
||||
const { data, where } = params;
|
||||
return this.prisma.account.update({
|
||||
return this.prismaService.account.update({
|
||||
data,
|
||||
where
|
||||
});
|
||||
|
@ -7,8 +7,8 @@ import { Currency } from '@prisma/client';
|
||||
@Injectable()
|
||||
export class AdminService {
|
||||
public constructor(
|
||||
private exchangeRateDataService: ExchangeRateDataService,
|
||||
private prisma: PrismaService
|
||||
private readonly exchangeRateDataService: ExchangeRateDataService,
|
||||
private readonly prismaService: PrismaService
|
||||
) {}
|
||||
|
||||
public async get(): Promise<AdminData> {
|
||||
@ -61,14 +61,14 @@ export class AdminService {
|
||||
}
|
||||
],
|
||||
lastDataGathering: await this.getLastDataGathering(),
|
||||
transactionCount: await this.prisma.order.count(),
|
||||
userCount: await this.prisma.user.count(),
|
||||
transactionCount: await this.prismaService.order.count(),
|
||||
userCount: await this.prismaService.user.count(),
|
||||
users: await this.getUsersWithAnalytics()
|
||||
};
|
||||
}
|
||||
|
||||
private async getLastDataGathering() {
|
||||
const lastDataGathering = await this.prisma.property.findUnique({
|
||||
const lastDataGathering = await this.prismaService.property.findUnique({
|
||||
where: { key: 'LAST_DATA_GATHERING' }
|
||||
});
|
||||
|
||||
@ -76,9 +76,10 @@ export class AdminService {
|
||||
return new Date(lastDataGathering.value);
|
||||
}
|
||||
|
||||
const dataGatheringInProgress = await this.prisma.property.findUnique({
|
||||
where: { key: 'LOCKED_DATA_GATHERING' }
|
||||
});
|
||||
const dataGatheringInProgress =
|
||||
await this.prismaService.property.findUnique({
|
||||
where: { key: 'LOCKED_DATA_GATHERING' }
|
||||
});
|
||||
|
||||
if (dataGatheringInProgress) {
|
||||
return 'IN_PROGRESS';
|
||||
@ -88,7 +89,7 @@ export class AdminService {
|
||||
}
|
||||
|
||||
private async getUsersWithAnalytics() {
|
||||
return await this.prisma.user.findMany({
|
||||
return await this.prismaService.user.findMany({
|
||||
orderBy: {
|
||||
Analytics: {
|
||||
updatedAt: 'desc'
|
||||
|
@ -6,7 +6,7 @@ import { RedisCacheService } from './redis-cache/redis-cache.service';
|
||||
@Controller()
|
||||
export class AppController {
|
||||
public constructor(
|
||||
private prisma: PrismaService,
|
||||
private readonly prismaService: PrismaService,
|
||||
private readonly redisCacheService: RedisCacheService
|
||||
) {
|
||||
this.initialize();
|
||||
@ -15,13 +15,13 @@ export class AppController {
|
||||
private async initialize() {
|
||||
this.redisCacheService.reset();
|
||||
|
||||
const isDataGatheringLocked = await this.prisma.property.findUnique({
|
||||
const isDataGatheringLocked = await this.prismaService.property.findUnique({
|
||||
where: { key: 'LOCKED_DATA_GATHERING' }
|
||||
});
|
||||
|
||||
if (!isDataGatheringLocked) {
|
||||
// Prepare for automatical data gather if not locked
|
||||
await this.prisma.property.deleteMany({
|
||||
await this.prismaService.property.deleteMany({
|
||||
where: {
|
||||
OR: [{ key: 'LAST_DATA_GATHERING' }, { key: 'LOCKED_DATA_GATHERING' }]
|
||||
}
|
||||
|
@ -7,13 +7,13 @@ import { AuthDevice, Prisma } from '@prisma/client';
|
||||
export class AuthDeviceService {
|
||||
public constructor(
|
||||
private readonly configurationService: ConfigurationService,
|
||||
private prisma: PrismaService
|
||||
private readonly prismaService: PrismaService
|
||||
) {}
|
||||
|
||||
public async authDevice(
|
||||
where: Prisma.AuthDeviceWhereUniqueInput
|
||||
): Promise<AuthDevice | null> {
|
||||
return this.prisma.authDevice.findUnique({
|
||||
return this.prismaService.authDevice.findUnique({
|
||||
where
|
||||
});
|
||||
}
|
||||
@ -26,7 +26,7 @@ export class AuthDeviceService {
|
||||
orderBy?: Prisma.AuthDeviceOrderByInput;
|
||||
}): Promise<AuthDevice[]> {
|
||||
const { skip, take, cursor, where, orderBy } = params;
|
||||
return this.prisma.authDevice.findMany({
|
||||
return this.prismaService.authDevice.findMany({
|
||||
skip,
|
||||
take,
|
||||
cursor,
|
||||
@ -38,7 +38,7 @@ export class AuthDeviceService {
|
||||
public async createAuthDevice(
|
||||
data: Prisma.AuthDeviceCreateInput
|
||||
): Promise<AuthDevice> {
|
||||
return this.prisma.authDevice.create({
|
||||
return this.prismaService.authDevice.create({
|
||||
data
|
||||
});
|
||||
}
|
||||
@ -49,7 +49,7 @@ export class AuthDeviceService {
|
||||
}): Promise<AuthDevice> {
|
||||
const { data, where } = params;
|
||||
|
||||
return this.prisma.authDevice.update({
|
||||
return this.prismaService.authDevice.update({
|
||||
data,
|
||||
where
|
||||
});
|
||||
@ -58,7 +58,7 @@ export class AuthDeviceService {
|
||||
public async deleteAuthDevice(
|
||||
where: Prisma.AuthDeviceWhereUniqueInput
|
||||
): Promise<AuthDevice> {
|
||||
return this.prisma.authDevice.delete({
|
||||
return this.prismaService.authDevice.delete({
|
||||
where
|
||||
});
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import { UserService } from '../user/user.service';
|
||||
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
||||
public constructor(
|
||||
readonly configurationService: ConfigurationService,
|
||||
private prisma: PrismaService,
|
||||
private readonly prismaService: PrismaService,
|
||||
private readonly userService: UserService
|
||||
) {
|
||||
super({
|
||||
@ -24,7 +24,7 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
||||
const user = await this.userService.user({ id });
|
||||
|
||||
if (user) {
|
||||
await this.prisma.analytics.upsert({
|
||||
await this.prismaService.analytics.upsert({
|
||||
create: { User: { connect: { id: user.id } } },
|
||||
update: { activityCount: { increment: 1 }, updatedAt: new Date() },
|
||||
where: { userId: user.id }
|
||||
|
4
apps/api/src/app/cache/cache.service.ts
vendored
4
apps/api/src/app/cache/cache.service.ts
vendored
@ -3,10 +3,10 @@ import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class CacheService {
|
||||
public constructor(private prisma: PrismaService) {}
|
||||
public constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
public async flush(): Promise<void> {
|
||||
await this.prisma.property.deleteMany({
|
||||
await this.prismaService.property.deleteMany({
|
||||
where: {
|
||||
OR: [{ key: 'LAST_DATA_GATHERING' }, { key: 'LOCKED_DATA_GATHERING' }]
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import { DateQuery } from './interfaces/date-query.interface';
|
||||
|
||||
@Injectable()
|
||||
export class MarketDataService {
|
||||
public constructor(private prisma: PrismaService) {}
|
||||
public constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
public async get({
|
||||
date,
|
||||
@ -16,7 +16,7 @@ export class MarketDataService {
|
||||
date: Date;
|
||||
symbol: string;
|
||||
}): Promise<MarketData> {
|
||||
return await this.prisma.marketData.findFirst({
|
||||
return await this.prismaService.marketData.findFirst({
|
||||
where: {
|
||||
symbol,
|
||||
date: resetHours(date)
|
||||
@ -31,7 +31,7 @@ export class MarketDataService {
|
||||
dateQuery: DateQuery;
|
||||
symbols: string[];
|
||||
}): Promise<MarketData[]> {
|
||||
return await this.prisma.marketData.findMany({
|
||||
return await this.prismaService.marketData.findMany({
|
||||
orderBy: [
|
||||
{
|
||||
date: 'asc'
|
||||
|
@ -11,12 +11,12 @@ export class ExperimentalService {
|
||||
private readonly accountService: AccountService,
|
||||
private readonly dataProviderService: DataProviderService,
|
||||
private readonly exchangeRateDataService: ExchangeRateDataService,
|
||||
private prisma: PrismaService,
|
||||
private readonly prismaService: PrismaService,
|
||||
private readonly rulesService: RulesService
|
||||
) {}
|
||||
|
||||
public async getBenchmark(aSymbol: string) {
|
||||
return this.prisma.marketData.findMany({
|
||||
return this.prismaService.marketData.findMany({
|
||||
orderBy: { date: 'asc' },
|
||||
select: { date: true, marketPrice: true },
|
||||
where: { symbol: aSymbol }
|
||||
|
@ -5,10 +5,10 @@ import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class ExportService {
|
||||
public constructor(private prisma: PrismaService) {}
|
||||
public constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
public async export({ userId }: { userId: string }): Promise<Export> {
|
||||
const orders = await this.prisma.order.findMany({
|
||||
const orders = await this.prismaService.order.findMany({
|
||||
orderBy: { date: 'desc' },
|
||||
select: {
|
||||
currency: true,
|
||||
|
@ -15,13 +15,13 @@ export class InfoService {
|
||||
|
||||
public constructor(
|
||||
private readonly configurationService: ConfigurationService,
|
||||
private jwtService: JwtService,
|
||||
private prisma: PrismaService
|
||||
private readonly jwtService: JwtService,
|
||||
private readonly prismaService: PrismaService
|
||||
) {}
|
||||
|
||||
public async get(): Promise<InfoItem> {
|
||||
const info: Partial<InfoItem> = {};
|
||||
const platforms = await this.prisma.platform.findMany({
|
||||
const platforms = await this.prismaService.platform.findMany({
|
||||
orderBy: { name: 'asc' },
|
||||
select: { id: true, name: true }
|
||||
});
|
||||
@ -63,7 +63,7 @@ export class InfoService {
|
||||
}
|
||||
|
||||
private async countActiveUsers(aDays: number) {
|
||||
return await this.prisma.user.count({
|
||||
return await this.prismaService.user.count({
|
||||
orderBy: {
|
||||
Analytics: {
|
||||
updatedAt: 'desc'
|
||||
@ -116,7 +116,7 @@ export class InfoService {
|
||||
}
|
||||
|
||||
private async getLastDataGathering() {
|
||||
const lastDataGathering = await this.prisma.property.findUnique({
|
||||
const lastDataGathering = await this.prismaService.property.findUnique({
|
||||
where: { key: 'LAST_DATA_GATHERING' }
|
||||
});
|
||||
|
||||
@ -144,7 +144,7 @@ export class InfoService {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const stripeConfig = await this.prisma.property.findUnique({
|
||||
const stripeConfig = await this.prismaService.property.findUnique({
|
||||
where: { key: 'STRIPE_CONFIG' }
|
||||
});
|
||||
|
||||
|
@ -12,13 +12,13 @@ export class OrderService {
|
||||
public constructor(
|
||||
private readonly cacheService: CacheService,
|
||||
private readonly dataGatheringService: DataGatheringService,
|
||||
private prisma: PrismaService
|
||||
private readonly prismaService: PrismaService
|
||||
) {}
|
||||
|
||||
public async order(
|
||||
orderWhereUniqueInput: Prisma.OrderWhereUniqueInput
|
||||
): Promise<Order | null> {
|
||||
return this.prisma.order.findUnique({
|
||||
return this.prismaService.order.findUnique({
|
||||
where: orderWhereUniqueInput
|
||||
});
|
||||
}
|
||||
@ -33,7 +33,7 @@ export class OrderService {
|
||||
}): Promise<OrderWithAccount[]> {
|
||||
const { include, skip, take, cursor, where, orderBy } = params;
|
||||
|
||||
return this.prisma.order.findMany({
|
||||
return this.prismaService.order.findMany({
|
||||
cursor,
|
||||
include,
|
||||
orderBy,
|
||||
@ -61,7 +61,7 @@ export class OrderService {
|
||||
|
||||
await this.cacheService.flush();
|
||||
|
||||
return this.prisma.order.create({
|
||||
return this.prismaService.order.create({
|
||||
data: {
|
||||
...data,
|
||||
isDraft
|
||||
@ -72,7 +72,7 @@ export class OrderService {
|
||||
public async deleteOrder(
|
||||
where: Prisma.OrderWhereUniqueInput
|
||||
): Promise<Order> {
|
||||
return this.prisma.order.delete({
|
||||
return this.prismaService.order.delete({
|
||||
where
|
||||
});
|
||||
}
|
||||
@ -123,7 +123,7 @@ export class OrderService {
|
||||
|
||||
await this.cacheService.flush();
|
||||
|
||||
return this.prisma.order.update({
|
||||
return this.prismaService.order.update({
|
||||
data: {
|
||||
...data,
|
||||
isDraft
|
||||
|
@ -10,7 +10,7 @@ export class SubscriptionService {
|
||||
|
||||
public constructor(
|
||||
private readonly configurationService: ConfigurationService,
|
||||
private prisma: PrismaService
|
||||
private readonly prismaService: PrismaService
|
||||
) {
|
||||
this.stripe = new Stripe(
|
||||
this.configurationService.get('STRIPE_SECRET_KEY'),
|
||||
@ -68,7 +68,7 @@ export class SubscriptionService {
|
||||
aCheckoutSessionId
|
||||
);
|
||||
|
||||
await this.prisma.subscription.create({
|
||||
await this.prismaService.subscription.create({
|
||||
data: {
|
||||
expiresAt: addDays(new Date(), 365),
|
||||
User: {
|
||||
|
@ -18,7 +18,7 @@ export class UserService {
|
||||
|
||||
public constructor(
|
||||
private readonly configurationService: ConfigurationService,
|
||||
private prisma: PrismaService
|
||||
private readonly prismaService: PrismaService
|
||||
) {}
|
||||
|
||||
public async getUser({
|
||||
@ -29,7 +29,7 @@ export class UserService {
|
||||
Settings,
|
||||
subscription
|
||||
}: UserWithSettings): Promise<IUser> {
|
||||
const access = await this.prisma.access.findMany({
|
||||
const access = await this.prismaService.access.findMany({
|
||||
include: {
|
||||
User: true
|
||||
},
|
||||
@ -60,7 +60,7 @@ export class UserService {
|
||||
public async user(
|
||||
userWhereUniqueInput: Prisma.UserWhereUniqueInput
|
||||
): Promise<UserWithSettings | null> {
|
||||
const userFromDatabase = await this.prisma.user.findUnique({
|
||||
const userFromDatabase = await this.prismaService.user.findUnique({
|
||||
include: { Account: true, Settings: true, Subscription: true },
|
||||
where: userWhereUniqueInput
|
||||
});
|
||||
@ -129,7 +129,7 @@ export class UserService {
|
||||
orderBy?: Prisma.UserOrderByInput;
|
||||
}): Promise<User[]> {
|
||||
const { skip, take, cursor, where, orderBy } = params;
|
||||
return this.prisma.user.findMany({
|
||||
return this.prismaService.user.findMany({
|
||||
skip,
|
||||
take,
|
||||
cursor,
|
||||
@ -146,7 +146,7 @@ export class UserService {
|
||||
}
|
||||
|
||||
public async createUser(data?: Prisma.UserCreateInput): Promise<User> {
|
||||
let user = await this.prisma.user.create({
|
||||
let user = await this.prismaService.user.create({
|
||||
data: {
|
||||
...data,
|
||||
Account: {
|
||||
@ -169,7 +169,7 @@ export class UserService {
|
||||
process.env.ACCESS_TOKEN_SALT
|
||||
);
|
||||
|
||||
user = await this.prisma.user.update({
|
||||
user = await this.prismaService.user.update({
|
||||
data: { accessToken: hashedAccessToken },
|
||||
where: { id: user.id }
|
||||
});
|
||||
@ -185,36 +185,36 @@ export class UserService {
|
||||
data: Prisma.UserUpdateInput;
|
||||
}): Promise<User> {
|
||||
const { where, data } = params;
|
||||
return this.prisma.user.update({
|
||||
return this.prismaService.user.update({
|
||||
data,
|
||||
where
|
||||
});
|
||||
}
|
||||
|
||||
public async deleteUser(where: Prisma.UserWhereUniqueInput): Promise<User> {
|
||||
await this.prisma.access.deleteMany({
|
||||
await this.prismaService.access.deleteMany({
|
||||
where: { OR: [{ granteeUserId: where.id }, { userId: where.id }] }
|
||||
});
|
||||
|
||||
await this.prisma.account.deleteMany({
|
||||
await this.prismaService.account.deleteMany({
|
||||
where: { userId: where.id }
|
||||
});
|
||||
|
||||
await this.prisma.analytics.delete({
|
||||
await this.prismaService.analytics.delete({
|
||||
where: { userId: where.id }
|
||||
});
|
||||
|
||||
await this.prisma.order.deleteMany({
|
||||
await this.prismaService.order.deleteMany({
|
||||
where: { userId: where.id }
|
||||
});
|
||||
|
||||
try {
|
||||
await this.prisma.settings.delete({
|
||||
await this.prismaService.settings.delete({
|
||||
where: { userId: where.id }
|
||||
});
|
||||
} catch {}
|
||||
|
||||
return this.prisma.user.delete({
|
||||
return this.prismaService.user.delete({
|
||||
where
|
||||
});
|
||||
}
|
||||
@ -224,7 +224,7 @@ export class UserService {
|
||||
userId,
|
||||
viewMode
|
||||
}: UserSettingsParams) {
|
||||
await this.prisma.settings.upsert({
|
||||
await this.prismaService.settings.upsert({
|
||||
create: {
|
||||
currency,
|
||||
User: {
|
||||
|
@ -30,7 +30,7 @@ export class DataGatheringService {
|
||||
private readonly configurationService: ConfigurationService,
|
||||
private readonly dataProviderService: DataProviderService,
|
||||
private readonly ghostfolioScraperApi: GhostfolioScraperApiService,
|
||||
private prisma: PrismaService
|
||||
private readonly prismaService: PrismaService
|
||||
) {}
|
||||
|
||||
public async gather7Days() {
|
||||
@ -40,7 +40,7 @@ export class DataGatheringService {
|
||||
console.log('7d data gathering has been started.');
|
||||
console.time('7d-data-gathering');
|
||||
|
||||
await this.prisma.property.create({
|
||||
await this.prismaService.property.create({
|
||||
data: {
|
||||
key: 'LOCKED_DATA_GATHERING',
|
||||
value: new Date().toISOString()
|
||||
@ -52,7 +52,7 @@ export class DataGatheringService {
|
||||
try {
|
||||
await this.gatherSymbols(symbols);
|
||||
|
||||
await this.prisma.property.upsert({
|
||||
await this.prismaService.property.upsert({
|
||||
create: {
|
||||
key: 'LAST_DATA_GATHERING',
|
||||
value: new Date().toISOString()
|
||||
@ -64,7 +64,7 @@ export class DataGatheringService {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
await this.prisma.property.delete({
|
||||
await this.prismaService.property.delete({
|
||||
where: {
|
||||
key: 'LOCKED_DATA_GATHERING'
|
||||
}
|
||||
@ -76,7 +76,7 @@ export class DataGatheringService {
|
||||
}
|
||||
|
||||
public async gatherMax() {
|
||||
const isDataGatheringLocked = await this.prisma.property.findUnique({
|
||||
const isDataGatheringLocked = await this.prismaService.property.findUnique({
|
||||
where: { key: 'LOCKED_DATA_GATHERING' }
|
||||
});
|
||||
|
||||
@ -84,7 +84,7 @@ export class DataGatheringService {
|
||||
console.log('Max data gathering has been started.');
|
||||
console.time('max-data-gathering');
|
||||
|
||||
await this.prisma.property.create({
|
||||
await this.prismaService.property.create({
|
||||
data: {
|
||||
key: 'LOCKED_DATA_GATHERING',
|
||||
value: new Date().toISOString()
|
||||
@ -96,7 +96,7 @@ export class DataGatheringService {
|
||||
try {
|
||||
await this.gatherSymbols(symbols);
|
||||
|
||||
await this.prisma.property.upsert({
|
||||
await this.prismaService.property.upsert({
|
||||
create: {
|
||||
key: 'LAST_DATA_GATHERING',
|
||||
value: new Date().toISOString()
|
||||
@ -108,7 +108,7 @@ export class DataGatheringService {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
await this.prisma.property.delete({
|
||||
await this.prismaService.property.delete({
|
||||
where: {
|
||||
key: 'LOCKED_DATA_GATHERING'
|
||||
}
|
||||
@ -138,7 +138,7 @@ export class DataGatheringService {
|
||||
currentData
|
||||
)) {
|
||||
try {
|
||||
await this.prisma.symbolProfile.upsert({
|
||||
await this.prismaService.symbolProfile.upsert({
|
||||
create: {
|
||||
currency,
|
||||
dataSource,
|
||||
@ -202,7 +202,7 @@ export class DataGatheringService {
|
||||
}
|
||||
|
||||
try {
|
||||
await this.prisma.marketData.create({
|
||||
await this.prismaService.marketData.create({
|
||||
data: {
|
||||
symbol,
|
||||
date: currentDate,
|
||||
@ -270,7 +270,7 @@ export class DataGatheringService {
|
||||
private async getSymbols7D(): Promise<IDataGatheringItem[]> {
|
||||
const startDate = subDays(resetHours(new Date()), 7);
|
||||
|
||||
const distinctOrders = await this.prisma.order.findMany({
|
||||
const distinctOrders = await this.prismaService.order.findMany({
|
||||
distinct: ['symbol'],
|
||||
orderBy: [{ symbol: 'asc' }],
|
||||
select: { dataSource: true, symbol: true },
|
||||
@ -331,7 +331,7 @@ export class DataGatheringService {
|
||||
}
|
||||
);
|
||||
|
||||
const distinctOrders = await this.prisma.order.findMany({
|
||||
const distinctOrders = await this.prismaService.order.findMany({
|
||||
distinct: ['symbol'],
|
||||
orderBy: [{ date: 'asc' }],
|
||||
select: { dataSource: true, date: true, symbol: true },
|
||||
@ -353,7 +353,7 @@ export class DataGatheringService {
|
||||
private async getSymbolsProfileData(): Promise<IDataGatheringItem[]> {
|
||||
const startDate = subDays(resetHours(new Date()), 7);
|
||||
|
||||
const distinctOrders = await this.prisma.order.findMany({
|
||||
const distinctOrders = await this.prismaService.order.findMany({
|
||||
distinct: ['symbol'],
|
||||
orderBy: [{ symbol: 'asc' }],
|
||||
select: { dataSource: true, symbol: true }
|
||||
@ -370,11 +370,11 @@ export class DataGatheringService {
|
||||
}
|
||||
|
||||
private async isDataGatheringNeeded() {
|
||||
const lastDataGathering = await this.prisma.property.findUnique({
|
||||
const lastDataGathering = await this.prismaService.property.findUnique({
|
||||
where: { key: 'LAST_DATA_GATHERING' }
|
||||
});
|
||||
|
||||
const isDataGatheringLocked = await this.prisma.property.findUnique({
|
||||
const isDataGatheringLocked = await this.prismaService.property.findUnique({
|
||||
where: { key: 'LOCKED_DATA_GATHERING' }
|
||||
});
|
||||
|
||||
|
@ -26,11 +26,11 @@ export class DataProviderService {
|
||||
private readonly alphaVantageService: AlphaVantageService,
|
||||
private readonly configurationService: ConfigurationService,
|
||||
private readonly ghostfolioScraperApiService: GhostfolioScraperApiService,
|
||||
private prisma: PrismaService,
|
||||
private readonly prismaService: PrismaService,
|
||||
private readonly rakutenRapidApiService: RakutenRapidApiService,
|
||||
private readonly yahooFinanceService: YahooFinanceService
|
||||
) {
|
||||
this.rakutenRapidApiService?.setPrisma(this.prisma);
|
||||
this.rakutenRapidApiService?.setPrisma(this.prismaService);
|
||||
}
|
||||
|
||||
public async get(
|
||||
@ -112,9 +112,8 @@ export class DataProviderService {
|
||||
`','`
|
||||
)}') ${granularityQuery} ${rangeQuery} ORDER BY date;`;
|
||||
|
||||
const marketDataByGranularity: MarketData[] = await this.prisma.$queryRaw(
|
||||
queryRaw
|
||||
);
|
||||
const marketDataByGranularity: MarketData[] =
|
||||
await this.prismaService.$queryRaw(queryRaw);
|
||||
|
||||
response = marketDataByGranularity.reduce((r, marketData) => {
|
||||
const { date, marketPrice, symbol } = marketData;
|
||||
|
@ -23,7 +23,7 @@ import { ScraperConfig } from './interfaces/scraper-config.interface';
|
||||
export class GhostfolioScraperApiService implements DataProviderInterface {
|
||||
private static NUMERIC_REGEXP = /[-]{0,1}[\d]*[.,]{0,1}[\d]+/g;
|
||||
|
||||
public constructor(private prisma: PrismaService) {}
|
||||
public constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
public canHandle(symbol: string) {
|
||||
return isGhostfolioScraperApiSymbol(symbol);
|
||||
@ -41,7 +41,7 @@ export class GhostfolioScraperApiService implements DataProviderInterface {
|
||||
|
||||
const scraperConfig = await this.getScraperConfigurationBySymbol(symbol);
|
||||
|
||||
const { marketPrice } = await this.prisma.marketData.findFirst({
|
||||
const { marketPrice } = await this.prismaService.marketData.findFirst({
|
||||
orderBy: {
|
||||
date: 'desc'
|
||||
},
|
||||
@ -111,7 +111,7 @@ export class GhostfolioScraperApiService implements DataProviderInterface {
|
||||
public async getScraperConfigurations(): Promise<ScraperConfig[]> {
|
||||
try {
|
||||
const { value: scraperConfigString } =
|
||||
await this.prisma.property.findFirst({
|
||||
await this.prismaService.property.findFirst({
|
||||
select: {
|
||||
value: true
|
||||
},
|
||||
|
@ -23,7 +23,7 @@ import { PrismaService } from '../../prisma.service';
|
||||
export class RakutenRapidApiService implements DataProviderInterface {
|
||||
public static FEAR_AND_GREED_INDEX_NAME = 'Fear & Greed Index';
|
||||
|
||||
private prisma: PrismaService;
|
||||
private prismaService: PrismaService;
|
||||
|
||||
public constructor(
|
||||
private readonly configurationService: ConfigurationService
|
||||
@ -89,7 +89,7 @@ export class RakutenRapidApiService implements DataProviderInterface {
|
||||
// TODO: can be removed after all data from the last year has been gathered
|
||||
// (introduced on 27.03.2021)
|
||||
|
||||
await this.prisma.marketData.create({
|
||||
await this.prismaService.marketData.create({
|
||||
data: {
|
||||
symbol,
|
||||
date: subWeeks(getToday(), 1),
|
||||
@ -97,7 +97,7 @@ export class RakutenRapidApiService implements DataProviderInterface {
|
||||
}
|
||||
});
|
||||
|
||||
await this.prisma.marketData.create({
|
||||
await this.prismaService.marketData.create({
|
||||
data: {
|
||||
symbol,
|
||||
date: subMonths(getToday(), 1),
|
||||
@ -105,7 +105,7 @@ export class RakutenRapidApiService implements DataProviderInterface {
|
||||
}
|
||||
});
|
||||
|
||||
await this.prisma.marketData.create({
|
||||
await this.prismaService.marketData.create({
|
||||
data: {
|
||||
symbol,
|
||||
date: subYears(getToday(), 1),
|
||||
@ -134,7 +134,7 @@ export class RakutenRapidApiService implements DataProviderInterface {
|
||||
}
|
||||
|
||||
public setPrisma(aPrismaService: PrismaService) {
|
||||
this.prisma = aPrismaService;
|
||||
this.prismaService = aPrismaService;
|
||||
}
|
||||
|
||||
private async getFearAndGreedIndex(): Promise<{
|
||||
|
@ -4,10 +4,10 @@ import { PrismaService } from './prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class ImpersonationService {
|
||||
public constructor(private prisma: PrismaService) {}
|
||||
public constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
public async validateImpersonationId(aId = '', aUserId: string) {
|
||||
const accessObject = await this.prisma.access.findFirst({
|
||||
const accessObject = await this.prismaService.access.findFirst({
|
||||
where: { GranteeUser: { id: aUserId }, id: aId }
|
||||
});
|
||||
|
||||
|
@ -9,12 +9,12 @@ import { continents, countries } from 'countries-list';
|
||||
|
||||
@Injectable()
|
||||
export class SymbolProfileService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
public async getSymbolProfiles(
|
||||
symbols: string[]
|
||||
): Promise<EnhancedSymbolProfile[]> {
|
||||
return this.prisma.symbolProfile
|
||||
return this.prismaService.symbolProfile
|
||||
.findMany({
|
||||
where: {
|
||||
symbol: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user