Files
calendar/packages/app-store/_utils/installation.ts
T
sean-brydonGitHubPeer Richelsenkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>Omar López
3449ad1a9f Apps: Riverside/Whereby/Around (#3053)
* Add Whereby Boilerplate

* Whereby App

* around boilerplate

* AroundCo App

* Add Riverside App

* Add Riverside to details

* Fix URL validation

* Remove Icons

* Remove console.log

* revert merge

* Fix images

* Update Iconds to be SVG

* Add Disconnect button

* Fix type

* Fixing i18n merge

* Refactor app installations

* Update varient

* Update default responder + riverside logo

* Update apps/web/pages/event-types/[type].tsx

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Omar López <zomars@me.com>
2022-06-27 12:17:38 +02:00

42 lines
905 B
TypeScript

import type { Prisma } from "@prisma/client";
import { HttpError } from "@calcom/lib/http-error";
import prisma from "@calcom/prisma";
export async function checkInstalled(slug: string, userId: number) {
const alreadyInstalled = await prisma.credential.findFirst({
where: {
appId: slug,
userId: userId,
},
});
if (alreadyInstalled) {
throw new HttpError({ statusCode: 422, message: "Already installed" });
}
}
export async function createDefaultInstallation({
appType,
userId,
slug,
key = {},
}: {
appType: string;
userId: number;
slug: string;
key?: Prisma.InputJsonValue;
}) {
const installation = await prisma.credential.create({
data: {
type: appType,
key,
userId,
appId: slug,
},
});
if (!installation) {
throw new Error(`Unable to create user credential for type ${appType}`);
}
return installation;
}