Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust async/await usage in createAsyncThunk for payloadCreator functions #22452

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const searchEntities = createAsyncThunk(
<%_ } else { _%>
const requestUrl = `${apiSearchUrl}?query=${query}`;
<%_ } _%>
return axios.get<I<%= entityReactName %>[]>(requestUrl);
return await axios.get<I<%= entityReactName %>[]>(requestUrl);
}
);

Expand All @@ -73,14 +73,14 @@ export const getEntities = createAsyncThunk('<%= entityInstance %>/fetch_entity_
<%_ } else { _%>
const requestUrl = `${apiUrl}?${sort ? `sort=${sort}&` : ''}cacheBuster=${new Date().getTime()}`;
<%_ } _%>
return axios.get<I<%= entityReactName %>[]>(requestUrl);
return await axios.get<I<%= entityReactName %>[]>(requestUrl);
});

export const getEntity = createAsyncThunk(
'<%= entityInstance %>/fetch_entity',
async (id: string | number) => {
const requestUrl = `${apiUrl}/${id}`;
return axios.get<I<%= entityReactName %>>(requestUrl);
return await axios.get<I<%= entityReactName %>>(requestUrl);
},
{ serializeError: serializeAxiosError }
);
Expand All @@ -94,7 +94,7 @@ export const createEntity = createAsyncThunk(
thunkAPI.dispatch(getEntities({}));
return result;
<%_ } else { _%>
return axios.post<I<%= entityReactName %>>(apiUrl, cleanEntity(entity));
return await axios.post<I<%= entityReactName %>>(apiUrl, cleanEntity(entity));
<%_ } _%>
},
{ serializeError: serializeAxiosError }
Expand All @@ -108,7 +108,7 @@ export const updateEntity = createAsyncThunk(
thunkAPI.dispatch(getEntities({}));
return result;
<%_ } else { _%>
return axios.put<I<%= entityReactName %>>(`${apiUrl}/${entity.<%= primaryKey.name %>}`, cleanEntity(entity));
return await axios.put<I<%= entityReactName %>>(`${apiUrl}/${entity.<%= primaryKey.name %>}`, cleanEntity(entity));
<%_ } _%>
},
{ serializeError: serializeAxiosError }
Expand All @@ -122,7 +122,7 @@ export const partialUpdateEntity = createAsyncThunk(
thunkAPI.dispatch(getEntities({}));
return result;
<%_ } else { _%>
return axios.patch<I<%= entityReactName %>>(`${apiUrl}/${entity.<%= primaryKey.name %>}`, cleanEntity(entity));
return await axios.patch<I<%= entityReactName %>>(`${apiUrl}/${entity.<%= primaryKey.name %>}`, cleanEntity(entity));
<%_ } _%>
},
{ serializeError: serializeAxiosError }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type ActivateState = Readonly<typeof initialState>;

// Actions

export const activateAction = createAsyncThunk('activate/activate_account', async (key: string) => axios.get(`api/activate?key=${key}`), {
export const activateAction = createAsyncThunk('activate/activate_account', async (key: string) => await axios.get(`api/activate?key=${key}`), {
serializeError: serializeAxiosError,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ const apiUrl = 'api/account/reset-password';
export const handlePasswordResetInit = createAsyncThunk(
'passwordReset/reset_password_init',
// If the content-type isn't set that way, axios will try to encode the body and thus modify the data sent to the server.
async (mail: string) => axios.post(`${apiUrl}/init`, mail, { headers: { ['Content-Type']: 'text/plain' } }),
async (mail: string) => await axios.post(`${apiUrl}/init`, mail, { headers: { ['Content-Type']: 'text/plain' } }),
{ serializeError: serializeAxiosError }
);

export const handlePasswordResetFinish = createAsyncThunk(
'passwordReset/reset_password_finish',
async (data: { key: string; newPassword: string }) => axios.post(`${apiUrl}/finish`, data),
async (data: { key: string; newPassword: string }) => await axios.post(`${apiUrl}/finish`, data),
{ serializeError: serializeAxiosError }
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface IPassword {

export const savePassword = createAsyncThunk(
'password/update_password',
async (password: IPassword) => axios.post(`${apiUrl}/change-password`, password),
async (password: IPassword) => await axios.post(`${apiUrl}/change-password`, password),
{ serializeError: serializeAxiosError }
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type RegisterState = Readonly<typeof initialState>;

export const handleRegister = createAsyncThunk(
'register/create_account',
async (data: { login: string; email: string; password: string; langKey?: string }) => axios.post<any>('api/register', data),
async (data: { login: string; email: string; password: string; langKey?: string }) => await axios.post<any>('api/register', data),
{ serializeError: serializeAxiosError }
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export type SessionsState = Readonly<typeof initialState>;
// Actions
const apiUrl = '/api/account/sessions/';

export const findAll = createAsyncThunk('sessions/find_all', async () => axios.get<any>(apiUrl), {
export const findAll = createAsyncThunk('sessions/find_all', async () => await axios.get<any>(apiUrl), {
serializeError: serializeAxiosError,
});

export const invalidateSession = createAsyncThunk('sessions/invalidate', async (series: any) => axios.delete(`${apiUrl}${series}`), {
export const invalidateSession = createAsyncThunk('sessions/invalidate', async (series: any) => await axios.delete(`${apiUrl}${series}`), {
serializeError: serializeAxiosError,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const saveAccountSettings: (account: any) => AppThunk = account => async
dispatch(getSession());
};

export const updateAccount = createAsyncThunk('settings/update_account', async (account: any) => axios.post<any>(apiUrl, account), {
export const updateAccount = createAsyncThunk('settings/update_account', async (account: any) => await axios.post<any>(apiUrl, account), {
serializeError: serializeAxiosError,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,31 @@ export type AdministrationState = Readonly<typeof initialState>;

// Actions
<%_ if (applicationTypeGateway && serviceDiscoveryAny) { _%>
export const getGatewayRoutes = createAsyncThunk('administration/fetch_gateway_route', async () => axios.get<any>('api/gateway/routes'), {
export const getGatewayRoutes = createAsyncThunk('administration/fetch_gateway_route', async () => await axios.get<any>('api/gateway/routes'), {
serializeError: serializeAxiosError,
});
<%_ } _%>

<%_ if (withAdminUi) { _%>
export const getSystemHealth = createAsyncThunk('administration/fetch_health', async () => axios.get<any>('management/health'), {
export const getSystemHealth = createAsyncThunk('administration/fetch_health', async () => await axios.get<any>('management/health'), {
serializeError: serializeAxiosError,
});

export const getSystemMetrics = createAsyncThunk('administration/fetch_metrics', async () => axios.get<any>('management/jhimetrics'), {
export const getSystemMetrics = createAsyncThunk('administration/fetch_metrics', async () => await axios.get<any>('management/jhimetrics'), {
serializeError: serializeAxiosError,
});

export const getSystemThreadDump = createAsyncThunk('administration/fetch_thread_dump', async () => axios.get<any>('management/threaddump'), {
export const getSystemThreadDump = createAsyncThunk('administration/fetch_thread_dump', async () => await axios.get<any>('management/threaddump'), {
serializeError: serializeAxiosError,
});

export const getLoggers = createAsyncThunk('administration/fetch_logs', async () => axios.get<any>('management/loggers'), {
export const getLoggers = createAsyncThunk('administration/fetch_logs', async () => await axios.get<any>('management/loggers'), {
serializeError: serializeAxiosError,
});

export const setLoggers = createAsyncThunk(
'administration/fetch_logs_change_level',
async ({ name, configuredLevel }: any) => axios.post(`management/loggers/${name}`, { configuredLevel }),
async ({ name, configuredLevel }: any) => await axios.post(`management/loggers/${name}`, { configuredLevel }),
{
serializeError: serializeAxiosError,
}
Expand All @@ -89,11 +89,11 @@ export const changeLogLevel: (name, configuredLevel) => AppThunk = (name, config
dispatch(getLoggers());
};

export const getConfigurations = createAsyncThunk('administration/fetch_configurations', async () => axios.get<any>('management/configprops'), {
export const getConfigurations = createAsyncThunk('administration/fetch_configurations', async () => await axios.get<any>('management/configprops'), {
serializeError: serializeAxiosError,
});

export const getEnv = createAsyncThunk('administration/fetch_env', async () => axios.get<any>('management/env'), {
export const getEnv = createAsyncThunk('administration/fetch_env', async () => await axios.get<any>('management/env'), {
serializeError: serializeAxiosError,
});
<%_ } _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ const adminUrl = 'api/admin/users';

export const getUsers = createAsyncThunk('userManagement/fetch_users', async ({ page, size, sort }: IQueryParams) => {
const requestUrl = `${apiUrl}${sort ? `?page=${page}&size=${size}&sort=${sort}` : ''}`;
return axios.get<IUser[]>(requestUrl);
return await axios.get<IUser[]>(requestUrl);
});

export const getUsersAsAdmin = createAsyncThunk('userManagement/fetch_users_as_admin', async ({ page, size, sort }: IQueryParams) => {
const requestUrl = `${adminUrl}${sort ? `?page=${page}&size=${size}&sort=${sort}` : ''}`;
return axios.get<IUser[]>(requestUrl);
return await axios.get<IUser[]>(requestUrl);
});

export const getRoles = createAsyncThunk('userManagement/fetch_roles', async () => {
return axios.get<any[]>(`api/authorities`);
return await axios.get<any[]>(`api/authorities`);
});

export const getUser = createAsyncThunk(
'userManagement/fetch_user',
async (id: string) => {
const requestUrl = `${adminUrl}/${id}`;
return axios.get<IUser>(requestUrl);
return await axios.get<IUser>(requestUrl);
},
{ serializeError: serializeAxiosError }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const initialState = {

export type ApplicationProfileState = Readonly<typeof initialState>;

export const getProfile = createAsyncThunk('applicationProfile/get_profile', async () => axios.get<any>('management/info'), {
export const getProfile = createAsyncThunk('applicationProfile/get_profile', async () => await axios.get<any>('management/info'), {
serializeError: serializeAxiosError,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ export const getSession = (): AppThunk => <% if (enableTranslation) { %>async<%
<%_ } _%>
};

export const getAccount = createAsyncThunk('authentication/get_account', async () => axios.get<any>('api/account'), {
export const getAccount = createAsyncThunk('authentication/get_account', async () => await axios.get<any>('api/account'), {
serializeError: serializeAxiosError,
});

<%_ if (authenticationTypeSession) { _%>
export const authenticate = createAsyncThunk('authentication/login', async (data: string) => axios.post<any>('api/authentication', data, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }), {
export const authenticate = createAsyncThunk('authentication/login', async (data: string) => await axios.post<any>('api/authentication', data, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }), {
serializeError: serializeAxiosError,
});

Expand All @@ -86,7 +86,7 @@ interface IAuthParams {
rememberMe?: boolean;
}

export const authenticate = createAsyncThunk('authentication/login', async (auth: IAuthParams) => axios.post<any>('api/authenticate', auth), {
export const authenticate = createAsyncThunk('authentication/login', async (auth: IAuthParams) => await axios.post<any>('api/authenticate', auth), {
serializeError: serializeAxiosError,
});

Expand Down Expand Up @@ -123,7 +123,7 @@ export const logout: () => AppThunk = () => dispatch => {
dispatch(logoutSession());
};
<%_ } else { _%>
export const logoutServer = createAsyncThunk('authentication/logout', async () => axios.post<any>('api/logout', {}), {
export const logoutServer = createAsyncThunk('authentication/logout', async () => await axios.post<any>('api/logout', {}), {
serializeError: serializeAxiosError,
});

Expand Down
Loading