fix: getAppInstallsBySlug now use teamIds

new-app-install-flow
Morgan Vernay 2023-10-20 15:54:22 +03:00
parent 4fba8af57c
commit d5b34b86c5
1 changed files with 8 additions and 4 deletions

View File

@ -358,7 +358,7 @@ const getEventTypeById = async (eventTypeId: number) => {
} as ConfigureEventTypeProp; } as ConfigureEventTypeProp;
}; };
const getAppInstallsBySlug = async (appSlug: string, userId: number, teamId?: number) => { const getAppInstallsBySlug = async (appSlug: string, userId: number, teamIds?: number[]) => {
const appInstalls = await prisma.credential.findMany({ const appInstalls = await prisma.credential.findMany({
where: { where: {
OR: [ OR: [
@ -366,10 +366,10 @@ const getAppInstallsBySlug = async (appSlug: string, userId: number, teamId?: nu
appId: appSlug, appId: appSlug,
userId: userId, userId: userId,
}, },
teamId teamIds && Boolean(teamIds.length)
? { ? {
appId: appSlug, appId: appSlug,
teamId: 5, teamId: { in: teamIds },
} }
: {}, : {},
], ],
@ -404,7 +404,11 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
.map((team) => ({ ...team.team, accepted: team.accepted })); .map((team) => ({ ...team.team, accepted: team.accepted }));
const hasTeams = Boolean(userAcceptedTeams.length); const hasTeams = Boolean(userAcceptedTeams.length);
const appInstalls = await getAppInstallsBySlug(parsedAppSlug, user.id, parsedTeamIdParam); const appInstalls = await getAppInstallsBySlug(
parsedAppSlug,
user.id,
userAcceptedTeams.map(({ id }) => id)
);
if (parsedTeamIdParam) { if (parsedTeamIdParam) {
const isUserMemberOfTeam = userAcceptedTeams.some((team) => team.id === parsedTeamIdParam); const isUserMemberOfTeam = userAcceptedTeams.some((team) => team.id === parsedTeamIdParam);