2021-10-28 14:43:26 +00:00
|
|
|
import {
|
|
|
|
addChannelToVoucher,
|
|
|
|
createVoucher,
|
|
|
|
deleteVouchers,
|
|
|
|
getVouchers
|
|
|
|
} from "../../requests/Discounts/Vouchers";
|
2021-03-23 10:15:39 +00:00
|
|
|
|
|
|
|
export function deleteVouchersStartsWith(startsWith) {
|
|
|
|
cy.deleteElementsStartsWith(deleteVouchers, getVouchers, startsWith, "code");
|
|
|
|
}
|
2021-10-28 14:43:26 +00:00
|
|
|
|
|
|
|
export function createVoucherInChannel({
|
|
|
|
name,
|
|
|
|
productId,
|
|
|
|
channelId,
|
|
|
|
value,
|
2022-02-11 14:58:40 +00:00
|
|
|
code = name,
|
|
|
|
type,
|
|
|
|
country
|
2021-10-28 14:43:26 +00:00
|
|
|
}) {
|
|
|
|
let voucher;
|
2022-02-11 14:58:40 +00:00
|
|
|
return createVoucher({ name, productId, code, type, country })
|
2021-10-28 14:43:26 +00:00
|
|
|
.then(({ voucher: voucherResp }) => {
|
|
|
|
voucher = voucherResp;
|
|
|
|
addChannelToVoucher(voucher.id, channelId, value);
|
|
|
|
})
|
|
|
|
.then(() => voucher);
|
|
|
|
}
|