* wip * use light imports * fix * perf: Reduce bundle size via better imports with `googleapis` (#17811) * fix test * refactor * update vite.config.js * fix * fix unit test failing
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { prisma } from "@calcom/prisma";
|
|
import { safeCredentialSelect } from "@calcom/prisma/selects/credential";
|
|
|
|
type CredentialCreateInput = {
|
|
type: string;
|
|
key: any;
|
|
userId: number;
|
|
appId: string;
|
|
};
|
|
|
|
export class CredentialRepository {
|
|
static async create(data: CredentialCreateInput) {
|
|
return await prisma.credential.create({ data: { ...data } });
|
|
}
|
|
|
|
/**
|
|
* Doesn't retrieve key field as that has credentials
|
|
*/
|
|
static async findFirstByIdWithUser({ id }: { id: number }) {
|
|
return await prisma.credential.findFirst({ where: { id }, select: safeCredentialSelect });
|
|
}
|
|
|
|
/**
|
|
* Includes 'key' field which is sensitive data.
|
|
*/
|
|
static async findFirstByIdWithKeyAndUser({ id }: { id: number }) {
|
|
return await prisma.credential.findFirst({
|
|
where: { id },
|
|
select: { ...safeCredentialSelect, key: true },
|
|
});
|
|
}
|
|
|
|
static async findFirstByAppIdAndUserId({ appId, userId }: { appId: string; userId: number }) {
|
|
return await prisma.credential.findFirst({
|
|
where: {
|
|
appId,
|
|
userId,
|
|
},
|
|
});
|
|
}
|
|
|
|
static async findFirstByUserIdAndType({ userId, type }: { userId: number; type: string }) {
|
|
return await prisma.credential.findFirst({ where: { userId, type } });
|
|
}
|
|
|
|
static async deleteById({ id }: { id: number }) {
|
|
await prisma.credential.delete({ where: { id } });
|
|
}
|
|
}
|