feat: user invitation revoke mutation added
This commit is contained in:
committed by
Andrew Bastin
parent
9c6754c70f
commit
5368c52aab
@@ -269,6 +269,27 @@ export class AdminResolver {
|
|||||||
return invitedUser.right;
|
return invitedUser.right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Mutation(() => Boolean, {
|
||||||
|
description: 'Revoke a user invite by invitee email',
|
||||||
|
})
|
||||||
|
@UseGuards(GqlAuthGuard, GqlAdminGuard)
|
||||||
|
async revokeUserInvitationByAdmin(
|
||||||
|
@GqlAdmin() adminUser: Admin,
|
||||||
|
@Args({
|
||||||
|
name: 'inviteeEmail',
|
||||||
|
description: 'Invite Email',
|
||||||
|
type: () => ID,
|
||||||
|
})
|
||||||
|
inviteeEmail: string,
|
||||||
|
): Promise<boolean> {
|
||||||
|
const invite = await this.adminService.revokeUserInvite(
|
||||||
|
inviteeEmail,
|
||||||
|
adminUser.uid,
|
||||||
|
);
|
||||||
|
if (E.isLeft(invite)) throwErr(invite.left);
|
||||||
|
return invite.right;
|
||||||
|
}
|
||||||
|
|
||||||
@Mutation(() => Boolean, {
|
@Mutation(() => Boolean, {
|
||||||
description: 'Delete an user account from infra',
|
description: 'Delete an user account from infra',
|
||||||
})
|
})
|
||||||
@@ -471,4 +492,14 @@ export class AdminResolver {
|
|||||||
userInvited(@GqlUser() admin: AuthUser) {
|
userInvited(@GqlUser() admin: AuthUser) {
|
||||||
return this.pubsub.asyncIterator(`admin/${admin.uid}/invited`);
|
return this.pubsub.asyncIterator(`admin/${admin.uid}/invited`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscription(() => InvitedUser, {
|
||||||
|
description: 'Listen for User Invite Revocation',
|
||||||
|
resolve: (value) => value,
|
||||||
|
})
|
||||||
|
@SkipThrottle()
|
||||||
|
@UseGuards(GqlAuthGuard, GqlAdminGuard)
|
||||||
|
userRevoked(@GqlUser() admin: AuthUser) {
|
||||||
|
return this.pubsub.asyncIterator(`admin/${admin.uid}/invitation_revoked`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
TEAM_INVITE_ALREADY_MEMBER,
|
TEAM_INVITE_ALREADY_MEMBER,
|
||||||
TEAM_INVITE_NO_INVITE_FOUND,
|
TEAM_INVITE_NO_INVITE_FOUND,
|
||||||
USER_ALREADY_INVITED,
|
USER_ALREADY_INVITED,
|
||||||
|
USER_INVITATION_NOT_FOUND,
|
||||||
USER_IS_ADMIN,
|
USER_IS_ADMIN,
|
||||||
USER_NOT_FOUND,
|
USER_NOT_FOUND,
|
||||||
} from '../errors';
|
} from '../errors';
|
||||||
@@ -110,6 +111,35 @@ export class AdminService {
|
|||||||
return E.right(invitedUser);
|
return E.right(invitedUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Revoke infra level user invitation
|
||||||
|
* @param inviteeEmail Invitee's email
|
||||||
|
* @param adminUid Admin Uid
|
||||||
|
* @returns an Either of array of `InvitedUser` object or error string
|
||||||
|
*/
|
||||||
|
async revokeUserInvite(inviteeEmail: string, adminUid: string) {
|
||||||
|
try {
|
||||||
|
const deletedInvitee = await this.prisma.invitedUsers.delete({
|
||||||
|
where: {
|
||||||
|
inviteeEmail,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const invitedUser = <InvitedUser>{
|
||||||
|
adminEmail: deletedInvitee.adminEmail,
|
||||||
|
adminUid: deletedInvitee.adminUid,
|
||||||
|
inviteeEmail: deletedInvitee.inviteeEmail,
|
||||||
|
invitedOn: deletedInvitee.invitedOn,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.pubsub.publish(`admin/${adminUid}/invitation_revoked`, invitedUser);
|
||||||
|
|
||||||
|
return E.right(true);
|
||||||
|
} catch (error) {
|
||||||
|
return E.left(USER_INVITATION_NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the list of invited users by the admin.
|
* Fetch the list of invited users by the admin.
|
||||||
* @returns an Either of array of `InvitedUser` object or error
|
* @returns an Either of array of `InvitedUser` object or error
|
||||||
|
|||||||
@@ -99,6 +99,12 @@ export const USER_IS_OWNER = 'user/is_owner' as const;
|
|||||||
*/
|
*/
|
||||||
export const USER_IS_ADMIN = 'user/is_admin' as const;
|
export const USER_IS_ADMIN = 'user/is_admin' as const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User invite deletion failure error due to invitation not found
|
||||||
|
* (AdminService)
|
||||||
|
*/
|
||||||
|
export const USER_INVITATION_NOT_FOUND = 'user/invitation_not_found' as const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Teams not found
|
* Teams not found
|
||||||
* (TeamsService)
|
* (TeamsService)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import { Shortcode } from 'src/shortcode/shortcode.model';
|
|||||||
// A custom message type that defines the topic and the corresponding payload.
|
// A custom message type that defines the topic and the corresponding payload.
|
||||||
// For every module that publishes a subscription add its type def and the possible subscription type.
|
// For every module that publishes a subscription add its type def and the possible subscription type.
|
||||||
export type TopicDef = {
|
export type TopicDef = {
|
||||||
[topic: `admin/${string}/${'invited'}`]: InvitedUser;
|
[topic: `admin/${string}/${'invited' | 'invitation_revoked'}`]: InvitedUser;
|
||||||
[topic: `user/${string}/${'updated' | 'deleted'}`]: User;
|
[topic: `user/${string}/${'updated' | 'deleted'}`]: User;
|
||||||
[topic: `user_settings/${string}/${'created' | 'updated'}`]: UserSettings;
|
[topic: `user_settings/${string}/${'created' | 'updated'}`]: UserSettings;
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user