mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
35 lines
841 B
TypeScript
35 lines
841 B
TypeScript
import { prisma } from '@documenso/prisma';
|
|
|
|
import { TEAM_MEMBER_ROLE_PERMISSIONS_MAP } from '../../constants/teams';
|
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
|
import { buildTeamWhereQuery } from '../../utils/teams';
|
|
|
|
export type DeleteTokenByIdOptions = {
|
|
id: number;
|
|
userId: number;
|
|
teamId: number;
|
|
};
|
|
|
|
export const deleteTokenById = async ({ id, userId, teamId }: DeleteTokenByIdOptions) => {
|
|
const team = await prisma.team.findFirst({
|
|
where: buildTeamWhereQuery({
|
|
teamId,
|
|
userId,
|
|
roles: TEAM_MEMBER_ROLE_PERMISSIONS_MAP['MANAGE_TEAM'],
|
|
}),
|
|
});
|
|
|
|
if (!team) {
|
|
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
|
message: 'You do not have permission to delete this token',
|
|
});
|
|
}
|
|
|
|
await prisma.apiToken.delete({
|
|
where: {
|
|
id,
|
|
teamId,
|
|
},
|
|
});
|
|
};
|