hasDelegate
Check whether a delegate with the given key has been set on the request.
Import
import { hasDelegate } from '@evershop/evershop/lib/middleware/delegate';
Syntax
hasDelegate(id: string, request: EvershopRequest): boolean
Parameters
id
Type: string
The delegate key to check.
request
Type: EvershopRequest
The Express request object.
Return Value
Returns true if the delegate exists, false otherwise.
Examples
import { hasDelegate, getDelegate } from '@evershop/evershop/lib/middleware/delegate';
export default async (request, response, next) => {
if (hasDelegate('product', request)) {
const product = getDelegate('product', request);
// Use product data...
}
next();
};
See Also
- setDelegate - Store a delegate value
- getDelegate - Read a delegate value