@feardread/feature-factory 4.0.6 → 4.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.min.js +2 -2
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/factory/index.js +4 -4
- package/src/factory/thunk.js +4 -8
package/package.json
CHANGED
package/src/factory/index.js
CHANGED
|
@@ -83,7 +83,7 @@ export function FeatureFactory(entity, reducers = {}, endpoints = null) {
|
|
|
83
83
|
const createStandardThunks = (sliceName) => ({
|
|
84
84
|
fetch: ThunkFactory.create(sliceName, 'all'),
|
|
85
85
|
fetchOne: ThunkFactory.create(sliceName, 'one'),
|
|
86
|
-
search: ThunkFactory.
|
|
86
|
+
search: ThunkFactory.post(sliceName, 'search'),
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
/**
|
|
@@ -102,13 +102,13 @@ export function FeatureFactory(entity, reducers = {}, endpoints = null) {
|
|
|
102
102
|
.addCase(action.fulfilled, (state, actionPayload) => {
|
|
103
103
|
state.loading = false;
|
|
104
104
|
state.success = true;
|
|
105
|
-
state.data = actionPayload.payload;
|
|
105
|
+
state.data = actionPayload.payload.result;
|
|
106
106
|
|
|
107
107
|
// Handle single item for fetchOne operation
|
|
108
108
|
if (key === 'fetchOne' && Array.isArray(actionPayload.payload)) {
|
|
109
|
-
state[sliceName] = actionPayload.payload[0];
|
|
109
|
+
state[sliceName] = actionPayload.payload[0].result;
|
|
110
110
|
} else if (Array.isArray(actionPayload.payload) && actionPayload.payload.length > 0) {
|
|
111
|
-
state[sliceName] = actionPayload.payload[0];
|
|
111
|
+
state[sliceName] = actionPayload.payload[0].result;
|
|
112
112
|
}
|
|
113
113
|
})
|
|
114
114
|
.addCase(action.rejected, (state, actionPayload) => {
|
package/src/factory/thunk.js
CHANGED
|
@@ -68,6 +68,8 @@ const buildUrl = (entity, prefix, params = {}, useIdInUrl = false) => {
|
|
|
68
68
|
*/
|
|
69
69
|
const handleResponse = (response) => {
|
|
70
70
|
// Handle different response structures
|
|
71
|
+
console.log('resp = ', response)
|
|
72
|
+
return response.data;
|
|
71
73
|
if (response?.data?.result !== undefined) {
|
|
72
74
|
return response.data.result;
|
|
73
75
|
}
|
|
@@ -120,15 +122,11 @@ const createGenericThunk = (entity, prefix, options = {}) => {
|
|
|
120
122
|
`${entity}/${prefix}`,
|
|
121
123
|
async (payload = {}, thunkApi) => {
|
|
122
124
|
try {
|
|
123
|
-
const url =
|
|
125
|
+
const url = buildUrl(entity, prefix, payload, config.useIdInUrl);
|
|
124
126
|
|
|
125
127
|
let apiCall;
|
|
126
128
|
const apiConfig = config.useParams ? { params: payload } : {};
|
|
127
129
|
|
|
128
|
-
if ( config.customApiUrl !== null ) {
|
|
129
|
-
API.instance.defaults.baseURL = config.customApiUrl;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
130
|
switch (config.method) {
|
|
133
131
|
case HTTP_METHODS.GET:
|
|
134
132
|
apiCall = API.get(url, apiConfig);
|
|
@@ -162,18 +160,16 @@ const createGenericThunk = (entity, prefix, options = {}) => {
|
|
|
162
160
|
* Factory for creating Redux async thunks with standardized patterns
|
|
163
161
|
*/
|
|
164
162
|
export const ThunkFactory = {
|
|
165
|
-
API_URL: null,
|
|
166
163
|
/**
|
|
167
164
|
* Creates a GET request thunk (legacy method for backward compatibility)
|
|
168
165
|
* @param {string} entity - The entity name
|
|
169
166
|
* @param {string} prefix - The operation prefix
|
|
170
167
|
* @returns {Function} The created async thunk
|
|
171
168
|
*/
|
|
172
|
-
create: (entity, prefix
|
|
169
|
+
create: (entity, prefix) => {
|
|
173
170
|
validateThunkParams(entity, prefix);
|
|
174
171
|
|
|
175
172
|
const operation = STANDARD_OPERATIONS[prefix];
|
|
176
|
-
const options = {operation, customApiUrl: apiUrl};
|
|
177
173
|
if (operation) {
|
|
178
174
|
return createGenericThunk(entity, prefix, options);
|
|
179
175
|
}
|