@boarteam/boar-pack-common-backend 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +0,0 @@
1
- import { Module } from "@nestjs/common";
2
- import { WebsocketsClients } from "./websockets.clients";
3
-
4
- @Module({
5
- providers: [
6
- WebsocketsClients,
7
- ],
8
- exports: [
9
- WebsocketsClients,
10
- ],
11
- })
12
- export class WebsocketsModule {
13
- }
@@ -1,18 +0,0 @@
1
- // Should be synced with common-frontend/src/tools/ApiError.ts
2
- export type TApiErrorBodyType = {
3
- statusCode: number
4
- message: string
5
- errors: {
6
- field: string,
7
- message: string
8
- }[]
9
- }
10
-
11
- // Copied from api-client/generated/core/ApiError.ts
12
- class ApiError extends Error {
13
- public readonly url: string;
14
- public readonly status: number;
15
- public readonly statusText: string;
16
- public readonly body: TApiErrorBodyType;
17
- public readonly request: any;
18
- }
@@ -1,5 +0,0 @@
1
- export * from './named-logger';
2
- export * from './select-query-builder.extension';
3
- export * from './typeorm.execption-filter';
4
- export * from './virtual-column.decorator';
5
- export * from './ApiError'
@@ -1,14 +0,0 @@
1
- import { ConsoleLogger } from "@nestjs/common";
2
-
3
- export class NamedLogger extends ConsoleLogger {
4
- private readonly prefix: string;
5
-
6
- constructor(prefix?: string) {
7
- super();
8
- this.prefix = prefix || 'Nest';
9
- }
10
-
11
- formatPid(pid: number): string {
12
- return `[${this.prefix}] ${pid} - `;
13
- }
14
- }
@@ -1,28 +0,0 @@
1
- import { SelectQueryBuilder } from 'typeorm';
2
- import { VIRTUAL_COLUMN_KEY } from './virtual-column.decorator';
3
-
4
- declare module 'typeorm' {
5
- interface SelectQueryBuilder<Entity> {
6
- // @ts-ignore
7
- executeEntitiesAndRawResults(): Promise<{ entities: Entity[]; raw: any[] }>;
8
- }
9
- }
10
-
11
- // @ts-ignore
12
- const originExecute = SelectQueryBuilder.prototype.executeEntitiesAndRawResults;
13
- // @ts-ignore
14
- SelectQueryBuilder.prototype.executeEntitiesAndRawResults = async function (
15
- queryRunner,
16
- ) {
17
- // @ts-ignore
18
- const { entities, raw } = await originExecute.call(this, queryRunner);
19
- entities.forEach((entity, index) => {
20
- const metaInfo = Reflect.getMetadata(VIRTUAL_COLUMN_KEY, entity) ?? {};
21
- const item = raw[index];
22
-
23
- for (const [propertyKey, name] of Object.entries<string>(metaInfo)) {
24
- entity[propertyKey] = item[name];
25
- }
26
- });
27
- return { entities, raw };
28
- };
@@ -1,56 +0,0 @@
1
- import { ArgumentsHost, Catch, ExceptionFilter, Logger } from "@nestjs/common";
2
- import { QueryFailedError } from "typeorm";
3
- import { BaseExceptionFilter } from "@nestjs/core";
4
-
5
- enum ErrorCode {
6
- // pg
7
- UniqueViolation = '23505',
8
-
9
- // mysql
10
- FailedRemovingByForeignKey = 'ER_ROW_IS_REFERENCED',
11
- FailedRemovingByForeignKey2 = 'ER_ROW_IS_REFERENCED_2',
12
- }
13
-
14
- @Catch(QueryFailedError)
15
- export class TypeOrmExceptionFilter extends BaseExceptionFilter implements ExceptionFilter {
16
- private static uniqueConstraintMessages: Record<string, string> = {}
17
-
18
- public static setUniqueConstraintMessage(constraint: string, message: string) {
19
- this.uniqueConstraintMessages[constraint] = message;
20
- }
21
-
22
- private readonly logger = new Logger(TypeOrmExceptionFilter.name);
23
-
24
- catch(exception: QueryFailedError, host: ArgumentsHost) {
25
- const ctx = host.switchToHttp();
26
- const response = ctx.getResponse();
27
- const { code, constraint }: { code: string, constraint: string } = exception as any || {};
28
-
29
- this.logger.error(`QueryFailedError: ${exception.message}, code: ${code}, constraint: ${constraint}`);
30
-
31
- switch (code) {
32
- case ErrorCode.UniqueViolation:
33
- response
34
- .status(400)
35
- .json({
36
- statusCode: 400,
37
- message: TypeOrmExceptionFilter.uniqueConstraintMessages[constraint] || 'The record already exists',
38
- error: 'Bad Request',
39
- });
40
- return;
41
-
42
- case ErrorCode.FailedRemovingByForeignKey:
43
- case ErrorCode.FailedRemovingByForeignKey2:
44
- response
45
- .status(400)
46
- .json({
47
- statusCode: 400,
48
- message: 'System cannot remove the record, please remove all related records first',
49
- error: 'Bad Request',
50
- });
51
- return;
52
- }
53
-
54
- return super.catch(exception, host);
55
- }
56
- }
@@ -1,13 +0,0 @@
1
- import 'reflect-metadata';
2
-
3
- export const VIRTUAL_COLUMN_KEY = Symbol('VIRTUAL_COLUMN_KEY');
4
-
5
- export function VirtualColumn(name?: string): PropertyDecorator {
6
- return (target, propertyKey) => {
7
- const metaInfo = Reflect.getMetadata(VIRTUAL_COLUMN_KEY, target) || {};
8
-
9
- metaInfo[propertyKey] = name ?? propertyKey;
10
-
11
- Reflect.defineMetadata(VIRTUAL_COLUMN_KEY, metaInfo, target);
12
- };
13
- }