690320:2053 UUID agian #01
Build and Deploy / deploy (push) Failing after 2m38s

This commit is contained in:
2026-03-20 20:53:50 +07:00
parent e3859c8349
commit 90cbbb8f11
4 changed files with 96 additions and 47 deletions
+27 -5
View File
@@ -5,6 +5,32 @@ import {
SearchOrganizationDto,
} from "@/types/dto/organization/organization.dto";
type ApiEnvelope<T> = {
data?: ApiEnvelope<T> | T;
message?: string;
statusCode?: number;
};
function unwrapApiData<T>(payload: ApiEnvelope<T> | T): ApiEnvelope<T> | T | null {
let current: ApiEnvelope<T> | T | null = payload;
while (
current &&
typeof current === "object" &&
"data" in current &&
current.data !== undefined
) {
current = current.data;
}
return current;
}
function unwrapArrayResponse<T>(payload: ApiEnvelope<T[]> | T[]): T[] {
const unwrapped = unwrapApiData(payload);
return Array.isArray(unwrapped) ? unwrapped : [];
}
export const organizationService = {
/**
* Get all organizations (supports filtering by projectId)
@@ -12,11 +38,7 @@ export const organizationService = {
*/
getAll: async (params?: SearchOrganizationDto) => {
const response = await apiClient.get("/organizations", { params });
// Normalize response if wrapped in data.data or direct data
if (response.data && Array.isArray(response.data.data)) {
return response.data.data;
}
return response.data.data || response.data;
return unwrapArrayResponse(response.data);
},
/**