* feature(dashboard): add polar / subscription * wip(payments): manage subscription * wip(payments): add free product, faq and some other improvements * fix(root): change node to bundler in tsconfig * wip(payments): display current subscription * feat(dashboard): schedule project for deletion * wip(payments): support custom products/subscriptions * wip(payments): fix polar scripts * wip(payments): add json package to dockerfiles
45 lines
804 B
TypeScript
45 lines
804 B
TypeScript
import { db } from '../prisma-client';
|
|
|
|
export type IServiceUser = Awaited<ReturnType<typeof getUserById>>;
|
|
|
|
export async function getUserById(id: string) {
|
|
return db.user.findUniqueOrThrow({
|
|
where: {
|
|
id,
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function getUserAccount({
|
|
email,
|
|
provider,
|
|
providerId,
|
|
}: { email: string; provider: string; providerId?: string }) {
|
|
const res = await db.user.findFirst({
|
|
where: {
|
|
email: {
|
|
equals: email,
|
|
mode: 'insensitive',
|
|
},
|
|
},
|
|
include: {
|
|
accounts: {
|
|
where: {
|
|
provider,
|
|
providerId: providerId ? String(providerId) : undefined,
|
|
},
|
|
take: 1,
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!res?.accounts[0]) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
...res,
|
|
account: res?.accounts[0],
|
|
};
|
|
}
|