2021-03-12 12:14:18 +00:00
|
|
|
import * as channels from "../apiRequests/Channels";
|
2021-02-15 09:44:50 +00:00
|
|
|
|
2021-03-12 12:14:18 +00:00
|
|
|
export function deleteChannelsStartsWith(nameStartsWith) {
|
|
|
|
channels.getChannels().then(resp => {
|
|
|
|
const channelsArray = new Set(resp.body.data.channels);
|
|
|
|
if (!channelsArray) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
channelsArray.forEach(element => {
|
|
|
|
if (element.name.startsWith(nameStartsWith)) {
|
|
|
|
const targetChannels = Array.from(channelsArray).filter(function(
|
|
|
|
channelElement
|
|
|
|
) {
|
|
|
|
return (
|
|
|
|
element.currencyCode === channelElement.currencyCode &&
|
|
|
|
element.id !== channelElement.id
|
|
|
|
);
|
|
|
|
});
|
|
|
|
if (targetChannels[0]) {
|
|
|
|
channels.deleteChannel(element.id, targetChannels[0].id);
|
|
|
|
channelsArray.delete(element);
|
2021-02-17 11:22:24 +00:00
|
|
|
}
|
2021-03-12 12:14:18 +00:00
|
|
|
}
|
2021-02-15 09:44:50 +00:00
|
|
|
});
|
2021-03-12 12:14:18 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
export function getDefaultChannel() {
|
|
|
|
return channels.getChannels().then(resp => {
|
|
|
|
const channelsArray = resp.body.data.channels;
|
|
|
|
return channelsArray.find(function(channelElement) {
|
|
|
|
return channelElement.slug === "default-channel";
|
2021-02-15 09:44:50 +00:00
|
|
|
});
|
2021-03-12 12:14:18 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
export function createChannel({
|
|
|
|
isActive = true,
|
|
|
|
name,
|
|
|
|
slug = name,
|
|
|
|
currencyCode = "PLN"
|
|
|
|
}) {
|
|
|
|
return channels
|
|
|
|
.createChannel(isActive, name, slug, currencyCode)
|
|
|
|
.its("body.data.channelCreate.channel");
|
2021-02-15 09:44:50 +00:00
|
|
|
}
|