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