2021-09-26 22:44:26 +00:00
|
|
|
import type { Ctx } from "blitz";
|
2021-08-05 17:07:15 +00:00
|
|
|
|
2021-10-20 23:03:32 +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: {
|
2021-10-20 22:01:03 +00:00
|
|
|
where: {
|
|
|
|
OR: [
|
|
|
|
{ status: { not: SubscriptionStatus.deleted } },
|
|
|
|
{
|
|
|
|
status: SubscriptionStatus.deleted,
|
|
|
|
cancellationEffectiveDate: { gt: new Date() },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-10-20 23:03:32 +00:00
|
|
|
orderBy: { lastEventTime: Prisma.SortOrder.desc },
|
2021-10-15 22:24:28 +00:00
|
|
|
},
|
2021-08-05 17:07:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|