Skip to content

Commit

Permalink
fix: insert discussion before comment (#10194)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Krick <[email protected]>
  • Loading branch information
mattkrick authored Sep 6, 2024
1 parent 7240929 commit 724a340
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import getRethink from '../../../database/rethinkDriver'
import AgendaItemsStage from '../../../database/types/AgendaItemsStage'
import MeetingAction from '../../../database/types/MeetingAction'
import getKysely from '../../../postgres/getKysely'
import insertDiscussions from '../../../postgres/queries/insertDiscussions'
import getPhase from '../../../utils/getPhase'
import {DataLoaderWorker} from '../../graphql'

Expand Down Expand Up @@ -47,16 +46,20 @@ const addAgendaItemToActiveActionMeeting = async (
updatedAt: now
})
.run(),
getKysely().updateTable('AgendaItem').set({meetingId}).where('id', '=', agendaItemId).execute(),
insertDiscussions([
{
id: discussionId,
teamId,
meetingId,
discussionTopicType: 'agendaItem' as const,
discussionTopicId: agendaItemId
}
])
getKysely()
.with('InsertDiscussion', (qb) =>
qb.insertInto('Discussion').values({
id: discussionId,
teamId,
meetingId,
discussionTopicType: 'agendaItem',
discussionTopicId: agendaItemId
})
)
.updateTable('AgendaItem')
.set({meetingId})
.where('id', '=', agendaItemId)
.execute()
])

return meetingId
Expand Down
52 changes: 33 additions & 19 deletions packages/server/graphql/mutations/helpers/createNewMeetingPhases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import TeamHealthPhase from '../../../database/types/TeamHealthPhase'
import TeamHealthStage from '../../../database/types/TeamHealthStage'
import UpdatesPhase from '../../../database/types/UpdatesPhase'
import UpdatesStage from '../../../database/types/UpdatesStage'
import insertDiscussions from '../../../postgres/queries/insertDiscussions'
import getKysely from '../../../postgres/getKysely'
import {MeetingTypeEnum} from '../../../postgres/types/Meeting'
import isPhaseAvailable from '../../../utils/isPhaseAvailable'
import {DataLoaderWorker} from '../../graphql'
Expand Down Expand Up @@ -77,6 +77,7 @@ const createNewMeetingPhases = async (
meetingType: MeetingTypeEnum,
dataLoader: DataLoaderWorker
) => {
const pg = getKysely()
const [meetingSettings, stageDurations, team] = await Promise.all([
dataLoader.get('meetingSettingsByType').load({teamId, meetingType}),
getPastStageDurations(teamId),
Expand Down Expand Up @@ -108,17 +109,22 @@ const createNewMeetingPhases = async (
case DISCUSS:
const discussPhase = new DiscussPhase(durations)
const discussStages = discussPhase.stages.filter((stage) => stage.reflectionGroupId)
asyncSideEffects.push(
insertDiscussions(
discussStages.map((stage) => ({
id: stage.discussionId,
teamId,
meetingId,
discussionTopicId: stage.reflectionGroupId,
discussionTopicType: 'reflectionGroup' as const
}))
if (discussStages.length > 0) {
asyncSideEffects.push(
pg
.insertInto('Discussion')
.values(
discussStages.map((stage) => ({
id: stage.discussionId,
teamId,
meetingId,
discussionTopicId: stage.reflectionGroupId,
discussionTopicType: 'reflectionGroup'
}))
)
.execute()
)
)
}
return discussPhase
case UPDATES:
return new UpdatesPhase({durations, stages: [new UpdatesStage(facilitatorTeamMemberId)]})
Expand All @@ -127,14 +133,22 @@ const createNewMeetingPhases = async (
const agendaItemIds = agendaItems.map(({id}) => id)
const agendaItemPhase = new AgendaItemsPhase(agendaItemIds, durations)
const {stages} = agendaItemPhase
const discussions = stages.map((stage) => ({
id: stage.discussionId,
teamId,
meetingId,
discussionTopicId: stage.agendaItemId,
discussionTopicType: 'agendaItem' as const
}))
asyncSideEffects.push(insertDiscussions(discussions))
if (stages.length > 0) {
asyncSideEffects.push(
pg
.insertInto('Discussion')
.values(
stages.map((stage) => ({
id: stage.discussionId,
teamId,
meetingId,
discussionTopicId: stage.agendaItemId,
discussionTopicType: 'agendaItem'
}))
)
.execute()
)
}
return agendaItemPhase
case 'ESTIMATE':
return new EstimatePhase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import DiscussStage from '../../../database/types/DiscussStage'
import GenericMeetingStage from '../../../database/types/GenericMeetingStage'
import MeetingRetrospective from '../../../database/types/MeetingRetrospective'
import getKysely from '../../../postgres/getKysely'
import insertDiscussions from '../../../postgres/queries/insertDiscussions'
import {AnyMeeting} from '../../../postgres/types/Meeting'
import {DataLoaderWorker} from '../../graphql'
import addAIGeneratedContentToThreads from './addAIGeneratedContentToThreads'
Expand All @@ -28,12 +27,11 @@ const handleCompletedRetrospectiveStage = async (
meeting: MeetingRetrospective,
dataLoader: DataLoaderWorker
) => {
const pg = getKysely()
if (stage.phaseType === REFLECT || stage.phaseType === GROUP) {
const data: Record<string, any> = await removeEmptyReflections(meeting, dataLoader)

if (stage.phaseType === REFLECT) {
const pg = getKysely()

const [reflectionGroups, unsortedReflections] = await Promise.all([
dataLoader.get('retroReflectionGroupsByMeetingId').load(meeting.id),
dataLoader.get('retroReflectionsByMeetingId').load(meeting.id)
Expand Down Expand Up @@ -93,7 +91,9 @@ const handleCompletedRetrospectiveStage = async (
discussionTopicId: stage.reflectionGroupId
}))
// discussions must exist before we can add comments to them!
await insertDiscussions(discussions)
if (discussions.length > 0) {
await pg.insertInto('Discussion').values(discussions).execute()
}
await Promise.all([
addAIGeneratedContentToThreads(discussPhaseStages, meetingId, dataLoader),
publishToEmbedder({jobType: 'relatedDiscussions:start', data: {meetingId}, priority: 0})
Expand Down
13 changes: 7 additions & 6 deletions packages/server/graphql/mutations/joinMeeting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import RetroMeetingMember from '../../database/types/RetroMeetingMember'
import TeamPromptMeetingMember from '../../database/types/TeamPromptMeetingMember'
import TeamPromptResponseStage from '../../database/types/TeamPromptResponseStage'
import UpdatesStage from '../../database/types/UpdatesStage'
import insertDiscussions from '../../postgres/queries/insertDiscussions'
import getKysely from '../../postgres/getKysely'
import {TeamMember} from '../../postgres/types'
import {analytics} from '../../utils/analytics/analytics'
import {getUserId, isTeamMember} from '../../utils/authorization'
Expand Down Expand Up @@ -145,15 +145,16 @@ const joinMeeting = {
// only add a new stage for the new users (ie. invited to the team after the meeting was started)
if (teamMemberResponseStage) return
const responsesStage = new TeamPromptResponseStage({teamMemberId})
await insertDiscussions([
{
await getKysely()
.insertInto('Discussion')
.values({
id: responsesStage.discussionId,
teamId,
meetingId,
discussionTopicId: teamMemberId,
discussionTopicType: 'teamPromptResponse' as const
}
])
discussionTopicType: 'teamPromptResponse'
})
.execute()
return addStageToPhase(responsesStage, 'RESPONSES')
}

Expand Down
9 changes: 5 additions & 4 deletions packages/server/graphql/mutations/updatePokerScope.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {GraphQLID, GraphQLList, GraphQLNonNull} from 'graphql'
import {Insertable} from 'kysely'
import {SubscriptionChannel, Threshold} from 'parabol-client/types/constEnums'
import {Writeable} from '../../../client/types/generics'
import {ESTIMATE_TASK_SORT_ORDER} from '../../../client/utils/constants'
import getRethink from '../../database/rethinkDriver'
import EstimateStage from '../../database/types/EstimateStage'
import MeetingPoker from '../../database/types/MeetingPoker'
import {TaskServiceEnum} from '../../database/types/Task'
import insertDiscussions, {InputDiscussions} from '../../postgres/queries/insertDiscussions'
import getKysely from '../../postgres/getKysely'
import {Discussion} from '../../postgres/pg'
import RedisLockQueue from '../../utils/RedisLockQueue'
import {getUserId, isTeamMember} from '../../utils/authorization'
import getPhase from '../../utils/getPhase'
Expand Down Expand Up @@ -112,7 +113,7 @@ const updatePokerScope = {
// add stages
const templateRef = await dataLoader.get('templateRefs').loadNonNull(templateRefId)
const {dimensions} = templateRef
const newDiscussions = [] as Writeable<InputDiscussions>
const newDiscussions = [] as Insertable<Discussion>[]
const additiveUpdates = updates.filter((update) => {
const {action, serviceTaskId} = update
return action === 'ADD' && !stages.find((stage) => stage.serviceTaskId === serviceTaskId)
Expand Down Expand Up @@ -168,7 +169,7 @@ const updatePokerScope = {
})
.run()
if (newDiscussions.length > 0) {
await insertDiscussions(newDiscussions)
await getKysely().insertInto('Discussion').values(newDiscussions).execute()
}
const data = {meetingId, newStageIds}
publish(SubscriptionChannel.MEETING, meetingId, 'UpdatePokerScopeSuccess', data, subOptions)
Expand Down
15 changes: 0 additions & 15 deletions packages/server/postgres/queries/insertDiscussions.ts

This file was deleted.

This file was deleted.

0 comments on commit 724a340

Please sign in to comment.