Skip to content

Commit

Permalink
feat: Update legacy status details
Browse files Browse the repository at this point in the history
  • Loading branch information
d-beezee committed May 20, 2024
1 parent a1899b1 commit 03d4af7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@appquality/tryber-database": "^0.37.0",
"@appquality/tryber-database": "^0.39.0",
"@appquality/wp-auth": "^1.0.7",
"@googlemaps/google-maps-services-js": "^3.3.7",
"@sendgrid/mail": "^7.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ describe("StatusChangeHandler", () => {
},
]);
await tryber.tables.CampaignPhase.do().insert([
{ id: 1, name: "Draft", type_id: 1 },
{ id: 2, name: "Running", type_id: 2 },
{ id: 3, name: "Closed", type_id: 3 },
{ id: 1, name: "Draft", type_id: 1, status_details: "Planned" },
{ id: 2, name: "Running", type_id: 2, status_details: "Running" },
{ id: 3, name: "Closed", type_id: 3, status_details: "Successful" },
]);

await tryber.tables.CampaignPhaseType.do().insert([
Expand Down Expand Up @@ -134,4 +134,22 @@ describe("StatusChangeHandler", () => {
if (!campaign) throw new Error("Campaign not found");
expect(campaign.status_id).toBe(1);
});

it("Should change the status details of the campaign", async () => {
const handler = new StatusChangeHandler({
newPhase: 1,
campaignId: 2,
creator: 1,
});

await handler.run();

const campaign = await tryber.tables.WpAppqEvdCampaign.do()
.select("status_details")
.where("id", 2)
.first();

if (!campaign) throw new Error("Campaign not found");
expect(campaign.status_details).toBe("Planned");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class StatusChangeHandler {

await this.handleStatusChange(type.name);

await this.legacySetStatusDetails();

await this.saveHistory();
console.log("Status changed from", this.oldPhase, "to", this.newPhase);
}
Expand Down Expand Up @@ -71,6 +73,18 @@ class StatusChangeHandler {

await this.triggerWebhook();
}
private async legacySetStatusDetails() {
const phase = await tryber.tables.CampaignPhase.do()
.select("status_details")
.where("id", this.newPhase)
.first();

if (!phase || !phase.status_details) return;

await tryber.tables.WpAppqEvdCampaign.do()
.update({ status_details: phase.status_details })
.where("id", this.campaignId);
}

private async triggerWebhook() {
const webhook = new WebhookTrigger({
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"@babel/parser" "^7.22.5"
"@babel/traverse" "^7.22.5"

"@appquality/tryber-database@^0.37.0":
version "0.37.0"
resolved "https://registry.yarnpkg.com/@appquality/tryber-database/-/tryber-database-0.37.0.tgz#cf68eeae7f26f3089c83dc7e657cd3369db4452d"
integrity sha512-wizquFsjXWPzDe3xYfC8MSzzuX4tSQpdO+4sLBsGTekaf0N4gwfzn9b0xrjq16aiQSAr84Y01elgiiJWC5J9+w==
"@appquality/tryber-database@^0.39.0":
version "0.39.0"
resolved "https://registry.yarnpkg.com/@appquality/tryber-database/-/tryber-database-0.39.0.tgz#b0b0e4a6c6d456f5cc7d6b9d0348e60795fac8ea"
integrity sha512-SQaETcgQml5qBhkJUJNRdk+POjQx8zRLTNPnRlR5/ZUdN6qzsrhUfmP+2mA1SHx0AIqP4Gfh2hKV1QJZj7FV/w==
dependencies:
better-sqlite3 "^8.1.0"
knex "^2.5.1"
Expand Down

0 comments on commit 03d4af7

Please sign in to comment.