import {type BackendEndpoint} from '@myparcel-pdk/common'; import {type OneOrMore, toArray} from '@myparcel/ts-utils'; import {type BackendEndpointResponse} from '../../types'; import {type ActionContext} from './types'; import {doMutate} from './doMutate'; export const createHandlerWithParameters = async ( args: OneOrMore, endpoint: E, context: ActionContext, allowBulk?: Bulk, ): Promise>> => { const ids = toArray(args); if (!ids.length) { throw new Error('No arguments provided'); } if (allowBulk && ids.length > 1) { // For bulk actions, don't pass ids to the mutations. return doMutate(endpoint, undefined, context); } if (ids.length === 1) { return doMutate(endpoint, ids[0], context); } return Promise.all(ids.map((id) => doMutate(endpoint, id, context))); };