Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update MeetingTemplate.updatedAt on prompt changes #9829

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/server/database/rethinkDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export type RethinkSchema = {
}
TemplateDimension: {
type: TemplateDimension
index: 'teamId' | 'templateId'
index: 'teamId' | 'templateId' | 'scaleId'
}
TemplateScale: {
type: TemplateScale
Expand Down
11 changes: 10 additions & 1 deletion packages/server/graphql/mutations/addPokerTemplateDimension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dndNoise from 'parabol-client/utils/dndNoise'
import getRethink from '../../database/rethinkDriver'
import {RDatum} from '../../database/stricterR'
import TemplateDimension from '../../database/types/TemplateDimension'
import getKysely from '../../postgres/getKysely'
import {getUserId, isTeamMember} from '../../utils/authorization'
import publish from '../../utils/publish'
import standardError from '../../utils/standardError'
Expand All @@ -24,6 +25,7 @@ const addPokerTemplateDimension = {
{authToken, dataLoader, socketId: mutatorId}: GQLContext
) {
const r = await getRethink()
const pg = getKysely()
const operationId = dataLoader.share()
const subOptions = {operationId, mutatorId}
const template = await dataLoader.get('meetingTemplates').load(templateId)
Expand Down Expand Up @@ -73,7 +75,14 @@ const addPokerTemplateDimension = {
templateId
})

await r.table('TemplateDimension').insert(newDimension).run()
await Promise.all([
r.table('TemplateDimension').insert(newDimension).run(),
pg
.updateTable('MeetingTemplate')
.set({updatedAt: new Date()})
.where('id', '=', templateId)
.execute()
])

const dimensionId = newDimension.id
const data = {dimensionId}
Expand Down
14 changes: 14 additions & 0 deletions packages/server/graphql/mutations/addPokerTemplateScaleValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {SubscriptionChannel} from 'parabol-client/types/constEnums'
import getRethink from '../../database/rethinkDriver'
import {RDatum} from '../../database/stricterR'
import TemplateScale from '../../database/types/TemplateScale'
import getKysely from '../../postgres/getKysely'
import {getUserId, isTeamMember} from '../../utils/authorization'
import publish from '../../utils/publish'
import standardError from '../../utils/standardError'
Expand Down Expand Up @@ -32,6 +33,7 @@ const addPokerTemplateScaleValue = {
{authToken, dataLoader, socketId: mutatorId}: GQLContext
) {
const r = await getRethink()
const pg = getKysely()
const now = new Date()
const operationId = dataLoader.share()
const subOptions = {operationId, mutatorId}
Expand Down Expand Up @@ -84,6 +86,18 @@ const addPokerTemplateScaleValue = {
})
}

// mark all templates using this scale as updated
const updatedDimensions = await r
.table('TemplateDimension')
.getAll(scaleId, {index: 'scaleId'})
.run()
const updatedTemplateIds = updatedDimensions.map(({templateId}) => templateId)
await pg
.updateTable('MeetingTemplate')
.set({updatedAt: now})
.where('id', 'in', updatedTemplateIds)
.execute()

const data = {scaleId}
publish(
SubscriptionChannel.TEAM,
Expand Down
11 changes: 10 additions & 1 deletion packages/server/graphql/mutations/addReflectTemplatePrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import palettePickerOptions from '../../../client/styles/palettePickerOptions'
import {PALETTE} from '../../../client/styles/paletteV3'
import getRethink from '../../database/rethinkDriver'
import RetrospectivePrompt from '../../database/types/RetrospectivePrompt'
import getKysely from '../../postgres/getKysely'
import {getUserId, isTeamMember} from '../../utils/authorization'
import publish from '../../utils/publish'
import standardError from '../../utils/standardError'
Expand All @@ -25,6 +26,7 @@ const addReflectTemplatePrompt = {
{authToken, dataLoader, socketId: mutatorId}: GQLContext
) {
const r = await getRethink()
const pg = getKysely()
const operationId = dataLoader.share()
const subOptions = {operationId, mutatorId}
const template = await dataLoader.get('meetingTemplates').load(templateId)
Expand Down Expand Up @@ -69,7 +71,14 @@ const addReflectTemplatePrompt = {
removedAt: null
})

await r.table('ReflectPrompt').insert(reflectPrompt).run()
await Promise.all([
await r.table('ReflectPrompt').insert(reflectPrompt).run(),
pg
.updateTable('MeetingTemplate')
.set({updatedAt: new Date()})
.where('id', '=', templateId)
.execute()
])

const promptId = reflectPrompt.id
const data = {promptId}
Expand Down
24 changes: 15 additions & 9 deletions packages/server/graphql/mutations/movePokerTemplateDimension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {GraphQLFloat, GraphQLID, GraphQLNonNull} from 'graphql'
import {SubscriptionChannel} from 'parabol-client/types/constEnums'
import getRethink from '../../database/rethinkDriver'
import getKysely from '../../postgres/getKysely'
import {getUserId, isTeamMember} from '../../utils/authorization'
import publish from '../../utils/publish'
import standardError from '../../utils/standardError'
Expand All @@ -24,6 +25,7 @@ const movePokerTemplateDimension = {
{authToken, dataLoader, socketId: mutatorId}: GQLContext
) {
const r = await getRethink()
const pg = getKysely()
const now = new Date()
const operationId = dataLoader.share()
const subOptions = {operationId, mutatorId}
Expand All @@ -39,16 +41,20 @@ const movePokerTemplateDimension = {
}

// RESOLUTION
await r
.table('TemplateDimension')
.get(dimensionId)
.update({
sortOrder,
updatedAt: now
})
.run()
const {teamId, templateId} = dimension

await Promise.all([
r
.table('TemplateDimension')
.get(dimensionId)
.update({
sortOrder,
updatedAt: now
})
.run(),
pg.updateTable('MeetingTemplate').set({updatedAt: now}).where('id', '=', templateId).execute()
])

const {teamId} = dimension
const data = {dimensionId}
publish(SubscriptionChannel.TEAM, teamId, 'MovePokerTemplateDimensionPayload', data, subOptions)
return data
Expand Down
13 changes: 13 additions & 0 deletions packages/server/graphql/mutations/movePokerTemplateScaleValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {GraphQLID, GraphQLInt, GraphQLNonNull, GraphQLString} from 'graphql'
import {SubscriptionChannel} from 'parabol-client/types/constEnums'
import getRethink from '../../database/rethinkDriver'
import {RValue} from '../../database/stricterR'
import getKysely from '../../postgres/getKysely'
import {getUserId, isTeamMember} from '../../utils/authorization'
import publish from '../../utils/publish'
import standardError from '../../utils/standardError'
Expand Down Expand Up @@ -30,6 +31,7 @@ const movePokerTemplateScaleValue = {
{authToken, dataLoader, socketId: mutatorId}: GQLContext
) => {
const r = await getRethink()
const pg = getKysely()
const viewerId = getUserId(authToken)
const now = new Date()
const operationId = dataLoader.share()
Expand Down Expand Up @@ -66,6 +68,17 @@ const movePokerTemplateScaleValue = {
updatedAt: now
}))
.run()
// mark all templates using this scale as updated
const updatedDimensions = await r
.table('TemplateDimension')
.getAll(scaleId, {index: 'scaleId'})
.run()
const updatedTemplateIds = updatedDimensions.map(({templateId}) => templateId)
await pg
.updateTable('MeetingTemplate')
.set({updatedAt: now})
.where('id', 'in', updatedTemplateIds)
.execute()

const data = {scaleId}
publish(
Expand Down
24 changes: 15 additions & 9 deletions packages/server/graphql/mutations/moveReflectTemplatePrompt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {GraphQLFloat, GraphQLID, GraphQLNonNull} from 'graphql'
import {SubscriptionChannel} from 'parabol-client/types/constEnums'
import getRethink from '../../database/rethinkDriver'
import getKysely from '../../postgres/getKysely'
import {getUserId, isTeamMember} from '../../utils/authorization'
import publish from '../../utils/publish'
import standardError from '../../utils/standardError'
Expand All @@ -24,6 +25,7 @@ const moveReflectTemplate = {
{authToken, dataLoader, socketId: mutatorId}: GQLContext
) {
const r = await getRethink()
const pg = getKysely()
const now = new Date()
const operationId = dataLoader.share()
const subOptions = {operationId, mutatorId}
Expand All @@ -39,16 +41,20 @@ const moveReflectTemplate = {
}

// RESOLUTION
await r
.table('ReflectPrompt')
.get(promptId)
.update({
sortOrder,
updatedAt: now
})
.run()
const {teamId, templateId} = prompt

await Promise.all([
r
.table('ReflectPrompt')
.get(promptId)
.update({
sortOrder,
updatedAt: now
})
.run(),
pg.updateTable('MeetingTemplate').set({updatedAt: now}).where('id', '=', templateId).execute()
])

const {teamId} = prompt
const data = {promptId}
publish(SubscriptionChannel.TEAM, teamId, 'MoveReflectTemplatePromptPayload', data, subOptions)
return data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {GraphQLID, GraphQLNonNull, GraphQLString} from 'graphql'
import {SubscriptionChannel} from 'parabol-client/types/constEnums'
import getRethink from '../../database/rethinkDriver'
import getKysely from '../../postgres/getKysely'
import {getUserId, isTeamMember} from '../../utils/authorization'
import publish from '../../utils/publish'
import standardError from '../../utils/standardError'
Expand All @@ -24,6 +25,7 @@ const reflectTemplatePromptUpdateDescription = {
{authToken, dataLoader, socketId: mutatorId}: GQLContext
) {
const r = await getRethink()
const pg = getKysely()
const now = new Date()
const operationId = dataLoader.share()
const subOptions = {operationId, mutatorId}
Expand All @@ -39,18 +41,21 @@ const reflectTemplatePromptUpdateDescription = {
}

// VALIDATION
const {teamId} = prompt
const {teamId, templateId} = prompt
const normalizedDescription = description.trim().slice(0, 256) || ''

// RESOLUTION
await r
.table('ReflectPrompt')
.get(promptId)
.update({
description: normalizedDescription,
updatedAt: now
})
.run()
await Promise.all([
r
.table('ReflectPrompt')
.get(promptId)
.update({
description: normalizedDescription,
updatedAt: now
})
.run(),
pg.updateTable('MeetingTemplate').set({updatedAt: now}).where('id', '=', templateId).execute()
])

const data = {promptId}
publish(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {GraphQLID, GraphQLNonNull, GraphQLString} from 'graphql'
import {SubscriptionChannel} from 'parabol-client/types/constEnums'
import getRethink from '../../database/rethinkDriver'
import getKysely from '../../postgres/getKysely'
import {getUserId, isTeamMember} from '../../utils/authorization'
import publish from '../../utils/publish'
import standardError from '../../utils/standardError'
Expand All @@ -24,6 +25,7 @@ const reflectTemplatePromptUpdateGroupColor = {
{authToken, dataLoader, socketId: mutatorId}: GQLContext
) {
const r = await getRethink()
const pg = getKysely()
const now = new Date()
const operationId = dataLoader.share()
const subOptions = {operationId, mutatorId}
Expand All @@ -40,17 +42,20 @@ const reflectTemplatePromptUpdateGroupColor = {
}

// VALIDATION
const {teamId} = prompt
const {teamId, templateId} = prompt

// RESOLUTION
await r
.table('ReflectPrompt')
.get(promptId)
.update({
groupColor,
updatedAt: now
})
.run()
await Promise.all([
r
.table('ReflectPrompt')
.get(promptId)
.update({
groupColor,
updatedAt: now
})
.run(),
pg.updateTable('MeetingTemplate').set({updatedAt: now}).where('id', '=', templateId).execute()
])

const data = {promptId}
publish(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {GraphQLID, GraphQLNonNull} from 'graphql'
import {SubscriptionChannel} from 'parabol-client/types/constEnums'
import getRethink from '../../database/rethinkDriver'
import {RDatum} from '../../database/stricterR'
import getKysely from '../../postgres/getKysely'
import {getUserId, isTeamMember} from '../../utils/authorization'
import publish from '../../utils/publish'
import standardError from '../../utils/standardError'
Expand All @@ -22,6 +23,7 @@ const removePokerTemplateDimension = {
{authToken, dataLoader, socketId: mutatorId}: GQLContext
) {
const r = await getRethink()
const pg = getKysely()
const now = new Date()
const operationId = dataLoader.share()
const subOptions = {operationId, mutatorId}
Expand Down Expand Up @@ -52,7 +54,10 @@ const removePokerTemplateDimension = {
}

// RESOLUTION
await r.table('TemplateDimension').get(dimensionId).update({removedAt: now}).run()
await Promise.all([
r.table('TemplateDimension').get(dimensionId).update({removedAt: now}).run(),
pg.updateTable('MeetingTemplate').set({updatedAt: now}).where('id', '=', templateId).execute()
])

const data = {dimensionId, templateId}
publish(
Expand Down
9 changes: 9 additions & 0 deletions packages/server/graphql/mutations/removePokerTemplateScale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {GraphQLID, GraphQLNonNull} from 'graphql'
import {SprintPokerDefaults, SubscriptionChannel} from 'parabol-client/types/constEnums'
import getRethink from '../../database/rethinkDriver'
import {RDatum} from '../../database/stricterR'
import getKysely from '../../postgres/getKysely'
import {getUserId, isTeamMember} from '../../utils/authorization'
import publish from '../../utils/publish'
import standardError from '../../utils/standardError'
Expand All @@ -22,6 +23,7 @@ const removePokerTemplateScale = {
{authToken, dataLoader, socketId: mutatorId}: GQLContext
) {
const r = await getRethink()
const pg = getKysely()
const now = new Date()
const operationId = dataLoader.share()
const subOptions = {operationId, mutatorId}
Expand Down Expand Up @@ -56,6 +58,13 @@ const removePokerTemplateScale = {
)('changes')('new_val')
.default([])
.run()
// mark templates as updated
const updatedTemplateIds = dimensions.map(({templateId}: any) => templateId)
await pg
.updateTable('MeetingTemplate')
.set({updatedAt: now})
.where('id', 'in', updatedTemplateIds)
.execute()

const data = {scaleId, dimensions}
publish(SubscriptionChannel.TEAM, teamId, 'RemovePokerTemplateScalePayload', data, subOptions)
Expand Down
Loading
Loading