@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.
- package/dist/modules/websockets/index.d.ts +1 -0
- package/dist/modules/websockets/index.js +1 -0
- package/dist/modules/websockets/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -3
- package/src/index.ts +0 -6
- package/src/modules/cluster/cluster.config.ts +0 -38
- package/src/modules/cluster/cluster.interface.ts +0 -25
- package/src/modules/cluster/cluster.module.ts +0 -47
- package/src/modules/cluster/cluster.service.ts +0 -178
- package/src/modules/cluster/index.ts +0 -4
- package/src/modules/schedule/schedule.module.ts +0 -18
- package/src/modules/schedule/schedule.service.ts +0 -43
- package/src/modules/scrypt/scrypt.config.ts +0 -36
- package/src/modules/scrypt/scrypt.module.ts +0 -20
- package/src/modules/scrypt/scrypt.service.ts +0 -41
- package/src/modules/websockets/dto/websockets.dto.ts +0 -12
- package/src/modules/websockets/index.ts +0 -2
- package/src/modules/websockets/websockets.clients.ts +0 -164
- package/src/modules/websockets/websockets.exception-filter.ts +0 -19
- package/src/modules/websockets/websockets.module.ts +0 -13
- package/src/tools/ApiError.ts +0 -18
- package/src/tools/index.ts +0 -5
- package/src/tools/named-logger.ts +0 -14
- package/src/tools/select-query-builder.extension.ts +0 -28
- package/src/tools/typeorm.execption-filter.ts +0 -56
- package/src/tools/virtual-column.decorator.ts +0 -13
package/src/tools/ApiError.ts
DELETED
|
@@ -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
|
-
}
|
package/src/tools/index.ts
DELETED
|
@@ -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
|
-
}
|