@@ -4,6 +4,12 @@ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
44import { base64ToArrayBuffer } from 'libs' ;
55import fetchBaseQueryHeaders from 'libs/fetchBaseQueryHeaders' ;
66
7+ // Helper function to transform backend response to frontend format
8+ const transformProjectResponse = ( project : any ) : IProject => ( {
9+ ...project ,
10+ isPublic : project . is_public ,
11+ } ) ;
12+
713export const projectApi = createApi ( {
814 reducerPath : 'projectApi' ,
915 refetchOnMountOrArgChange : true ,
@@ -22,6 +28,9 @@ export const projectApi = createApi({
2228 } ;
2329 } ,
2430
31+ transformResponse : ( response : any [ ] ) : IProject [ ] =>
32+ response . map ( transformProjectResponse ) ,
33+
2534 providesTags : ( result ) =>
2635 result
2736 ? [ ...result . map ( ( { project_name } ) => ( { type : 'Projects' as const , id : project_name } ) ) , 'Projects' ]
@@ -36,6 +45,8 @@ export const projectApi = createApi({
3645 } ;
3746 } ,
3847
48+ transformResponse : transformProjectResponse ,
49+
3950 providesTags : ( result ) => ( result ? [ { type : 'Projects' as const , id : result . project_name } ] : [ ] ) ,
4051 } ) ,
4152
@@ -46,6 +57,8 @@ export const projectApi = createApi({
4657 body : project ,
4758 } ) ,
4859
60+ transformResponse : transformProjectResponse ,
61+
4962 invalidatesTags : ( ) => [ 'Projects' ] ,
5063 } ) ,
5164
@@ -58,6 +71,8 @@ export const projectApi = createApi({
5871 } ,
5972 } ) ,
6073
74+ transformResponse : transformProjectResponse ,
75+
6176 invalidatesTags : ( result , error , params ) => [ { type : 'Projects' as const , id : params ?. project_name } ] ,
6277 } ) ,
6378
@@ -70,6 +85,8 @@ export const projectApi = createApi({
7085 } ,
7186 } ) ,
7287
88+ transformResponse : transformProjectResponse ,
89+
7390 invalidatesTags : ( result , error , params ) => [ { type : 'Projects' as const , id : params ?. project_name } ] ,
7491 } ) ,
7592
@@ -82,6 +99,8 @@ export const projectApi = createApi({
8299 } ,
83100 } ) ,
84101
102+ transformResponse : transformProjectResponse ,
103+
85104 invalidatesTags : ( result , error , params ) => [ { type : 'Projects' as const , id : params ?. project_name } ] ,
86105 } ) ,
87106
@@ -132,6 +151,7 @@ export const projectApi = createApi({
132151 method : 'POST' ,
133152 body : { is_public } ,
134153 } ) ,
154+ transformResponse : transformProjectResponse ,
135155 invalidatesTags : ( result , error , params ) => [ { type : 'Projects' as const , id : params ?. project_name } ] ,
136156 } ) ,
137157 } ) ,
0 commit comments