Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/routes/dossiers/_post/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -910,16 +910,38 @@ export default class PostDossiers extends UserRoute<{
"wp_appq_user_to_project.project_id",
"wp_appq_project.id"
)
.where("wp_appq_project.id", projectId);
.leftJoin(
"wp_appq_customer_account_invitations",
"wp_appq_user_to_project.profile_id",
"wp_appq_customer_account_invitations.tester_id"
)
.where("wp_appq_project.id", projectId)
.andWhere(function () {
this.whereNull("wp_appq_customer_account_invitations.status").orWhere(
"wp_appq_customer_account_invitations.status",
1
);
});

if (!projectUsers.length) return;

const workspaceUsers = await tryber.tables.WpAppqUserToCustomer.do()
.select("profile_id")
.select(tryber.ref("profile_id").withSchema("wp_appq_user_to_customer"))
.leftJoin(
"wp_appq_customer_account_invitations",
"wp_appq_user_to_customer.profile_id",
"wp_appq_customer_account_invitations.tester_id"
)
.whereIn(
"customer_id",
projectUsers.map((pu) => pu.customer_id)
);
)
.andWhere(function () {
this.whereNull("wp_appq_customer_account_invitations.status").orWhere(
"wp_appq_customer_account_invitations.status",
1
);
});

const rawIds = [
...projectUsers.map((pu) => pu.profile_id),
Expand Down
56 changes: 43 additions & 13 deletions src/routes/dossiers/_post/notifyEveryone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,32 @@ describe("Route POST /dossiers", () => {
await tryber.tables.CampaignPhase.do().insert([
{ id: 1, name: "Test Phase", type_id: 1 },
]);
await tryber.tables.WpAppqEvdProfile.do().insert({
id: 1,
wp_user_id: 100,
name: "",
email: "",
education_id: 1,
employment_id: 1,
});
await tryber.tables.WpAppqEvdProfile.do().insert([
{
id: 1,
wp_user_id: 100,
name: "",
email: "",
education_id: 1,
employment_id: 1,
},
{
id: 2,
wp_user_id: 101,
name: "",
email: "",
education_id: 1,
employment_id: 1,
},
]);
await tryber.tables.WpAppqCustomerAccountInvitations.do().insert([
{
id: 1,
token: "invitationtoken",
tester_id: 2,
status: "0",
},
]);
await tryber.tables.WpAppqCustomer.do().insert({
id: 1,
company: "Test Company",
Expand All @@ -65,11 +83,18 @@ describe("Route POST /dossiers", () => {
wp_user_id: 100,
});

await tryber.tables.WpAppqUserToCustomer.do().insert({
profile_id: 1,
wp_user_id: 100,
customer_id: 1,
});
await tryber.tables.WpAppqUserToCustomer.do().insert([
{
profile_id: 1,
wp_user_id: 100,
customer_id: 1,
},
{
profile_id: 2,
wp_user_id: 101,
customer_id: 1,
},
]);

await tryber.tables.WpAppqCampaignType.do().insert([
{
Expand Down Expand Up @@ -147,6 +172,11 @@ describe("Route POST /dossiers", () => {
profileIds: { users: [{ id: 1 }] },
campaignId: expect.any(Number),
});

expect(mockPostCampaignWatchers).not.toHaveBeenCalledWith({
profileIds: { users: [{ id: 2 }] }, // user pending invitation
campaignId: expect.any(Number),
});
});

it("Should not call postCampaignWatchers", async () => {
Expand Down
Loading