Skip to content

Commit a435387

Browse files
committed
fix: stricter types and conditionals
1 parent 4ec4c0e commit a435387

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

src/common/@types/classes/offset.response.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ export class OffsetMeta {
4242

4343
constructor({
4444
pageOptionsDto,
45-
itemCount,
45+
itemCount,
4646
}: {
47-
pageOptionsDto: OffsetPaginationDto
47+
pageOptionsDto: Omit<OffsetPaginationDto,"type">
4848
itemCount: number
4949
}) {
5050
this.page = pageOptionsDto.page;

src/common/@types/enums/misc.enum.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,26 @@ export enum TemplateEngine {
3737
HBS = "HBS",
3838
}
3939

40+
4041
export const FileType: Record<keyof typeof FileSize, RegExp> = {
4142
IMAGE: /(jpg|jpeg|png|gif|svg)$/i,
4243
DOC: /(pdf|doc|txt|key|csv|docx|xls|xlsx|ppt|pptx)$/i,
4344
};
4445

46+
export const ThreadFunctions = {
47+
HASH_STRING: "hashString",
48+
};
49+
50+
export const RoutingKey = {
51+
SEND_MAIL: "send-mail",
52+
SEND_NEWSLETTER: "send-newsletter",
53+
};
54+
55+
export const Queues = {
56+
MAIL: "mail",
57+
HTTP: "http",
58+
};
59+
4560
// database enums
4661

4762
export enum CursorType {
@@ -65,16 +80,6 @@ export enum ReferralStatus {
6580
COMPLETED = "COMPLETED",
6681
}
6782

68-
export enum RoutingKey {
69-
SEND_MAIL = "send-mail",
70-
SEND_NEWSLETTER = "send-newsletter",
71-
}
72-
73-
export enum Queues {
74-
MAIL = "mail",
75-
HTTP = "http",
76-
}
77-
7883
export enum PaginationType {
7984
OFFSET = "OFFSET",
8085
CURSOR = "CURSOR",

src/common/@types/interfaces/pagination.interface.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface QBCursorPaginationOptions<T extends Dictionary> {
1616
}
1717

1818
export interface QBOffsetPaginationOptions<T extends Dictionary> {
19-
pageOptionsDto: OffsetPaginationDto & { searchField: keyof T; alias: string }
19+
pageOptionsDto: Omit<OffsetPaginationDto, "type"> & { searchField: keyof T; alias: string }
2020
qb: QueryBuilder<T>
2121
}
2222

@@ -35,7 +35,7 @@ export interface PaginationAbstractResponse<T, Y> {
3535
}
3636

3737
export type Order = "$gt" | "$lt";
38-
export type OppositeOrder = "$gte" | "$lte";
38+
export type OppositeOrder = `${Order}e`;
3939

4040
export function getCursorType(cursor: QueryCursor): CursorType {
4141
return cursor === QueryCursor.DATE ? CursorType.NUMBER : CursorType.STRING;

src/common/misc/workers.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import { ThreadWorker } from "poolifier";
22
import { HelperService } from "@common/helpers";
3+
import { ThreadFunctions } from "@common/@types";
4+
35

4-
enum ThreadFunctions {
5-
HashString = "hashString",
6-
}
76

87
// all expensive process goes here to avoid blocking the main thread
98
function workerFunction(data: { functionName: string; input: string }) {
109
switch (data.functionName) {
11-
case ThreadFunctions.HashString: {
10+
case ThreadFunctions.HASH_STRING: {
1211
return HelperService.hashString(data.input);
1312
}
1413

1514
default: {
16-
throw new Error("Invalid function name");
15+
throw new Error(`Invalid thread function name, available are ${Object.keys(ThreadFunctions).join(" ,")}`);
1716
}
1817
}
1918
}

src/main.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async function bootstrap() {
5252
app.use(helmet());
5353
app.enableCors({
5454
credentials: true,
55-
methods: "GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS",
55+
methods: ["GET","HEAD","PUT","PATCH","POST","DELETE","OPTIONS"],
5656
maxAge: 3600,
5757
origin: configService.get("app.allowedOrigins", { infer: true }),
5858
});
@@ -64,13 +64,15 @@ async function bootstrap() {
6464

6565
const globalPrefix = configService.get("app.prefix", { infer: true });
6666

67+
app.setGlobalPrefix(globalPrefix);
68+
6769
app.useGlobalPipes(new ValidationPipe(AppUtils.validationPipeOptions()));
6870

6971
app.useGlobalFilters(new I18nValidationExceptionFilter({ detailedErrors: false }));
7072

7173
app.useGlobalInterceptors(new LoggerErrorInterceptor());
7274

73-
app.setGlobalPrefix(globalPrefix);
75+
7476

7577
// =========================================================
7678
// configure socket

0 commit comments

Comments
 (0)