diff --git a/packages/client/components/SelectMeetingDropdownItem.tsx b/packages/client/components/SelectMeetingDropdownItem.tsx index b6ee8e6fb42..8d5c9f340d5 100644 --- a/packages/client/components/SelectMeetingDropdownItem.tsx +++ b/packages/client/components/SelectMeetingDropdownItem.tsx @@ -55,7 +55,7 @@ const SelectMeetingDropdownItem = (props: Props) => { history.push(`/meet/${meetingId}`) } //FIXME 6062: change to React.ComponentType - const IconOrSVG = meetingTypeToIcon[meetingType] + const IconOrSVG = meetingTypeToIcon[meetingType]! const meetingPhase = getMeetingPhase(phases) const meetingPhaseLabel = (meetingPhase && phaseLabelLookup[meetingPhase.phaseType]) || 'Complete' diff --git a/packages/server/dataloader/customLoaderMakers.ts b/packages/server/dataloader/customLoaderMakers.ts index 0ceba9e5255..1743d3959d9 100644 --- a/packages/server/dataloader/customLoaderMakers.ts +++ b/packages/server/dataloader/customLoaderMakers.ts @@ -318,7 +318,7 @@ export const meetingSettingsByType = (parent: RootDataLoader) => { keys.forEach((key) => { const {meetingType} = key types[meetingType] = types[meetingType] || [] - types[meetingType].push(key.teamId) + types[meetingType]!.push(key.teamId) }) const entries = Object.entries(types) as [MeetingTypeEnum, string[]][] const resultsByType = await Promise.all( @@ -422,7 +422,7 @@ export const meetingTemplatesByType = (parent: RootDataLoader) => { keys.forEach((key) => { const {meetingType} = key types[meetingType] = types[meetingType] || [] - types[meetingType].push(key.teamId) + types[meetingType]!.push(key.teamId) }) const entries = Object.entries(types) as [MeetingTypeEnum, string[]][] const resultsByType = await Promise.all( diff --git a/packages/server/graphql/mutations/archiveTimelineEvent.ts b/packages/server/graphql/mutations/archiveTimelineEvent.ts index 7a30e9f89b6..f116011eece 100644 --- a/packages/server/graphql/mutations/archiveTimelineEvent.ts +++ b/packages/server/graphql/mutations/archiveTimelineEvent.ts @@ -4,6 +4,7 @@ import TimelineEventCheckinComplete from 'parabol-server/database/types/Timeline import TimelineEventRetroComplete from 'parabol-server/database/types/TimelineEventRetroComplete' import getRethink from '../../database/rethinkDriver' import {TimelineEventEnum} from '../../database/types/TimelineEvent' +import getKysely from '../../postgres/getKysely' import {getUserId, isTeamMember} from '../../utils/authorization' import publish from '../../utils/publish' import standardError from '../../utils/standardError' @@ -57,7 +58,15 @@ const archiveTimelineEvent = { .get('timelineEventsByMeetingId') .load(meetingId) const eventIds = meetingTimelineEvents.map(({id}) => id) - await r.table('TimelineEvent').getAll(r.args(eventIds)).update({isActive: false}).run() + const pg = getKysely() + await Promise.all([ + pg + .updateTable('TimelineEvent') + .set({isActive: false}) + .where('id', 'in', eventIds) + .execute(), + r.table('TimelineEvent').getAll(r.args(eventIds)).update({isActive: false}).run() + ]) meetingTimelineEvents.map((event) => { const {id: timelineEventId, userId} = event publish( diff --git a/packages/server/graphql/mutations/endCheckIn.ts b/packages/server/graphql/mutations/endCheckIn.ts index 38b63ef12d0..71a0b38313e 100644 --- a/packages/server/graphql/mutations/endCheckIn.ts +++ b/packages/server/graphql/mutations/endCheckIn.ts @@ -11,6 +11,7 @@ import MeetingAction from '../../database/types/MeetingAction' import Task from '../../database/types/Task' import TimelineEventCheckinComplete from '../../database/types/TimelineEventCheckinComplete' import generateUID from '../../generateUID' +import getKysely from '../../postgres/getKysely' import archiveTasksForDB from '../../safeMutations/archiveTasksForDB' import removeSuggestedAction from '../../safeMutations/removeSuggestedAction' import {Logger} from '../../utils/Logger' @@ -244,7 +245,11 @@ export default { }) ) const timelineEventId = events[0]!.id - await r.table('TimelineEvent').insert(events).run() + const pg = getKysely() + await Promise.all([ + pg.insertInto('TimelineEvent').values(events).execute(), + r.table('TimelineEvent').insert(events).run() + ]) if (team.isOnboardTeam) { const teamLeadUserId = await r .table('TeamMember') diff --git a/packages/server/graphql/mutations/endSprintPoker.ts b/packages/server/graphql/mutations/endSprintPoker.ts index 14fa0fbb449..250fc524130 100644 --- a/packages/server/graphql/mutations/endSprintPoker.ts +++ b/packages/server/graphql/mutations/endSprintPoker.ts @@ -7,6 +7,7 @@ import getRethink from '../../database/rethinkDriver' import Meeting from '../../database/types/Meeting' import MeetingPoker from '../../database/types/MeetingPoker' import TimelineEventPokerComplete from '../../database/types/TimelineEventPokerComplete' +import getKysely from '../../postgres/getKysely' import {Logger} from '../../utils/Logger' import {analytics} from '../../utils/analytics/analytics' import {getUserId, isSuperUser, isTeamMember} from '../../utils/authorization' @@ -127,7 +128,11 @@ export default { meetingId }) ) - await r.table('TimelineEvent').insert(events).run() + const pg = getKysely() + await Promise.all([ + pg.insertInto('TimelineEvent').values(events).execute(), + r.table('TimelineEvent').insert(events).run() + ]) const data = { meetingId, diff --git a/packages/server/graphql/mutations/helpers/bootstrapNewUser.ts b/packages/server/graphql/mutations/helpers/bootstrapNewUser.ts index b3a79ed611f..b2100882ef4 100644 --- a/packages/server/graphql/mutations/helpers/bootstrapNewUser.ts +++ b/packages/server/graphql/mutations/helpers/bootstrapNewUser.ts @@ -6,8 +6,8 @@ import SuggestedActionTryTheDemo from '../../../database/types/SuggestedActionTr import TimelineEventJoinedParabol from '../../../database/types/TimelineEventJoinedParabol' import User from '../../../database/types/User' import generateUID from '../../../generateUID' +import getKysely from '../../../postgres/getKysely' import getUsersbyDomain from '../../../postgres/queries/getUsersByDomain' -import insertUser from '../../../postgres/queries/insertUser' import IUser from '../../../postgres/types/IUser' import acceptTeamInvitation from '../../../safeMutations/acceptTeamInvitation' import {analytics} from '../../../utils/analytics/analytics' @@ -57,13 +57,22 @@ const bootstrapNewUser = async ( const hasSAMLURL = !!(await getSAMLURLFromEmail(email, dataLoader, false)) const isQualifiedForAutoJoin = (isVerified || hasSAMLURL) && isCompanyDomain const orgIds = organizations.map(({id}) => id) - + const pg = getKysely() const [teamsWithAutoJoinRes] = await Promise.all([ isQualifiedForAutoJoin ? dataLoader.get('autoJoinTeamsByOrgId').loadMany(orgIds) : [], - insertUser({...newUser, isPatient0, featureFlags: experimentalFlags}), - r({ - event: r.table('TimelineEvent').insert(joinEvent) - }).run() + pg + .with('User', (qc) => + qc.insertInto('User').values({ + ...newUser, + isPatient0, + featureFlags: experimentalFlags, + identities: newUser.identities.map((identity) => JSON.stringify(identity)) + }) + ) + .insertInto('TimelineEvent') + .values(joinEvent) + .execute(), + r.table('TimelineEvent').insert(joinEvent).run() ]) // Identify the user so user properties are set before any events are sent diff --git a/packages/server/graphql/mutations/helpers/createTeamAndLeader.ts b/packages/server/graphql/mutations/helpers/createTeamAndLeader.ts index 2e972dd3e6f..c46773ded75 100644 --- a/packages/server/graphql/mutations/helpers/createTeamAndLeader.ts +++ b/packages/server/graphql/mutations/helpers/createTeamAndLeader.ts @@ -4,10 +4,8 @@ import MeetingSettingsPoker from '../../../database/types/MeetingSettingsPoker' import MeetingSettingsRetrospective from '../../../database/types/MeetingSettingsRetrospective' import Team from '../../../database/types/Team' import TimelineEventCreatedTeam from '../../../database/types/TimelineEventCreatedTeam' -import getPg from '../../../postgres/getPg' -import {insertTeamQuery} from '../../../postgres/queries/generated/insertTeamQuery' +import getKysely from '../../../postgres/getKysely' import IUser from '../../../postgres/types/IUser' -import catchAndLog from '../../../postgres/utils/catchAndLog' import addTeamIdToTMS from '../../../safeMutations/addTeamIdToTMS' import insertNewTeamMember from '../../../safeMutations/insertNewTeamMember' @@ -38,8 +36,13 @@ export default async function createTeamAndLeader(user: IUser, newTeam: ValidNew orgId }) + const pg = getKysely() await Promise.all([ - catchAndLog(() => insertTeamQuery.run(verifiedTeam, getPg())), + pg + .with('Team', (qc) => qc.insertInto('Team').values(verifiedTeam)) + .insertInto('TimelineEvent') + .values(timelineEvent) + .execute(), // add meeting settings r.table('MeetingSettings').insert(meetingSettings).run(), // denormalize common fields to team member diff --git a/packages/server/graphql/mutations/helpers/notifications/MSTeamsNotifier.ts b/packages/server/graphql/mutations/helpers/notifications/MSTeamsNotifier.ts index 452791fb341..23159529393 100644 --- a/packages/server/graphql/mutations/helpers/notifications/MSTeamsNotifier.ts +++ b/packages/server/graphql/mutations/helpers/notifications/MSTeamsNotifier.ts @@ -92,7 +92,7 @@ export const MSTeamsNotificationHelper: NotificationIntegrationHelper { - identities: AuthIdentity[] -} - -type Diff = T extends U ? never : T - -type RequiredExceptFor = Pick> & - Partial - -type InsertUserQueryParamsWithoutPseudoId = RequiredExceptFor - -const insertUser = async (user: InsertUserQueryParamsWithoutPseudoId) => { - await catchAndLog(() => insertUserQuery.run(user as unknown as IInsertUserQueryParams, getPg())) -} - -export default insertUser diff --git a/packages/server/postgres/queries/src/insertTeamQuery.sql b/packages/server/postgres/queries/src/insertTeamQuery.sql deleted file mode 100644 index e2caacf620c..00000000000 --- a/packages/server/postgres/queries/src/insertTeamQuery.sql +++ /dev/null @@ -1,30 +0,0 @@ -/* - @name insertTeamQuery -*/ -INSERT INTO "Team" ( - "id", - "autoJoin", - "name", - "createdAt", - "createdBy", - "isArchived", - "isPaid", - "lastMeetingType", - "tier", - "orgId", - "isOnboardTeam", - "updatedAt" -) VALUES ( - :id, - :autoJoin, - :name, - :createdAt, - :createdBy, - :isArchived, - :isPaid, - :lastMeetingType, - :tier, - :orgId, - :isOnboardTeam, - :updatedAt -); diff --git a/packages/server/postgres/queries/src/insertUserQuery.sql b/packages/server/postgres/queries/src/insertUserQuery.sql deleted file mode 100644 index 6833ba3dc6d..00000000000 --- a/packages/server/postgres/queries/src/insertUserQuery.sql +++ /dev/null @@ -1,36 +0,0 @@ -/* - @name insertUserQuery -*/ -INSERT INTO "User" ( - "id", - "email", - "createdAt", - "updatedAt", - "inactive", - "lastSeenAt", - "preferredName", - "tier", - "picture", - "tms", - "featureFlags", - "lastSeenAtURLs", - "pseudoId", - "identities", - "isPatient0" -) VALUES ( - :id, - :email, - :createdAt, - :updatedAt, - :inactive, - :lastSeenAt, - :preferredName, - :tier, - :picture, - :tms, - :featureFlags, - :lastSeenAtURLs, - :pseudoId, - :identities, - :isPatient0 -);