Types (@vppos/core/types)
import type { CommonResponse, PaginationResponse, CommonErrorResponse } from "@vppos/core/types";
Response Types
CommonResponse<T>
Response chuẩn cho API trả về 1 object:
interface CommonResponse<T> {
data: T;
message: string;
status: number;
}
PaginationResponse<T>
Response chuẩn cho API có pagination:
interface PaginationResponse<T> {
data: T[];
meta: {
total: number;
page: number;
limit: number;
totalPages: number;
};
}
CommonErrorResponse
Response lỗi chuẩn:
interface CommonErrorResponse {
message: string;
errors?: FieldError[];
}
ApiErrorPayload
Payload lỗi chi tiết:
interface ApiErrorPayload {
message: string;
fieldErrors?: Record<string, string[]>;
}
Utility Types
StatusType
Enum trạng thái chung: active, inactive, etc.
FieldError
Field-level validation error.
Quy tắc
mẹo
- Luôn dùng
CommonResponse<T>hoặcPaginationResponse<T>— không tự định nghĩa response type - Kiểm tra types sẵn có trong
@vppos/core/typestrước khi tạo mới - Không dùng
any— luôn khai báo type cụ thể