Skip to content

Update ServiceFactory.update function signature to take optional TQueryParams #46

@brandongregoryscott

Description

@brandongregoryscott

The internal project that most of this package was based off of has since evolved - we've seen the need for query params in an update service call. The signature & implementation should be updated to be more flexible for consumers. It should look something like this:

    /**
     * Creates conventional Service Update function for the supplied resource type
     * @param recordType
     * @param resourceEndpoint
     */
    update<
        TRecord extends any,
        TPathParams extends any,
        TQueryParams = undefined
    >(
        recordType: { new (): TRecord },
        resourceEndpoint: string
    ): UpdateService<TRecord, TPathParams, TQueryParams> {
        return async (
            record: TRecord,
            pathParams?: TPathParams,
            queryParams?: TQueryParams
        ) =>
            await _update<TRecord, TPathParams, TQueryParams>(
                recordType,
                record,
                resourceEndpoint,
                pathParams,
                queryParams
            );
    },

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

const _update = async function<
    TRecord extends any,
    TPathParams extends any,
    TQueryParams extends any = any
>(
    recordType: { new (): TRecord },
    record: TRecord,
    resourceEndpoint: string,
    pathParams?: TPathParams,
    queryParams?: TQueryParams
) {
    const url = _buildUrl(record.id, resourceEndpoint, pathParams, queryParams);
    return await axios
        .put(url, record.toJS())
        .then((r) => ServiceUtils.mapAxiosResponse(recordType, r));
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions