Skip to content

Activities with organizations#968

Merged
joanagmaia merged 19 commits intofeature/segmentsfrom
feature/activities-with-organization
Jun 19, 2023
Merged

Activities with organizations#968
joanagmaia merged 19 commits intofeature/segmentsfrom
feature/activities-with-organization

Conversation

@epipav
Copy link
Copy Markdown
Collaborator

@epipav epipav commented Jun 8, 2023

Changes proposed ✍️

  • Member enrichment improvement: We now also get member's organization and create the related entity on enrichment/
  • New relation between organizations & activities using the new organizationId field in activities.
  • Members can now have their distinct affiliation settings. Affiliation is an override setting for a member's activities for the organization. Since members can have multiple organizations, for each member we can let users select which organization will be associated with their activities.
  • Member-segment affiliation settings can be manipulated by updating the member. The field is called affiliations and it has the form of:
{
    memberId: uuid
    segmentId: uuid
    organizationId: uuid
}

While we return this along with the member, we also include additional join attributes for segment and organization (organizationName, organizationLogo, segmentParentName, segmentName, segmentSlug)

  • If an affiliation setting isn't present for a member, we select the first organization of the member and associate it with their activities.
  • Activity organization is set on activity creation - Subsequent upserts to the activity will not change its organization.

What

🤖 Generated by Copilot at d394665

This pull request adds and improves features related to activity and member data, organization information, and conversation settings. It updates the data models, repositories, services, and scripts to handle the new and modified fields and associations. It also refactors some code to use the format method and adds a new script to the data sink worker service.

🤖 Generated by Copilot at d394665

organizationId
joins activities and orgs
a winter project

Why

How

🤖 Generated by Copilot at d394665

  • Drop and add back organizationId column to activities table with foreign key constraint (link, link)
  • Add belongsTo association between activity and organization models (link)
  • Include organizationId and organization model in activity repository methods (link, link, link)
  • Add script to generate parentIds for historical discord activities (link)
  • Add body property to message object sent to SQS queue by sendNodeWorkerMessage function (link)
  • Add logic to create organization object from enrichment data in memberEnrichmentService (link)
  • Add companyUrl and company properties to enrichment interfaces (link, link)
  • Modify awards attribute type from MULTI_SELECT to SPECIAL in sampleDataService (link)
  • Add script to restart a specific result by id in data_sink_worker service (link)
  • Refactor updateActivity and updateMember methods in data_sink_worker repo to use format method (link, link)
  • Modify insert query for conversationSettings table to include createdById column (link)
  • Refactor toDb and add format methods in repository base class (link, link)
  • Add null check for sentiment property of activity in memberRepository (link)

Checklist ✅

  • Label appropriately with Feature, Improvement, or Bug.
  • Add screehshots to the PR description for relevant FE changes
  • New backend functionality has been unit-tested.
  • API documentation has been updated (if necessary) (see docs on API documentation).
  • Quality standards are met.

@epipav epipav self-assigned this Jun 12, 2023
@epipav epipav added the Feature Created by Linear-GitHub Sync label Jun 12, 2023
@epipav epipav marked this pull request as ready for review June 12, 2023 10:57
@epipav epipav requested a review from sausage-todd June 13, 2023 08:33
Copy link
Copy Markdown
Contributor

@sausage-todd sausage-todd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, but clarify a couple comments please before we merge


const currentTenant = SequelizeRepository.getCurrentTenant(options)

const segment = SequelizeRepository.getStrictlySingleActiveSegment(options)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

Comment on lines +225 to +233
include: [
{
model: options.database.segment,
as: 'segments',
through: {
attributes: [],
},
},
],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Activities have their own segments, right? If you need segments in the returned data, why not include segments just by themselves on the top level?

Copy link
Copy Markdown
Collaborator Author

@epipav epipav Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need the include at all anymore, I was first keeping the affiliation settings in memberSegments then changed to a new table, this was some artifact from it. Thanks for spotting it 👍 removed the include

Comment on lines +17 to +24
UPDATE activities
SET "organizationId" = (
SELECT mo."organizationId"
FROM "memberOrganizations" AS mo
WHERE mo."memberId" = activities."memberId"
ORDER BY mo."createdAt" DESC
LIMIT 1
); No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right. Shouldn't we also filter by tenantId, and maybe segmentId ?

Copy link
Copy Markdown
Collaborator Author

@epipav epipav Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tenantId filter is already implicitly in memberId since each member can belong to only one tenant -
I didn't include segments because, in the prod data, we don't have segments yet. Tho probably it'll be better to add it for the staging data - I updated the query to also join by organizationSegments 👍

@@ -0,0 +1 @@
ALTER TABLE public."activities" DROP COLUMN "organizationId" No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DROP TABLE "memberSegmentAffiliations" ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added 👍

Comment on lines +10 to +12
export function switchSegments(options, segments) {
options.currentSegments = segments
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

Comment on lines +139 to +153
const parent = await segmentRepository.findBySlug(data.parentSlug, SegmentLevel.PROJECT)

if (parent === null) {
throw new Error(`Project ${data.parentSlug} does not exist.`)
}

const grandparent = await segmentRepository.findBySlug(
data.grandparentSlug,
SegmentLevel.PROJECT_GROUP,
)

if (grandparent === null) {
throw new Error(`Project group ${data.parentSlug} does not exist.`)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@joanagmaia joanagmaia merged commit e424cc9 into feature/segments Jun 19, 2023
@joanagmaia joanagmaia deleted the feature/activities-with-organization branch June 19, 2023 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Created by Linear-GitHub Sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants