This api used to remove all items from the cart.Here we pass the customer mail id and token .
clearCart({ CUSTOMER_EMAIL, TOKEN }) {
return token_check.token_verify(CUSTOMER_EMAIL, TOKEN)
.then((data) => {
if (data == "TOKEN_INVALID" || data == "TOKEN_EXPIRED" || data == "RECORD_NOT_FOUND")
return { summary: { status: "SUCCESS", reason: data } };
else if (data == "TOKEN_VALID") {
return order_line.findAll({
where: { status: { [Op.or]: ['CART', 'CHECKOUT'] }, in_checkout: 0 },
include: [{
model: customer,
as: "customer",
attributes: ['email', 'record_row_id'],
where: { email: CUSTOMER_EMAIL }
}]
}).then((order) => {
if (order[0]) {
return order_line.destroy({
where: { status: { [Op.or]: ['CART', 'CHECKOUT'] }, in_checkout: 0 },
include: [{
model: customer,
as: "customer",
attributes: ['email', 'record_row_id'],
where: { email: CUSTOMER_EMAIL }
}]
}).then((result) => {
if (result)
return { summary: { status: "SUCCESS", reason: "RECORD_DELETED" } };
else
return { summary: { status: "SUCCESS", reason: "RECORD_NOT_DELETED" } };
}).catch(function (error) {
//console.log(error);
return {
summary: { status: "SUCCESS", reason: "RECORD_NOT_FOUND" },
};
});
}
else {
return { summary: { status: "SUCCESS", reason: "RECORD_NOT_FOUND" } }
}
}).catch(function (error) {
//console.log(error);
return { summary: { status: "SUCCESS", reason: "RECORD_NOT_FOUND" } };
});
}
})
.catch(function (error) {
// console.log(error);
return { summary: { status: "SUCCESS", reason: "RECORD_NOT_FOUND" } };
});
},