 6e82d38249
			
		
	
	
		6e82d38249
		
			
		
	
	
	
	
		
			
			* Fix for appstores and wipe-my-cal * Fix email subject for reschedule * Fix email subject for reschedule * Fix api add wipemycal return * Now we ask on a endpoint if app its installed * Fix types Co-authored-by: Omar López <zomars@me.com>
		
			
				
	
	
		
			43 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import type { NextApiRequest, NextApiResponse } from "next";
 | |
| 
 | |
| import prisma from "@calcom/prisma";
 | |
| 
 | |
| /**
 | |
|  * This is an example endpoint for an app, these will run under `/api/integrations/[...args]`
 | |
|  * @param req
 | |
|  * @param res
 | |
|  */
 | |
| export default async function handler(req: NextApiRequest, res: NextApiResponse) {
 | |
|   if (!req.session?.user?.id) {
 | |
|     return res.status(401).json({ message: "You must be logged in to do this" });
 | |
|   }
 | |
|   const appType = "wipemycal_other";
 | |
|   try {
 | |
|     const alreadyInstalled = await prisma.credential.findFirst({
 | |
|       where: {
 | |
|         type: appType,
 | |
|         userId: req.session.user.id,
 | |
|       },
 | |
|     });
 | |
|     if (alreadyInstalled) {
 | |
|       throw new Error("Already installed");
 | |
|     }
 | |
|     const installation = await prisma.credential.create({
 | |
|       data: {
 | |
|         type: appType,
 | |
|         key: {},
 | |
|         userId: req.session.user.id,
 | |
|       },
 | |
|     });
 | |
|     if (!installation) {
 | |
|       throw new Error("Unable to create user credential for wipe-my-cal");
 | |
|     }
 | |
|   } catch (error: unknown) {
 | |
|     if (error instanceof Error) {
 | |
|       return res.status(500).json({ message: error.message });
 | |
|     }
 | |
|     return res.status(500);
 | |
|   }
 | |
| 
 | |
|   return res.status(200).json({ url: "/apps/installed" });
 | |
| }
 |