@bprotsyk/aso-core 2.1.16 → 2.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -17,7 +17,7 @@ declare function getAllOffers(): Promise<IKeitaroOffer[]>;
|
|
|
17
17
|
declare function findKeitaroOffers(filter: IKeitaroOffersFilter): Promise<IKeitaroOffer[]>;
|
|
18
18
|
declare function getOfferByKeitaroId(id: number): Promise<IKeitaroOffer>;
|
|
19
19
|
declare function updateOffer(offer: any): Promise<IKeitaroOffer>;
|
|
20
|
-
declare function addOfferToKeitaro(offer: IOffer, affiliateId: number, link: string,
|
|
20
|
+
declare function addOfferToKeitaro(offer: IOffer, affiliateId: number, link: string, campaignGroupIds?: number[], groupId?: number): Promise<void>;
|
|
21
21
|
declare function createCampaign(campaignData: Partial<IKeitaroCampaign>): Promise<IKeitaroCampaign>;
|
|
22
22
|
declare function getCampaignById(id: number): Promise<IKeitaroCampaign>;
|
|
23
23
|
export declare function upsertStreamToCampaign(campaign: IKeitaroCampaign, stream: Partial<IKeitaroStream>): Promise<void>;
|
|
@@ -55,11 +55,11 @@ async function cloneStreams(originalCampaignId, streamPositionsToClone, campaign
|
|
|
55
55
|
async function updateCampaign(id, payload) {
|
|
56
56
|
await http_1.default.put(`campaigns/${id}`, payload);
|
|
57
57
|
}
|
|
58
|
-
async function createStreamForMatchingCampaigns(streamPartialPayload, offerId, campaignRegExp,
|
|
58
|
+
async function createStreamForMatchingCampaigns(streamPartialPayload, offerId, campaignRegExp, onlyInGroups) {
|
|
59
59
|
// Get a list of all campaigns
|
|
60
60
|
const allCampaigns = await getAllCampaigns();
|
|
61
61
|
// Filter the campaigns by the given RegExp
|
|
62
|
-
const matchingCampaigns = allCampaigns.filter(campaign => (
|
|
62
|
+
const matchingCampaigns = allCampaigns.filter(campaign => (onlyInGroups ? onlyInGroups.includes(campaign.group_id) : true) && campaignRegExp.exec(campaign.name));
|
|
63
63
|
// console.log(matchingCampaigns)
|
|
64
64
|
// For each matching campaign, clone the streams
|
|
65
65
|
for (const matchingCampaign of matchingCampaigns) {
|
|
@@ -120,7 +120,7 @@ function createStreamPartialPayload(keitaroOfferId, offerName, offerId, offerGeo
|
|
|
120
120
|
}],
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
-
async function addOfferToKeitaro(offer, affiliateId, link,
|
|
123
|
+
async function addOfferToKeitaro(offer, affiliateId, link, campaignGroupIds, groupId) {
|
|
124
124
|
// TODO look if offer already exists by offer.name
|
|
125
125
|
let allOffers = await getAllOffers();
|
|
126
126
|
let identicalOffer = allOffers.find((o) => { return o.name.includes(offer.name); });
|
|
@@ -144,7 +144,7 @@ async function addOfferToKeitaro(offer, affiliateId, link, campaignGroupId, grou
|
|
|
144
144
|
keitaroOfferId = keitaroOffer.id;
|
|
145
145
|
}
|
|
146
146
|
let streamPartialPayload = createStreamPartialPayload(keitaroOfferId, offer.caption, offer.name, offer.geo);
|
|
147
|
-
await createStreamForMatchingCampaigns(streamPartialPayload, offer.name, /^(FA #|A #)/,
|
|
147
|
+
await createStreamForMatchingCampaigns(streamPartialPayload, offer.name, /^(FA #|A #)/, campaignGroupIds);
|
|
148
148
|
}
|
|
149
149
|
async function createCampaign(campaignData) {
|
|
150
150
|
let { data: campaign } = await http_1.default.post(`/campaigns`, campaignData);
|
package/package.json
CHANGED
|
@@ -71,12 +71,12 @@ async function updateCampaign(id: number, payload: Partial<IKeitaroCampaign>) {
|
|
|
71
71
|
await keitaroApi.put(`campaigns/${id}`, payload)
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
async function createStreamForMatchingCampaigns(streamPartialPayload: any, offerId: string, campaignRegExp: RegExp,
|
|
74
|
+
async function createStreamForMatchingCampaigns(streamPartialPayload: any, offerId: string, campaignRegExp: RegExp, onlyInGroups?: number[]) {
|
|
75
75
|
// Get a list of all campaigns
|
|
76
76
|
const allCampaigns = await getAllCampaigns()
|
|
77
77
|
|
|
78
78
|
// Filter the campaigns by the given RegExp
|
|
79
|
-
const matchingCampaigns = allCampaigns.filter(campaign => (
|
|
79
|
+
const matchingCampaigns = allCampaigns.filter(campaign => (onlyInGroups ? onlyInGroups.includes(campaign.group_id) : true) && campaignRegExp.exec(campaign.name));
|
|
80
80
|
// console.log(matchingCampaigns)
|
|
81
81
|
|
|
82
82
|
|
|
@@ -149,7 +149,7 @@ function createStreamPartialPayload(keitaroOfferId: number, offerName: string, o
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
async function addOfferToKeitaro(offer: IOffer, affiliateId: number, link: string,
|
|
152
|
+
async function addOfferToKeitaro(offer: IOffer, affiliateId: number, link: string, campaignGroupIds?: number[], groupId?: number) {
|
|
153
153
|
// TODO look if offer already exists by offer.name
|
|
154
154
|
let allOffers = await getAllOffers()
|
|
155
155
|
let identicalOffer = allOffers.find((o) => { return o.name.includes(offer.name) })
|
|
@@ -177,7 +177,7 @@ async function addOfferToKeitaro(offer: IOffer, affiliateId: number, link: strin
|
|
|
177
177
|
|
|
178
178
|
let streamPartialPayload = createStreamPartialPayload(keitaroOfferId, offer.caption, offer.name, offer.geo)
|
|
179
179
|
|
|
180
|
-
await createStreamForMatchingCampaigns(streamPartialPayload, offer.name, /^(FA #|A #)/,
|
|
180
|
+
await createStreamForMatchingCampaigns(streamPartialPayload, offer.name, /^(FA #|A #)/, campaignGroupIds)
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
async function createCampaign(campaignData: Partial<IKeitaroCampaign>): Promise<IKeitaroCampaign> {
|