Skip to content

Commit

Permalink
Remove unused code for insights in PATCH /campaigns/{campaignId}/ux
Browse files Browse the repository at this point in the history
  • Loading branch information
sinatragianpaolo committed Aug 1, 2024
1 parent 88a1940 commit 337d826
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const campaign = {
const requestBody = {
goal: "Test Goal",
usersNumber: 5,
insights: [],
sentiments: [],
questions: [],
methodology: {
Expand Down
102 changes: 0 additions & 102 deletions src/routes/campaigns/campaignId/ux/_patch/draft-modified.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,81 +59,12 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft modified", () => {
published: 0,
},
]);

await tryber.tables.UxCampaignInsights.do().insert([
{
id: 1,
campaign_id: 123,
version: 1,
title: "Publish insight",
description: "Publish description",
severity_id: 1,
cluster_ids: "1",
finding_id: 10,
enabled: 1,
},
{
id: 2,
campaign_id: 123,
version: 1,
title: "Publish insight 2",
description: "Publish description 2",
severity_id: 1,
cluster_ids: "1",
finding_id: 20,
enabled: 1,
},
// Draft modified insights
{
id: 3,
campaign_id: 123,
version: 2,
title: "Publish insight",
description: "Publish description",
severity_id: 1,
cluster_ids: "1",
finding_id: 10,
enabled: 1,
},
{
id: 4,
campaign_id: 123,
version: 2,
title: "Publish insight 2",
description: "Publish description 2",
severity_id: 1,
cluster_ids: "1",
finding_id: 20,
enabled: 1,
},
]);

await tryber.tables.UxCampaignVideoParts.do().insert([
{
id: 1,
media_id: 1,
insight_id: 2,
start: 0,
end: 10,
description: "Publish video part",
},
{
id: 2,
media_id: 1,
insight_id: 4,
start: 0,
end: 10,
description: "Publish video part",
},
]);
});

afterAll(async () => {
await tryber.tables.WpAppqEvdCampaign.do().delete();
await tryber.tables.UxCampaignData.do().delete();
await tryber.tables.WpAppqUserTaskMedia.do().delete();
await tryber.tables.UxCampaignInsights.do().delete();
await tryber.tables.UxCampaignVideoParts.do().delete();
await tryber.tables.UxCampaignQuestions.do().delete();
});

Expand All @@ -144,35 +75,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft modified", () => {
.send({
goal: "Test Goal",
usersNumber: 5,
insights: [
{
id: 3,
title: "Publish insight",
description: "Publish description",
order: 0,
severityId: 1,
clusterIds: [1],
videoParts: [],
},
{
id: 4,
title: "Publish insight 2",
description: "Publish description 2",
order: 0,
severityId: 1,
clusterIds: [1],
videoParts: [
{
id: 2,
order: 0,
start: 0,
end: 10,
mediaId: 1,
description: "Publish video part",
},
],
},
],
sentiments: [],
questions: [],
methodology,
Expand All @@ -198,9 +100,5 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft modified", () => {
campaign_id: 123,
})
);

const videoParts = await tryber.tables.UxCampaignVideoParts.do().select();

expect(videoParts.length).toBe(2);
});
});
1 change: 0 additions & 1 deletion src/routes/campaigns/campaignId/ux/_patch/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const campaign = {
const requestBody = {
goal: "Test Goal",
usersNumber: 5,
insights: [],
sentiments: [],
questions: [],
methodology: {
Expand Down
39 changes: 0 additions & 39 deletions src/routes/campaigns/campaignId/ux/_patch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ export default class PatchUx extends UserRoute<{
}

await this.publishData();
await this.publishInsight();
await this.publishQuestions();
await this.publishSentiments();
this.version++;
Expand Down Expand Up @@ -353,42 +352,4 @@ export default class PatchUx extends UserRoute<{
}
}
}

private async publishInsight() {
const draftData = this.lastDraft?.data;
if (!draftData) throw new OpenapiError("No draft found");

let findingOrder = 0;
for (const insight of draftData.findings) {
const insertedInsight = await tryber.tables.UxCampaignInsights.do()
.insert({
campaign_id: this.campaignId,
cluster_ids:
insight.clusters === "all"
? "0"
: insight.clusters.map((c) => c.id).join(","),
description: insight.description,
order: findingOrder++,
severity_id: insight.severity.id,
title: insight.title,
version: this.version + 1,
finding_id: insight.findingId,
})
.returning("id");

const insertedInsightId = insertedInsight[0].id ?? insertedInsight[0];

let videoPartOrder = 0;
for (const videoPart of insight.videoParts) {
await tryber.tables.UxCampaignVideoParts.do().insert({
start: videoPart.start,
end: videoPart.end,
media_id: videoPart.mediaId,
description: videoPart.description,
order: videoPartOrder++,
insight_id: insertedInsightId,
});
}
}
}
}

0 comments on commit 337d826

Please sign in to comment.