shellphone.app/app/users/queries/get-current-user.ts
2021-10-16 00:31:01 +02:00

29 lines
529 B
TypeScript

import type { Ctx } from "blitz";
import db, { SubscriptionStatus } from "db";
export default async function getCurrentUser(_ = null, { session }: Ctx) {
if (!session.userId) return null;
return db.user.findFirst({
where: { id: session.userId },
select: {
id: true,
fullName: true,
email: true,
role: true,
memberships: {
include: {
organization: {
include: {
subscriptions: {
where: { status: SubscriptionStatus.active },
},
},
},
},
},
},
});
}