Skip to content

Commit

Permalink
handle empty arrays
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Krick <matt.krick@gmail.com>
  • Loading branch information
mattkrick committed Sep 27, 2024
1 parent f2d5f15 commit 882cb0b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 41 deletions.
1 change: 1 addition & 0 deletions packages/server/dataloader/customRedisQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import getKysely from '../postgres/getKysely'
// All results must be mapped to their ids!
const customRedisQueries = {
endTimesByTemplateId: async (templateIds: string[]) => {
if (!templateIds.length) return []
const pg = getKysely()
const aQuarterAgo = new Date(Date.now() - ms('90d'))
const meetings = await pg
Expand Down
12 changes: 7 additions & 5 deletions packages/server/graphql/mutations/helpers/hideConversionModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ const hideConversionModal = async (orgId: string, dataLoader: DataLoaderWorker)
meeting.showConversionModal = false
})
const meetingIds = activeMeetings.map(({id}) => id)
await pg
.updateTable('NewMeeting')
.set({showConversionModal: false})
.where('id', 'in', meetingIds)
.execute()
if (meetingIds.length > 0) {
await pg
.updateTable('NewMeeting')
.set({showConversionModal: false})
.where('id', 'in', meetingIds)
.execute()
}
return activeMeetings
}
}
Expand Down
62 changes: 31 additions & 31 deletions packages/server/graphql/mutations/helpers/removeTeamMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,39 +140,39 @@ const removeTeamMember = async (
.run()

// Reassign facilitator for meetings this user is facilitating.
if (meetingIds) {
const facilitatingMeetings = await pg
.selectFrom('NewMeeting')
.select('id')
.where('id', 'in', meetingIds)
.where('facilitatorUserId', '=', userId)
.execute()

const facilitatingMeetings = await pg
.selectFrom('NewMeeting')
.select('id')
.where('id', 'in', meetingIds)
.where('facilitatorUserId', '=', userId)
.execute()

const newMeetingFacilitators = (
await dataLoader
.get('meetingMembersByMeetingId')
.loadMany(facilitatingMeetings.map((meeting) => meeting.id))
)
.filter(errorFilter)
.map((members) => members[0])
.filter((member) => !!member)

Promise.allSettled(
newMeetingFacilitators.map(async (newFacilitator) => {
if (!newFacilitator) {
// This user is the only meeting member, so do nothing.
// :TODO: (jmtaber129): Consider closing meetings where this user is the only meeting
// member.
return
}
await pg
.updateTable('NewMeeting')
.set({facilitatorUserId: newFacilitator.userId})
.where('id', '=', newFacilitator.meetingId)
.execute()
})
)
const newMeetingFacilitators = (
await dataLoader
.get('meetingMembersByMeetingId')
.loadMany(facilitatingMeetings.map((meeting) => meeting.id))
)
.filter(errorFilter)
.map((members) => members[0])
.filter((member) => !!member)

await Promise.allSettled(
newMeetingFacilitators.map(async (newFacilitator) => {
if (!newFacilitator) {
// This user is the only meeting member, so do nothing.
// :TODO: (jmtaber129): Consider closing meetings where this user is the only meeting
// member.
return
}
await pg
.updateTable('NewMeeting')
.set({facilitatorUserId: newFacilitator.userId})
.where('id', '=', newFacilitator.meetingId)
.execute()
})
)
}
return {
user,
notificationId,
Expand Down
8 changes: 3 additions & 5 deletions packages/server/graphql/private/mutations/hardDeleteUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ const hardDeleteUser: MutationResolvers['hardDeleteUser'] = async (
const teamIds = teamMembers.map(({teamId}) => teamId)
const meetingIds = meetingMembers.map(({meetingId}) => meetingId)

const discussions = await pg
.selectFrom('Discussion')
.select('id')
.where('id', 'in', teamIds)
.execute()
const discussions = teamIds.length
? await pg.selectFrom('Discussion').select('id').where('id', 'in', teamIds).execute()
: []
const teamDiscussionIds = discussions.map(({id}) => id)

// soft delete first for side effects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import getKysely from '../../../../postgres/getKysely'
// Warning: the query is very expensive
// TODO: store all calculations in the database, e.g. meeting.attendeeCount (see #7975)
const getActiveTeamCountByTeamIds = async (teamIds: string[]) => {
if (!teamIds.length) return 0
const r = await getRethink()
const pg = getKysely()
const meetingIdsByTeamId = await pg
Expand Down

0 comments on commit 882cb0b

Please sign in to comment.