rsm-hcd / AndcultureCode.JavaScript.React

Common patterns, functions, etc... used when building react applications
6 stars 8 forks source link

Update ServiceFactory.deletefunction signature to take optional TPathParams #47

Open brandongregoryscott opened 4 years ago

brandongregoryscott commented 4 years ago

Similiar to #46, the ServiceFactory.delete signature and implementation should be updated for greater flexibility.

It should look something like this:

    /**
     * Creates conventional Service Delete function for the supplied resource type
     * @param recordType
     * @param resourceEndpoint
     */
    delete<TPathParams extends any>(resourceEndpoint: string): DeleteService {
        return async (id: number, pathParams?: TPathParams) =>
            await _delete<TPathParams>(id, resourceEndpoint, pathParams);
    },

// ---------------------------------------------------------------------------------------------
// #region Private Functions
// ---------------------------------------------------------------------------------------------

const _delete = async function<TPathParams extends any>(
    id: number,
    resourceEndpoint: string,
    pathParams?: TPathParams
) {
    const url = _buildUrl(id, resourceEndpoint, pathParams);
    return await axios
        .delete(url)
        .then((r) => ServiceUtils.mapAxiosResponse(Boolean, r));
};