Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
♻️ Use prisma code references
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 25, 2020
1 parent 0b3dd4a commit 9ab66df
Show file tree
Hide file tree
Showing 30 changed files with 454 additions and 457 deletions.
8 changes: 4 additions & 4 deletions src/interceptors/audit-log.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import type { Prisma } from '@prisma/client';
import { getClientIp } from 'request-ip';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { UAParser } from 'ua-parser-js';
import { GROUP_NOT_FOUND } from '../errors/errors.constants';
import { STAART_AUDIT_LOG_DATA } from '../modules/audit-logs/audit-log.constants';
import { UserRequest } from '../modules/auth/auth.interface';
import { WebhooksService } from '../modules/webhooks/webhooks.service';
import { GeolocationService } from '../providers/geolocation/geolocation.service';
import { PrismaService } from '../providers/prisma/prisma.service';
import { WebhooksService } from '../modules/webhooks/webhooks.service';
import { UAParser } from 'ua-parser-js';

@Injectable()
export class AuditLogger implements NestInterceptor {
Expand Down Expand Up @@ -48,7 +48,7 @@ export class AuditLogger implements NestInterceptor {
const userAgent = request.get('user-agent');
const ua = new UAParser(userAgent);
for await (const event of auditLog) {
const data: Prisma.auditLogsCreateInput = {
const data: Prisma.AuditLogCreateInput = {
event,
city: location?.city?.names?.en,
region: location?.subdivisions?.pop()?.names?.en,
Expand All @@ -67,7 +67,7 @@ export class AuditLogger implements NestInterceptor {
if (request.user.id && request.user.type === 'user')
data.user = { connect: { id: request.user.id } };
if (groupId) data.group = { connect: { id: groupId } };
await this.prisma.auditLogs.create({ data });
await this.prisma.auditLog.create({ data });
this.webhooksService.triggerWebhook(groupId, event);
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/modules/api-keys/api-keys-group.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
Put,
Query,
} from '@nestjs/common';
import { apiKeys } from '@prisma/client';
import { ApiKey } from '@prisma/client';
import { CursorPipe } from '../../pipes/cursor.pipe';
import { OptionalIntPipe } from '../../pipes/optional-int.pipe';
import { OrderByPipe } from '../../pipes/order-by.pipe';
import { WherePipe } from '../../pipes/where.pipe';
import { Expose } from '../../providers/prisma/prisma.interface';
import { AuditLog } from '../audit-logs/audit-log.decorator';
import { Scopes } from '../auth/scope.decorator';
import { Expose } from '../../providers/prisma/prisma.interface';
import {
CreateApiKeyDto,
ReplaceApiKeyDto,
Expand All @@ -35,7 +35,7 @@ export class ApiKeyGroupController {
async create(
@Param('groupId', ParseIntPipe) groupId: number,
@Body() data: CreateApiKeyDto,
): Promise<Expose<apiKeys>> {
): Promise<Expose<ApiKey>> {
return this.apiKeysService.createApiKeyForGroup(groupId, data);
}

Expand All @@ -48,7 +48,7 @@ export class ApiKeyGroupController {
@Query('cursor', CursorPipe) cursor?: Record<string, number | string>,
@Query('where', WherePipe) where?: Record<string, number | string>,
@Query('orderBy', OrderByPipe) orderBy?: Record<string, 'asc' | 'desc'>,
): Promise<Expose<apiKeys>[]> {
): Promise<Expose<ApiKey>[]> {
return this.apiKeysService.getApiKeysForGroup(groupId, {
skip,
take,
Expand All @@ -71,7 +71,7 @@ export class ApiKeyGroupController {
async get(
@Param('groupId', ParseIntPipe) groupId: number,
@Param('id', ParseIntPipe) id: number,
): Promise<Expose<apiKeys>> {
): Promise<Expose<ApiKey>> {
return this.apiKeysService.getApiKeyForGroup(groupId, Number(id));
}

Expand All @@ -82,7 +82,7 @@ export class ApiKeyGroupController {
@Body() data: UpdateApiKeyDto,
@Param('groupId', ParseIntPipe) groupId: number,
@Param('id', ParseIntPipe) id: number,
): Promise<Expose<apiKeys>> {
): Promise<Expose<ApiKey>> {
return this.apiKeysService.updateApiKeyForGroup(groupId, Number(id), data);
}

Expand All @@ -93,7 +93,7 @@ export class ApiKeyGroupController {
@Body() data: ReplaceApiKeyDto,
@Param('groupId', ParseIntPipe) groupId: number,
@Param('id', ParseIntPipe) id: number,
): Promise<Expose<apiKeys>> {
): Promise<Expose<ApiKey>> {
return this.apiKeysService.updateApiKeyForGroup(groupId, Number(id), data);
}

Expand All @@ -103,7 +103,7 @@ export class ApiKeyGroupController {
async remove(
@Param('groupId', ParseIntPipe) groupId: number,
@Param('id', ParseIntPipe) id: number,
): Promise<Expose<apiKeys>> {
): Promise<Expose<ApiKey>> {
return this.apiKeysService.deleteApiKeyForGroup(groupId, Number(id));
}

Expand Down
16 changes: 8 additions & 8 deletions src/modules/api-keys/api-keys-user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
Put,
Query,
} from '@nestjs/common';
import { apiKeys } from '@prisma/client';
import { ApiKey } from '@prisma/client';
import { CursorPipe } from '../../pipes/cursor.pipe';
import { OptionalIntPipe } from '../../pipes/optional-int.pipe';
import { OrderByPipe } from '../../pipes/order-by.pipe';
import { WherePipe } from '../../pipes/where.pipe';
import { Expose } from '../../providers/prisma/prisma.interface';
import { AuditLog } from '../audit-logs/audit-log.decorator';
import { Scopes } from '../auth/scope.decorator';
import { Expose } from '../../providers/prisma/prisma.interface';
import {
CreateApiKeyDto,
ReplaceApiKeyDto,
Expand All @@ -35,7 +35,7 @@ export class ApiKeyUserController {
async create(
@Param('userId', ParseIntPipe) userId: number,
@Body() data: CreateApiKeyDto,
): Promise<Expose<apiKeys>> {
): Promise<Expose<ApiKey>> {
return this.apiKeysService.createApiKeyForUser(userId, data);
}

Expand All @@ -48,7 +48,7 @@ export class ApiKeyUserController {
@Query('cursor', CursorPipe) cursor?: Record<string, number | string>,
@Query('where', WherePipe) where?: Record<string, number | string>,
@Query('orderBy', OrderByPipe) orderBy?: Record<string, 'asc' | 'desc'>,
): Promise<Expose<apiKeys>[]> {
): Promise<Expose<ApiKey>[]> {
return this.apiKeysService.getApiKeysForUser(userId, {
skip,
take,
Expand All @@ -71,7 +71,7 @@ export class ApiKeyUserController {
async get(
@Param('userId', ParseIntPipe) userId: number,
@Param('id', ParseIntPipe) id: number,
): Promise<Expose<apiKeys>> {
): Promise<Expose<ApiKey>> {
return this.apiKeysService.getApiKeyForUser(userId, Number(id));
}

Expand All @@ -82,7 +82,7 @@ export class ApiKeyUserController {
@Body() data: UpdateApiKeyDto,
@Param('userId', ParseIntPipe) userId: number,
@Param('id', ParseIntPipe) id: number,
): Promise<Expose<apiKeys>> {
): Promise<Expose<ApiKey>> {
return this.apiKeysService.updateApiKeyForUser(userId, Number(id), data);
}

Expand All @@ -93,7 +93,7 @@ export class ApiKeyUserController {
@Body() data: ReplaceApiKeyDto,
@Param('userId', ParseIntPipe) userId: number,
@Param('id', ParseIntPipe) id: number,
): Promise<Expose<apiKeys>> {
): Promise<Expose<ApiKey>> {
return this.apiKeysService.updateApiKeyForUser(userId, Number(id), data);
}

Expand All @@ -103,7 +103,7 @@ export class ApiKeyUserController {
async remove(
@Param('userId', ParseIntPipe) userId: number,
@Param('id', ParseIntPipe) id: number,
): Promise<Expose<apiKeys>> {
): Promise<Expose<ApiKey>> {
return this.apiKeysService.deleteApiKeyForUser(userId, Number(id));
}

Expand Down

0 comments on commit 9ab66df

Please sign in to comment.