Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add functionality to change templates during a retro (#9544)
- Loading branch information
1 parent
2171065
commit e6434e1
Showing
9 changed files
with
188 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/client/mutations/UpdateMeetingTemplateMutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import graphql from 'babel-plugin-relay/macro' | ||
import {commitMutation} from 'react-relay' | ||
import {StandardMutation} from '../types/relayMutations' | ||
import {UpdateMeetingTemplateMutation as TUpdateMeetingTemplateMutation} from '../__generated__/UpdateMeetingTemplateMutation.graphql' | ||
|
||
graphql` | ||
fragment UpdateMeetingTemplateMutation_meeting on UpdateMeetingTemplateSuccess { | ||
meeting { | ||
... on RetrospectiveMeeting { | ||
id | ||
templateId | ||
phases { | ||
id | ||
... on ReflectPhase { | ||
reflectPrompts { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` | ||
|
||
const mutation = graphql` | ||
mutation UpdateMeetingTemplateMutation($meetingId: ID!, $templateId: ID!) { | ||
updateMeetingTemplate(meetingId: $meetingId, templateId: $templateId) { | ||
... on ErrorPayload { | ||
error { | ||
message | ||
} | ||
} | ||
...UpdateMeetingTemplateMutation_meeting @relay(mask: false) | ||
} | ||
} | ||
` | ||
|
||
const UpdateMeetingTemplateMutation: StandardMutation<TUpdateMeetingTemplateMutation> = ( | ||
atmosphere, | ||
variables, | ||
{onError, onCompleted} | ||
) => { | ||
return commitMutation<TUpdateMeetingTemplateMutation>(atmosphere, { | ||
mutation, | ||
variables, | ||
onCompleted, | ||
onError | ||
}) | ||
} | ||
|
||
export default UpdateMeetingTemplateMutation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/server/graphql/public/mutations/updateMeetingTemplate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {SubscriptionChannel} from '../../../../client/types/constEnums' | ||
import getRethink from '../../../database/rethinkDriver' | ||
import MeetingRetrospective from '../../../database/types/MeetingRetrospective' | ||
import {getUserId, isTeamMember} from '../../../utils/authorization' | ||
import getPhase from '../../../utils/getPhase' | ||
import publish from '../../../utils/publish' | ||
import standardError from '../../../utils/standardError' | ||
import {MutationResolvers} from '../resolverTypes' | ||
|
||
const updateMeetingTemplate: MutationResolvers['updateMeetingTemplate'] = async ( | ||
_source, | ||
{meetingId, templateId}, | ||
{authToken, dataLoader, socketId: mutatorId} | ||
) => { | ||
const viewerId = getUserId(authToken) | ||
const r = await getRethink() | ||
const operationId = dataLoader.share() | ||
const subOptions = {mutatorId, operationId} | ||
const meeting = (await dataLoader.get('newMeetings').load(meetingId)) as MeetingRetrospective | ||
if (!meeting) return standardError(new Error('Meeting not found'), {userId: viewerId}) | ||
if (!isTeamMember(authToken, meeting.teamId)) { | ||
return standardError(new Error('Team not found'), {userId: viewerId}) | ||
} | ||
const reflections = await dataLoader.get('retroReflectionsByMeetingId').load(meetingId) | ||
if (reflections.length > 0) { | ||
return standardError(new Error('Cannot change template after reflections have been created'), { | ||
userId: viewerId | ||
}) | ||
} | ||
const reflectPhase = getPhase(meeting.phases, 'reflect') | ||
const hasCompletedReflectPhase = reflectPhase.stages.every((stage) => stage.isComplete) | ||
if (hasCompletedReflectPhase) { | ||
return standardError( | ||
new Error('Cannot change template after reflection phase has been completed'), | ||
{ | ||
userId: viewerId | ||
} | ||
) | ||
} | ||
|
||
await r.table('NewMeeting').get(meetingId).update({templateId}).run() | ||
meeting.templateId = templateId | ||
|
||
const data = {meetingId, templateId} | ||
publish(SubscriptionChannel.MEETING, meetingId, 'UpdateMeetingTemplateSuccess', data, subOptions) | ||
return data | ||
} | ||
|
||
export default updateMeetingTemplate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/server/graphql/public/typeDefs/updateMeetingTemplate.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
extend type Mutation { | ||
""" | ||
Update a meeting template | ||
""" | ||
updateMeetingTemplate( | ||
""" | ||
The id of the meeting | ||
""" | ||
meetingId: ID! | ||
""" | ||
The id of the meeting template | ||
""" | ||
templateId: ID! | ||
): UpdateMeetingTemplatePayload! | ||
} | ||
|
||
""" | ||
Return value for updateMeetingTemplate, which could be an error | ||
""" | ||
union UpdateMeetingTemplatePayload = ErrorPayload | UpdateMeetingTemplateSuccess | ||
|
||
type UpdateMeetingTemplateSuccess { | ||
""" | ||
The updated meeting | ||
""" | ||
meeting: NewMeeting! | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/server/graphql/public/types/UpdateMeetingTemplateSuccess.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {UpdateMeetingTemplateSuccessResolvers} from '../resolverTypes' | ||
|
||
export type UpdateMeetingTemplateSuccessSource = { | ||
meetingId: string | ||
} | ||
|
||
const UpdateMeetingTemplateSuccess: UpdateMeetingTemplateSuccessResolvers = { | ||
meeting: async ({meetingId}, _args, {dataLoader}) => { | ||
const meeting = await dataLoader.get('newMeetings').load(meetingId) | ||
return meeting | ||
} | ||
} | ||
|
||
export default UpdateMeetingTemplateSuccess |