29 lines
529 B
TypeScript
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 },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|