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
Original file line number Diff line number Diff line change
Expand Up @@ -905,68 +905,6 @@ describe('OrganizationRepository tests', () => {
expect(found.rows[0].name).toBe('crowd.dev')
})

it('Should filter by activityCount', async () => {
const mockIRepositoryOptions = await SequelizeTestUtils.getTestIRepositoryOptions(db)
const org1 = await createOrganization(crowddev, mockIRepositoryOptions, [
{
username: {
github: {
username: 'joan',
integrationId: generateUUIDv1(),
},
},
displayName: 'Joan',
joinedAt: moment().toDate(),
activities: [
{
type: 'activity',
username: 'joan',
timestamp: '2020-05-27T15:13:30Z',
platform: PlatformType.GITHUB,
sourceId: '#sourceId1',
},
],
},
{
username: {
github: {
username: 'anil',
integrationId: generateUUIDv1(),
},
},
displayName: 'anil',
joinedAt: moment().toDate(),
activities: [
{
type: 'activity',
username: 'anil',
timestamp: '2020-06-27T15:13:30Z',
platform: PlatformType.TWITTER,
sourceId: '#sourceId2',
},
],
},
])
await createOrganization(piedpiper, mockIRepositoryOptions)
await createOrganization(hooli, mockIRepositoryOptions)

const found = await OrganizationRepository.findAndCountAll(
{
advancedFilter: {
activityCount: {
gte: 2,
},
},
},
mockIRepositoryOptions,
)

delete org1.members

expect(found.count).toBe(1)
expect(found.rows).toStrictEqual([org1])
})

it('Should filter by memberCount', async () => {
const mockIRepositoryOptions = await SequelizeTestUtils.getTestIRepositoryOptions(db)
const org1 = await createOrganization(crowddev, mockIRepositoryOptions, [
Expand Down Expand Up @@ -1046,126 +984,6 @@ describe('OrganizationRepository tests', () => {
])
})

it('Should filter by joinedAt', async () => {
const mockIRepositoryOptions = await SequelizeTestUtils.getTestIRepositoryOptions(db)
await createOrganization(crowddev, mockIRepositoryOptions, [
{
username: {
github: {
username: 'joan',
integrationId: generateUUIDv1(),
},
},
displayName: 'Joan',
joinedAt: moment().toDate(),
activities: [
{
type: 'activity',
username: 'joan',
timestamp: '2020-05-27T15:13:30Z',
platform: PlatformType.GITHUB,
sourceId: '#sourceId1',
},
],
},
{
username: {
github: {
username: 'anil',
integrationId: generateUUIDv1(),
},
},
displayName: 'anil',
joinedAt: moment().toDate(),
activities: [
{
username: 'anil',
type: 'activity',
timestamp: '2020-04-27T15:13:30Z',
platform: PlatformType.SLACK,
sourceId: '#sourceId2',
},
],
},
{
username: {
github: {
username: 'uros',
integrationId: generateUUIDv1(),
},
},
displayName: 'uros',
joinedAt: moment().toDate(),
activities: [
{
type: 'activity',
username: 'uros',
timestamp: '2020-03-27T15:13:30Z',
platform: PlatformType.TWITTER,
sourceId: '#sourceId3',
},
],
},
])
const org2 = await createOrganization(piedpiper, mockIRepositoryOptions, [
{
username: {
github: {
username: 'mario',
integrationId: generateUUIDv1(),
},
},
displayName: 'mario',
joinedAt: moment().toDate(),
activities: [
{
type: 'activity',
username: 'mario',
timestamp: '2022-03-27T15:13:30Z',
platform: PlatformType.DEVTO,
sourceId: '#sourceId4',
},
],
},
{
username: {
github: {
username: 'igor',
integrationId: generateUUIDv1(),
},
},
displayName: 'igor',
joinedAt: moment().toDate(),
activities: [
{
type: 'activity',
username: 'igor',
timestamp: '2022-02-27T15:13:30Z',
platform: PlatformType.DEVTO,
sourceId: '#sourceId5',
},
],
},
])
await createOrganization(hooli, mockIRepositoryOptions)

const found = await OrganizationRepository.findAndCountAll(
{
advancedFilter: {
joinedAt: {
gte: '2022-02-27',
},
},
},
mockIRepositoryOptions,
)

delete org2.members

expect(found.count).toBe(1)
expect(found.rows.sort((a, b) => (a.createdAt > b.createdAt ? 1 : -1))).toStrictEqual([org2])
})

it('Should work with advanced filters', async () => {
const mockIRepositoryOptions = await SequelizeTestUtils.getTestIRepositoryOptions(db)
await createOrganization(crowddev, mockIRepositoryOptions, [
Expand Down
28 changes: 17 additions & 11 deletions backend/src/database/repositories/organizationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,10 @@ class OrganizationRepository {
`
WITH
activity_counts AS (
SELECT mo."organizationId", COUNT(a.id) AS "activityCount"
FROM "memberOrganizations" mo
LEFT JOIN activities a ON a."memberId" = mo."memberId"
WHERE mo."organizationId" = :id
GROUP BY mo."organizationId"
SELECT "organizationId", COUNT(id) AS "activityCount"
FROM activities
WHERE "organizationId" = :id
GROUP BY "organizationId"
),
member_counts AS (
SELECT "organizationId", COUNT(DISTINCT "memberId") AS "memberCount"
Expand All @@ -388,12 +387,11 @@ class OrganizationRepository {
GROUP BY "organizationId"
),
active_on AS (
SELECT mo."organizationId", ARRAY_AGG(DISTINCT platform) AS "activeOn"
FROM "memberOrganizations" mo
JOIN activities a ON a."memberId" = mo."memberId"
WHERE mo."organizationId" = :id
GROUP BY mo."organizationId"
),
SELECT "organizationId", ARRAY_AGG(DISTINCT platform) AS "activeOn"
FROM activities
WHERE "organizationId" = :id
GROUP BY "organizationId"
),
identities AS (
SELECT "organizationId", ARRAY_AGG(DISTINCT platform) AS "identities"
FROM "memberOrganizations" mo
Expand Down Expand Up @@ -600,6 +598,14 @@ class OrganizationRepository {

const translator = FieldTranslatorFactory.getTranslator(OpenSearchIndex.ORGANIZATIONS)

if (filter.and) {
filter.and.push({
activityCount: {
gt: 0,
},
})
}

const parsed = OpensearchQueryParser.parse(
{ filter, limit, offset, orderBy },
OpenSearchIndex.ORGANIZATIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
label="Headline"
prop="headline"
width="300"
sortable
>
<template #default="scope">
<router-link
Expand All @@ -132,10 +131,10 @@
>
<div class="mr-4">
<span
v-if="scope.row.headline"
v-if="scope.row.headline || scope.row.description"
class="text-sm h-full flex items-center text-gray-900"
>
{{ scope.row.headline }}
{{ scope.row.headline || scope.row.description }}
</span>
<span
v-else
Expand Down Expand Up @@ -348,7 +347,6 @@
label="Location"
width="150"
prop="location"
sortable
>
<template #default="scope">
<router-link
Expand Down Expand Up @@ -377,7 +375,6 @@
label="Industry"
width="150"
prop="industry"
sortable
>
<template #default="scope">
<router-link
Expand Down Expand Up @@ -406,7 +403,6 @@
label="Headcount"
width="150"
prop="size"
sortable
>
<template #default="scope">
<router-link
Expand Down Expand Up @@ -435,7 +431,6 @@
label="Type"
width="150"
prop="type"
sortable
>
<template #default="scope">
<router-link
Expand Down