first commit

This commit is contained in:
2025-11-10 15:05:01 +05:30
commit 0230105958
35 changed files with 13428 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
class ApiError<T = unknown> extends Error {
statusCode: number;
data: T | null;
message: string;
success: boolean;
errors: Array<Error>;
isOperational: boolean;
stack?: string;
constructor(
statusCode: number,
message: string = 'Something went wrong',
errors: Array<Error> = [],
isOperational: boolean = true,
stack?: string
) {
super(message);
this.statusCode = statusCode;
this.data = null;
this.message = message;
this.success = false;
this.errors = errors;
this.isOperational = isOperational;
if (stack) {
this.stack = stack;
} else {
Error.captureStackTrace(this, this.constructor);
}
}
}
export default ApiError;

View File

@@ -0,0 +1,32 @@
import { PaginationDto, PaginationMetaDto } from '../dto/pagination.dto';
export function createPaginationMeta(
paginationDto: PaginationDto,
total: number,
): PaginationMetaDto {
const { page = 1, limit = 10 } = paginationDto;
const totalPages = Math.ceil(total / limit);
return {
page,
limit,
total,
totalPages,
hasNext: page < totalPages,
hasPrev: page > 1,
};
}
export function paginate<T>(
data: T[],
paginationDto: PaginationDto,
total: number,
) {
const meta = createPaginationMeta(paginationDto, total);
return {
data,
meta,
};
}