shellphone.app/app/users/queries/get-current-user.ts

38 lines
786 B
TypeScript
Raw Normal View History

2021-09-26 22:44:26 +00:00
import type { Ctx } from "blitz";
2021-08-05 17:07:15 +00:00
import db, { Prisma, SubscriptionStatus } from "db";
2021-08-05 17:07:15 +00:00
export default async function getCurrentUser(_ = null, { session }: Ctx) {
if (!session.userId) return null;
return db.user.findFirst({
where: { id: session.userId },
select: {
id: true,
2021-09-25 14:16:31 +00:00
fullName: true,
2021-08-05 17:07:15 +00:00
email: true,
role: true,
memberships: {
include: {
organization: {
2021-10-15 22:24:28 +00:00
include: {
subscriptions: {
where: {
OR: [
{ status: { not: SubscriptionStatus.deleted } },
{
status: SubscriptionStatus.deleted,
cancellationEffectiveDate: { gt: new Date() },
},
],
},
orderBy: { lastEventTime: Prisma.SortOrder.desc },
2021-10-15 22:24:28 +00:00
},
2021-08-05 17:07:15 +00:00
},
},
},
},
},
});
}