Browse Source

fix(api): improve type safety in api key, impersonation, platform, and market data services

pull/8356/head
KenTandrian 4 weeks ago
parent
commit
a75da38596
  1. 6
      apps/api/src/services/api-key/api-key.service.ts
  2. 2
      apps/api/src/services/impersonation/impersonation.service.ts
  3. 4
      apps/api/src/services/market-data/market-data.service.ts
  4. 2
      apps/api/src/services/platform/platform.service.ts

6
apps/api/src/services/api-key/api-key.service.ts

@ -32,12 +32,12 @@ export class ApiKeyService {
public async getUserByApiKey(apiKey: string) {
const hashedKey = this.hashApiKey(apiKey);
const { user } = await this.prismaService.apiKey.findUnique({
const apiKeyEntity = await this.prismaService.apiKey.findUnique({
include: { user: true },
where: { hashedKey }
});
return user;
return apiKeyEntity?.user;
}
public hashApiKey(apiKey: string): string {
@ -53,7 +53,7 @@ export class ApiKeyService {
private generateApiKey(): string {
return getRandomString(32)
.split('')
.reduce((acc, char, index) => {
.reduce<string[]>((acc, char, index) => {
const chunkIndex = Math.floor(index / 4);
acc[chunkIndex] = (acc[chunkIndex] || '') + char;
return acc;

2
apps/api/src/services/impersonation/impersonation.service.ts

@ -50,7 +50,7 @@ export class ImpersonationService {
authenticatedUserSubscription: user?.subscription,
isActive: false,
scopes: getScopesOfOwnAccess(),
userId: user?.id,
userId: user?.id as string,
userSettings: user?.settings?.settings ?? {},
userSubscription: user?.subscription
};

4
apps/api/src/services/market-data/market-data.service.ts

@ -30,7 +30,7 @@ export class MarketDataService {
dataSource,
date = new Date(),
symbol
}: DataGatheringItem): Promise<MarketData> {
}: DataGatheringItem): Promise<MarketData | null> {
return await this.prismaService.marketData.findFirst({
where: {
dataSource,
@ -43,7 +43,7 @@ export class MarketDataService {
public async getLatest({
dataSource,
symbol
}: AssetProfileIdentifier): Promise<MarketData> {
}: AssetProfileIdentifier): Promise<MarketData | null> {
return this.prismaService.marketData.findFirst({
orderBy: [{ date: 'desc' }],
where: {

2
apps/api/src/services/platform/platform.service.ts

@ -21,7 +21,7 @@ export class PlatformService {
public async getPlatform(
platformWhereUniqueInput: Prisma.PlatformWhereUniqueInput
): Promise<Platform> {
): Promise<Platform | null> {
return this.prismaService.platform.findUnique({
where: platformWhereUniqueInput
});

Loading…
Cancel
Save