mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 17:10:56 +00:00
chore: fmt
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
||||
import { createParamDecorator, ExecutionContext } from "@nestjs/common";
|
||||
|
||||
// TODO: integrate @edr/auth — this decorator currently returns whatever was
|
||||
// attached to request.user by the (not-yet-wired) auth middleware. Once the
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
import { SetMetadata } from "@nestjs/common";
|
||||
|
||||
export const IS_PUBLIC_KEY = 'isPublic';
|
||||
export const IS_PUBLIC_KEY = "isPublic";
|
||||
|
||||
// TODO: integrate @edr/auth — pair with the JwtAuthGuard from the auth package
|
||||
// so it skips authentication for routes marked @Public(). Until then, this is
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
import { SetMetadata } from "@nestjs/common";
|
||||
|
||||
export const ROLES_KEY = 'roles';
|
||||
export const ROLES_KEY = "roles";
|
||||
|
||||
// TODO: integrate @edr/auth — pair this metadata with a RolesGuard from the
|
||||
// auth package. Until then, this decorator only sets metadata and has no
|
||||
|
||||
@@ -3,18 +3,18 @@ import {
|
||||
DeleteDateColumn,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
} from "typeorm";
|
||||
|
||||
export abstract class BaseEntity {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id!: string;
|
||||
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
|
||||
@CreateDateColumn({ name: "created_at", type: "timestamptz" })
|
||||
createdAt!: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
|
||||
@UpdateDateColumn({ name: "updated_at", type: "timestamptz" })
|
||||
updatedAt!: Date;
|
||||
|
||||
@DeleteDateColumn({ name: 'deleted_at', type: 'timestamptz', nullable: true })
|
||||
@DeleteDateColumn({ name: "deleted_at", type: "timestamptz", nullable: true })
|
||||
deletedAt?: Date | null;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Logger,
|
||||
} from '@nestjs/common';
|
||||
} from "@nestjs/common";
|
||||
|
||||
interface ErrorResponseBody {
|
||||
success: false;
|
||||
@@ -31,26 +31,33 @@ export class HttpExceptionFilter implements ExceptionFilter {
|
||||
: HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
|
||||
const messageRaw =
|
||||
exception instanceof HttpException ? exception.getResponse() : 'Internal server error';
|
||||
exception instanceof HttpException
|
||||
? exception.getResponse()
|
||||
: "Internal server error";
|
||||
|
||||
const message =
|
||||
typeof messageRaw === 'string'
|
||||
typeof messageRaw === "string"
|
||||
? messageRaw
|
||||
: (messageRaw as { message?: string }).message ?? 'Unexpected error';
|
||||
: ((messageRaw as { message?: string }).message ?? "Unexpected error");
|
||||
|
||||
const body: ErrorResponseBody = {
|
||||
success: false,
|
||||
statusCode: status,
|
||||
message,
|
||||
error: exception instanceof Error ? exception.name : 'Error',
|
||||
error: exception instanceof Error ? exception.name : "Error",
|
||||
timestamp: new Date().toISOString(),
|
||||
path: request.url,
|
||||
};
|
||||
|
||||
if (status >= 500) {
|
||||
this.logger.error(`${request.method} ${request.url} -> ${status}`, (exception as Error)?.stack);
|
||||
this.logger.error(
|
||||
`${request.method} ${request.url} -> ${status}`,
|
||||
(exception as Error)?.stack,
|
||||
);
|
||||
} else {
|
||||
this.logger.warn(`${request.method} ${request.url} -> ${status} ${message}`);
|
||||
this.logger.warn(
|
||||
`${request.method} ${request.url} -> ${status} ${message}`,
|
||||
);
|
||||
}
|
||||
|
||||
response.status(status).json(body);
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
// Decorators
|
||||
export * from './decorators/current-user.decorator';
|
||||
export * from './decorators/roles.decorator';
|
||||
export * from './decorators/public.decorator';
|
||||
export * from "./decorators/current-user.decorator";
|
||||
export * from "./decorators/roles.decorator";
|
||||
export * from "./decorators/public.decorator";
|
||||
|
||||
// Filters
|
||||
export * from './filters/http-exception.filter';
|
||||
export * from "./filters/http-exception.filter";
|
||||
|
||||
// Interceptors
|
||||
export * from './interceptors/response-transform.interceptor';
|
||||
export * from "./interceptors/response-transform.interceptor";
|
||||
|
||||
// Pipes
|
||||
export * from './pipes/validation.pipe';
|
||||
export * from "./pipes/validation.pipe";
|
||||
|
||||
// Entities
|
||||
export * from './entities/base.entity';
|
||||
export * from "./entities/base.entity";
|
||||
|
||||
// Repositories
|
||||
export * from './repositories/base.repository';
|
||||
export * from "./repositories/base.repository";
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
NestInterceptor,
|
||||
} from "@nestjs/common";
|
||||
import { Observable } from "rxjs";
|
||||
import { map } from "rxjs/operators";
|
||||
|
||||
export interface StandardResponse<T> {
|
||||
success: true;
|
||||
@@ -9,8 +14,14 @@ export interface StandardResponse<T> {
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ResponseTransformInterceptor<T> implements NestInterceptor<T, StandardResponse<T>> {
|
||||
intercept(_context: ExecutionContext, next: CallHandler<T>): Observable<StandardResponse<T>> {
|
||||
export class ResponseTransformInterceptor<T> implements NestInterceptor<
|
||||
T,
|
||||
StandardResponse<T>
|
||||
> {
|
||||
intercept(
|
||||
_context: ExecutionContext,
|
||||
next: CallHandler<T>,
|
||||
): Observable<StandardResponse<T>> {
|
||||
return next.handle().pipe(
|
||||
map((data) => ({
|
||||
success: true,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { ValidationPipe, ValidationPipeOptions } from '@nestjs/common';
|
||||
import { ValidationPipe, ValidationPipeOptions } from "@nestjs/common";
|
||||
|
||||
export const createValidationPipe = (overrides?: ValidationPipeOptions): ValidationPipe =>
|
||||
export const createValidationPipe = (
|
||||
overrides?: ValidationPipeOptions,
|
||||
): ValidationPipe =>
|
||||
new ValidationPipe({
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
|
||||
@@ -5,13 +5,16 @@ import {
|
||||
FindOptionsWhere,
|
||||
ObjectLiteral,
|
||||
Repository,
|
||||
} from 'typeorm';
|
||||
} from "typeorm";
|
||||
|
||||
export abstract class BaseRepository<T extends ObjectLiteral> {
|
||||
protected constructor(protected readonly repository: Repository<T>) {}
|
||||
|
||||
/** Find a single entity by its primary key. */
|
||||
async findById(id: string, options?: Omit<FindOneOptions<T>, 'where'>): Promise<T | null> {
|
||||
async findById(
|
||||
id: string,
|
||||
options?: Omit<FindOneOptions<T>, "where">,
|
||||
): Promise<T | null> {
|
||||
return this.repository.findOne({
|
||||
...options,
|
||||
where: { id } as unknown as FindOptionsWhere<T>,
|
||||
|
||||
Reference in New Issue
Block a user