Skip to content

Commit

Permalink
fix: stricter types and conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiin committed Oct 8, 2023
1 parent 4ec4c0e commit a435387
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/common/@types/classes/offset.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export class OffsetMeta {

constructor({
pageOptionsDto,
itemCount,
itemCount,
}: {
pageOptionsDto: OffsetPaginationDto
pageOptionsDto: Omit<OffsetPaginationDto,"type">
itemCount: number
}) {
this.page = pageOptionsDto.page;
Expand Down
25 changes: 15 additions & 10 deletions src/common/@types/enums/misc.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,26 @@ export enum TemplateEngine {
HBS = "HBS",
}


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

export const ThreadFunctions = {
HASH_STRING: "hashString",
};

export const RoutingKey = {
SEND_MAIL: "send-mail",
SEND_NEWSLETTER: "send-newsletter",
};

export const Queues = {
MAIL: "mail",
HTTP: "http",
};

// database enums

export enum CursorType {
Expand All @@ -65,16 +80,6 @@ export enum ReferralStatus {
COMPLETED = "COMPLETED",
}

export enum RoutingKey {
SEND_MAIL = "send-mail",
SEND_NEWSLETTER = "send-newsletter",
}

export enum Queues {
MAIL = "mail",
HTTP = "http",
}

export enum PaginationType {
OFFSET = "OFFSET",
CURSOR = "CURSOR",
Expand Down
4 changes: 2 additions & 2 deletions src/common/@types/interfaces/pagination.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface QBCursorPaginationOptions<T extends Dictionary> {
}

export interface QBOffsetPaginationOptions<T extends Dictionary> {
pageOptionsDto: OffsetPaginationDto & { searchField: keyof T; alias: string }
pageOptionsDto: Omit<OffsetPaginationDto, "type"> & { searchField: keyof T; alias: string }
qb: QueryBuilder<T>
}

Expand All @@ -35,7 +35,7 @@ export interface PaginationAbstractResponse<T, Y> {
}

export type Order = "$gt" | "$lt";
export type OppositeOrder = "$gte" | "$lte";
export type OppositeOrder = `${Order}e`;

export function getCursorType(cursor: QueryCursor): CursorType {
return cursor === QueryCursor.DATE ? CursorType.NUMBER : CursorType.STRING;
Expand Down
9 changes: 4 additions & 5 deletions src/common/misc/workers.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { ThreadWorker } from "poolifier";
import { HelperService } from "@common/helpers";
import { ThreadFunctions } from "@common/@types";


enum ThreadFunctions {
HashString = "hashString",
}

// all expensive process goes here to avoid blocking the main thread
function workerFunction(data: { functionName: string; input: string }) {
switch (data.functionName) {
case ThreadFunctions.HashString: {
case ThreadFunctions.HASH_STRING: {
return HelperService.hashString(data.input);
}

default: {
throw new Error("Invalid function name");
throw new Error(`Invalid thread function name, available are ${Object.keys(ThreadFunctions).join(" ,")}`);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function bootstrap() {
app.use(helmet());
app.enableCors({
credentials: true,
methods: "GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS",
methods: ["GET","HEAD","PUT","PATCH","POST","DELETE","OPTIONS"],
maxAge: 3600,
origin: configService.get("app.allowedOrigins", { infer: true }),
});
Expand All @@ -64,13 +64,15 @@ async function bootstrap() {

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

app.setGlobalPrefix(globalPrefix);

app.useGlobalPipes(new ValidationPipe(AppUtils.validationPipeOptions()));

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

app.useGlobalInterceptors(new LoggerErrorInterceptor());

app.setGlobalPrefix(globalPrefix);


// =========================================================
// configure socket
Expand Down

0 comments on commit a435387

Please sign in to comment.