fix: platform gcal connect reconnect credentials (#14513)

* fix: enable gcal connect to reconnect revoked google credentials

* feat: callback to react when check fails
This commit is contained in:
Morgan authored and GitHub committed 2024-04-11 09:36:35 +00:00
1 parent 3fcba33b1b
commit 621067acd8
7 files changed
+94 -11

No files matched your search

@@ -9,16 +9,29 @@ import { APPS_TYPE_ID_MAPPING } from "@calcom/platform-constants";
export class CredentialsRepository {
constructor(private readonly dbRead: PrismaReadService, private readonly dbWrite: PrismaWriteService) {}
createAppCredential(type: keyof typeof APPS_TYPE_ID_MAPPING, key: Prisma.InputJsonValue, userId: number) {
return this.dbWrite.prisma.credential.create({
data: {
async createAppCredential(
type: keyof typeof APPS_TYPE_ID_MAPPING,
key: Prisma.InputJsonValue,
userId: number
) {
const credential = await this.getByTypeAndUserId(type, userId);
return this.dbWrite.prisma.credential.upsert({
create: {
type,
key,
userId,
appId: APPS_TYPE_ID_MAPPING[type],
},
update: {
key,
invalid: false,
},
where: {
id: credential?.id,
},
});
}
getByTypeAndUserId(type: string, userId: number) {
return this.dbWrite.prisma.credential.findFirst({ where: { type, userId } });
}
@@ -7,13 +7,26 @@ export class SelectedCalendarsRepository {
constructor(private readonly dbRead: PrismaReadService, private readonly dbWrite: PrismaWriteService) {}
createSelectedCalendar(externalId: string, credentialId: number, userId: number, integration: string) {
return this.dbWrite.prisma.selectedCalendar.create({
data: {
return this.dbWrite.prisma.selectedCalendar.upsert({
create: {
userId,
externalId,
credentialId,
integration,
},
update: {
userId,
externalId,
credentialId,
integration,
},
where: {
userId_integration_externalId: {
userId,
integration,
externalId,
},
},
});
}