2021-08-13 19:46:42 +00:00
|
|
|
import { Team } from "@prisma/client";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-08-13 19:46:42 +00:00
|
|
|
import prisma from "@lib/prisma";
|
2021-08-23 09:40:57 +00:00
|
|
|
import { defaultAvatarSrc } from "@lib/profile";
|
2021-08-13 19:46:42 +00:00
|
|
|
|
|
|
|
export const getTeam = async (idOrSlug: string): Promise<Team | null> => {
|
|
|
|
const teamIdOrSlug = idOrSlug;
|
|
|
|
const teamSelectInput = {
|
|
|
|
id: true,
|
|
|
|
name: true,
|
|
|
|
slug: true,
|
|
|
|
members: {
|
|
|
|
where: {
|
|
|
|
accepted: true,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
user: {
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
username: true,
|
|
|
|
email: true,
|
|
|
|
name: true,
|
|
|
|
bio: true,
|
|
|
|
avatar: true,
|
|
|
|
theme: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-08-23 09:40:57 +00:00
|
|
|
const team = await prisma.team.findFirst({
|
2021-08-13 19:46:42 +00:00
|
|
|
where: {
|
|
|
|
OR: [
|
|
|
|
{
|
|
|
|
id: parseInt(teamIdOrSlug) || undefined,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
slug: teamIdOrSlug,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
select: teamSelectInput,
|
|
|
|
});
|
|
|
|
|
2021-08-23 09:40:57 +00:00
|
|
|
team.members = team.members.map((member) => {
|
|
|
|
member.user.avatar = member.user.avatar || defaultAvatarSrc({ email: member.user.email });
|
|
|
|
return member;
|
|
|
|
});
|
2021-08-13 19:46:42 +00:00
|
|
|
|
|
|
|
return team;
|
|
|
|
};
|