mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-26 09:39:49 +00:00
refactor(nestjs): Implement users module
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
|
||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { UsersApplication } from './Users.application';
|
||||
import { InviteUserDto, SendInviteUserDto } from './dtos/InviteUser.dto';
|
||||
|
||||
@Controller('invite')
|
||||
@ApiTags('users')
|
||||
export class UsersInviteController {
|
||||
constructor(private readonly usersApplication: UsersApplication) {}
|
||||
|
||||
/**
|
||||
* Accept a user invitation.
|
||||
*/
|
||||
@Post('accept/:token')
|
||||
@ApiOperation({ summary: 'Accept a user invitation.' })
|
||||
async acceptInvite(
|
||||
@Param('token') token: string,
|
||||
@Body() inviteUserDTO: InviteUserDto,
|
||||
) {
|
||||
await this.usersApplication.acceptInvite(token, inviteUserDTO);
|
||||
|
||||
return {
|
||||
message: 'The invitation has been accepted successfully.',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an invitation token is valid.
|
||||
*/
|
||||
@Get('check/:token')
|
||||
@ApiOperation({ summary: 'Check if an invitation token is valid.' })
|
||||
async checkInvite(@Param('token') token: string) {
|
||||
const inviteDetails = await this.usersApplication.checkInvite(token);
|
||||
|
||||
return inviteDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an invitation to a new user.
|
||||
*/
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Send an invitation to a new user.' })
|
||||
async sendInvite(@Body() sendInviteDTO: SendInviteUserDto) {
|
||||
const result = await this.usersApplication.sendInvite(sendInviteDTO);
|
||||
|
||||
return {
|
||||
invitedUser: result.invitedUser,
|
||||
message: 'The invitation has been sent successfully.',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Resend an invitation to an existing user.
|
||||
*/
|
||||
@Post('users/:id/resend')
|
||||
@ApiOperation({ summary: 'Resend an invitation to an existing user.' })
|
||||
async resendInvite(@Param('id') userId: number) {
|
||||
const result = await this.usersApplication.resendInvite(userId);
|
||||
|
||||
return {
|
||||
user: result.user,
|
||||
message: 'The invitation has been resent successfully.',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user