feat: 添加 NestJS API 基础设施

This commit is contained in:
root
2026-09-14 12:32:46 +08:00
parent c37101e783
commit f3fb16dbc0
22 changed files with 2213 additions and 5 deletions
+4
View File
@@ -22,6 +22,10 @@ describe("contracts", () => {
it("defines the complete error-code contract", () => {
expect(Object.values(ErrorCode)).toEqual([
"OK",
"VALIDATION_ERROR",
"NOT_FOUND",
"SERVICE_UNAVAILABLE",
"INTERNAL_ERROR",
"AUTH_TOKEN_EXPIRED",
"AUTH_REFRESH_REUSED",
"BOTTLE_DAILY_LIMIT",
+11
View File
@@ -1,5 +1,9 @@
export enum ErrorCode {
OK = "OK",
VALIDATION_ERROR = "VALIDATION_ERROR",
NOT_FOUND = "NOT_FOUND",
SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
INTERNAL_ERROR = "INTERNAL_ERROR",
AUTH_TOKEN_EXPIRED = "AUTH_TOKEN_EXPIRED",
AUTH_REFRESH_REUSED = "AUTH_REFRESH_REUSED",
BOTTLE_DAILY_LIMIT = "BOTTLE_DAILY_LIMIT",
@@ -18,6 +22,13 @@ export interface SuccessResponse<T> {
requestId: string;
}
export interface ErrorResponse {
code: Exclude<ErrorCode, ErrorCode.OK>;
message: string;
data: null;
requestId: string;
}
export const ok = <T>(data: T, requestId: string): SuccessResponse<T> => ({
code: ErrorCode.OK,
message: "success",