Skip to content

Commit

Permalink
fix: include id if available
Browse files Browse the repository at this point in the history
  • Loading branch information
IanKrieger committed Sep 28, 2023
1 parent 3f190b5 commit b9847c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/user/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
UpdateCampaignInput,
} from "graphql/types";
import { CampaignFragment } from "graphql/campaign.generated";
import { AdFragment } from "graphql/ad-set.generated";
import { AdFragment, AdSetFragment } from "graphql/ad-set.generated";
import {
AdSetForm,
Billing,
Expand All @@ -18,6 +18,7 @@ import {
import _ from "lodash";
import BigNumber from "bignumber.js";
import { CreativeFragment } from "graphql/creative.generated";
import moment from "moment";

const TYPE_CODE_LOOKUP: Record<string, string> = {
notification_all_v1: "Push Notification",
Expand Down Expand Up @@ -90,6 +91,8 @@ export function editCampaignValues(
campaign: CampaignFragment,
advertiserId: string,
): CampaignForm {
const sort = (a: AdSetFragment, b: AdSetFragment) =>
moment(a.createdAt).valueOf() - moment(b.createdAt).valueOf();
const ads: AdFragment[] = _.flatMap(campaign.adSets, "ads");

const billingType = (_.head(campaign.adSets)?.billingType ??
Expand All @@ -99,7 +102,7 @@ export function editCampaignValues(

return {
id: campaign.id,
adSets: campaign.adSets.map((adSet) => {
adSets: [...campaign.adSets].sort(sort).map((adSet) => {
const seg = adSet.segments ?? ([] as Segment[]);

return {
Expand Down Expand Up @@ -156,6 +159,7 @@ function creativeList(
return {
...validCreativeFields(c, advertiserId, included),
createdAt: c.createdAt,
creativeInstanceId: included ? ad.id : undefined,
};
});
};
Expand Down Expand Up @@ -217,11 +221,13 @@ export function transformEditForm(
id: adSet.id,
billingType: form.billingType,
price: transformPrice(form),
name: adSet.name,
segments: adSet.segments.map((v) => ({ code: v.code, name: v.name })),
oses: adSet.oses.map((v) => ({ code: v.code, name: v.name })),
ads: adSet.creatives
.filter((c) => c.included)
.map((ad) => ({
id: ad.creativeInstanceId,
creativeId: ad.id,
creativeSetId: adSet.id,
})),
Expand Down
1 change: 1 addition & 0 deletions src/user/views/adsManager/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type Segment = {
};

export type Creative = CreativeInput & {
creativeInstanceId?: string;
id?: string;
targetUrlValid?: string;
state?: string;
Expand Down

0 comments on commit b9847c4

Please sign in to comment.