Thanks for adding useful information here Pawan :)
One small correction . in below code block we need to update third method i.e getCartForuser to deletecartIfExists
async function clearCartIfAlreadyExists(userId: string) : Promise<void> {
const existingCart = await getCartForuser(userId);
await deleteCartIfExists(userId, existingCart);
}
async function getCartForuser(userId: string): Promise<Cart> {
return await getCartForuser(userId);
}
async function getCartForuser(userId: string, existingCart: Cart): Promise<Cart> {
if(existingCart) {
await cartService.deleteCart(userId);
}
}