feat: add admin module

This commit is contained in:
2026-06-01 14:45:01 +03:30
parent 7dda2564a8
commit 967b96184a
30 changed files with 335 additions and 30 deletions
@@ -0,0 +1,53 @@
import {
CallHandler,
ExecutionContext,
Injectable,
NestInterceptor,
} from '@nestjs/common';
import { map, Observable } from 'rxjs';
import { AppResponse, PaginatedResponse } from '../responses';
@Injectable()
export class ResponseInterceptor implements NestInterceptor {
intercept(
context: ExecutionContext,
next: CallHandler<any>,
): Observable<any> | Promise<Observable<any>> {
return next.handle().pipe(
map((response) => {
if (response instanceof PaginatedResponse) {
return {
success: true,
data: response.data,
pagination: {
...response.pagination,
totalPages: Math.ceil(
response.pagination.total / response.pagination.limit,
),
},
...(response.message && {
message: response.message,
}),
};
}
if (response instanceof AppResponse) {
return {
success: true,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
data: response.data,
...(response.message && {
message: response.message,
}),
};
}
return {
success: true,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
data: response,
};
}),
);
}
}
+6
View File
@@ -0,0 +1,6 @@
export class AppResponse<T> {
constructor(
public readonly data: T,
public readonly message?: string,
) {}
}
+2
View File
@@ -0,0 +1,2 @@
export * from './app-response';
export * from './paginated-response';
@@ -0,0 +1,13 @@
export interface PaginationMeta {
page: number;
limit: number;
total: number;
}
export class PaginatedResponse<T> {
constructor(
public readonly data: T[],
public readonly pagination: PaginationMeta,
public readonly message?: string,
) {}
}