import type { ServiceMethodFactory } from "@ethicdevs/react-monolith";
import { Organization } from "@prisma/client";
import type { UsersServiceDeps } from "./types";
const getUserOrganizations: ServiceMethodFactory<
UsersServiceDeps,
[string],
Promise<Organization[]>
> = ({ request }) => {
return async (userId) => {
const userOrgs = await request.prisma.organization.findMany({
where: {
OR: [
{
ownerId: userId,
},
{
memberships: {
some: {
userId,
},
},
},
],
},
orderBy: {
kind: "asc",
},
});
return userOrgs;
};
};
export default getUserOrganizations;