fix: deprecated code in new credential sync endpoints (#14116)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { NextApiRequest } from "next";
|
||||
|
||||
import { defaultResponder } from "@calcom/lib/server";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { schemaCredentialDeleteParams } from "~/lib/validations/credential-sync";
|
||||
|
||||
@@ -40,12 +41,7 @@ import { schemaCredentialDeleteParams } from "~/lib/validations/credential-sync"
|
||||
* description: Credential syncing not enabled
|
||||
*/
|
||||
async function handler(req: NextApiRequest) {
|
||||
const { prisma } = req;
|
||||
|
||||
const { userId: reqUserId, credentialId: reqCredentialId } = schemaCredentialDeleteParams.parse(req.query);
|
||||
|
||||
const userId = parseInt(reqUserId);
|
||||
const credentialId = parseInt(reqCredentialId);
|
||||
const { userId, credentialId } = schemaCredentialDeleteParams.parse(req.query);
|
||||
|
||||
const credential = await prisma.credential.delete({
|
||||
where: {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { NextApiRequest } from "next";
|
||||
|
||||
import { defaultResponder } from "@calcom/lib/server";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { schemaCredentialGetParams } from "~/lib/validations/credential-sync";
|
||||
|
||||
@@ -34,8 +35,6 @@ import { schemaCredentialGetParams } from "~/lib/validations/credential-sync";
|
||||
* description: Credential syncing not enabled
|
||||
*/
|
||||
async function handler(req: NextApiRequest) {
|
||||
const { prisma } = req;
|
||||
|
||||
const { appSlug, userId } = schemaCredentialGetParams.parse(req.query);
|
||||
|
||||
let credentials = await prisma.credential.findMany({
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { NextApiRequest } from "next";
|
||||
import { minimumTokenResponseSchema } from "@calcom/app-store/_utils/oauth/parseRefreshTokenResponse";
|
||||
import { symmetricDecrypt } from "@calcom/lib/crypto";
|
||||
import { defaultResponder } from "@calcom/lib/server";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { schemaCredentialPatchParams, schemaCredentialPatchBody } from "~/lib/validations/credential-sync";
|
||||
|
||||
@@ -54,8 +55,6 @@ import { schemaCredentialPatchParams, schemaCredentialPatchBody } from "~/lib/va
|
||||
* description: Credential syncing not enabled
|
||||
*/
|
||||
async function handler(req: NextApiRequest) {
|
||||
const { prisma } = req;
|
||||
|
||||
const { userId, credentialId } = schemaCredentialPatchParams.parse(req.query);
|
||||
|
||||
const { encryptedKey } = schemaCredentialPatchBody.parse(req.body);
|
||||
|
||||
@@ -6,8 +6,10 @@ import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
|
||||
import { symmetricDecrypt } from "@calcom/lib/crypto";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { defaultResponder } from "@calcom/lib/server";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
|
||||
import { schemaCredentialPostParams, schemaCredentialPostBody } from "~/lib/validations/credential-sync";
|
||||
import { schemaCredentialPostBody, schemaCredentialPostParams } from "~/lib/validations/credential-sync";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -54,8 +56,6 @@ import { schemaCredentialPostParams, schemaCredentialPostBody } from "~/lib/vali
|
||||
* description: Credential syncing not enabled
|
||||
*/
|
||||
async function handler(req: NextApiRequest) {
|
||||
const { prisma } = req;
|
||||
|
||||
if (!req.body) {
|
||||
throw new HttpError({ message: "Request body is missing", statusCode: 400 });
|
||||
}
|
||||
@@ -88,26 +88,29 @@ async function handler(req: NextApiRequest) {
|
||||
|
||||
const appMetadata = appStoreMetadata[app.dirName as keyof typeof appStoreMetadata];
|
||||
|
||||
const credential = await prisma.credential.create({
|
||||
const createdcredential = await prisma.credential.create({
|
||||
data: {
|
||||
userId,
|
||||
appId: appSlug,
|
||||
key,
|
||||
type: appMetadata.type,
|
||||
},
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: credentialForCalendarServiceSelect,
|
||||
});
|
||||
// createdcredential.user.email;
|
||||
// TODO: ^ Investigate why this select doesn't work.
|
||||
const credential = await prisma.credential.findUniqueOrThrow({
|
||||
where: {
|
||||
id: createdcredential.id,
|
||||
},
|
||||
select: credentialForCalendarServiceSelect,
|
||||
});
|
||||
// ^ Workaround for the select in `create` not working
|
||||
|
||||
if (createCalendarResources) {
|
||||
const calendar = await getCalendar(credential);
|
||||
if (!calendar) throw new HttpError({ message: "Calendar missing for credential", statusCode: 500 });
|
||||
const calendars = await calendar.listCalendars();
|
||||
|
||||
const calendarToCreate = calendars.find((calendar) => calendar.primary) || calendars[0];
|
||||
|
||||
if (createSelectedCalendar) {
|
||||
@@ -129,7 +132,7 @@ async function handler(req: NextApiRequest) {
|
||||
integration: appMetadata.type,
|
||||
externalId: calendarToCreate.externalId,
|
||||
credential: { connect: { id: credential.id } },
|
||||
primaryEmail: calendarToCreate.email || credential.user.email,
|
||||
primaryEmail: calendarToCreate.email || credential.user?.email,
|
||||
user: { connect: { id: userId } },
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user