Files
documenso/packages/lib/server-only/public-api/get-api-tokens.ts
2025-06-13 17:20:03 +10:00

31 lines
691 B
TypeScript

import { prisma } from '@documenso/prisma';
import { TEAM_MEMBER_ROLE_PERMISSIONS_MAP } from '../../constants/teams';
import { buildTeamWhereQuery } from '../../utils/teams';
export type GetApiTokensOptions = {
userId: number;
teamId: number;
};
export const getApiTokens = async ({ userId, teamId }: GetApiTokensOptions) => {
return await prisma.apiToken.findMany({
where: {
team: buildTeamWhereQuery({
teamId,
userId,
roles: TEAM_MEMBER_ROLE_PERMISSIONS_MAP['MANAGE_TEAM'],
}),
},
select: {
id: true,
name: true,
createdAt: true,
expires: true,
},
orderBy: {
createdAt: 'desc',
},
});
};