mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-06 06:48:21 +00:00
* bug fixes * changes * changes for single workspace support * added guards for signup route * test cases fixes * Workspace invite and user onboarding flow changes (#3190) * invite user flow changes * review comments * cleanup * testcase fix
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { Body, Controller, Post, Patch, UseGuards, UseInterceptors, UploadedFile } from '@nestjs/common';
|
|
import { Express } from 'express';
|
|
import { FileInterceptor } from '@nestjs/platform-express';
|
|
import { JwtAuthGuard } from 'src/modules/auth/jwt-auth.guard';
|
|
import { PasswordRevalidateGuard } from 'src/modules/auth/password-revalidate.guard';
|
|
import { UsersService } from 'src/services/users.service';
|
|
import { User } from 'src/decorators/user.decorator';
|
|
import { UpdateUserDto } from '@dto/user.dto';
|
|
|
|
@Controller('users')
|
|
export class UsersController {
|
|
constructor(private usersService: UsersService) {}
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@Patch('update')
|
|
async update(@User() user, @Body() updateUserDto: UpdateUserDto) {
|
|
const { first_name: firstName, last_name: lastName } = updateUserDto;
|
|
await this.usersService.update(user.id, { firstName, lastName });
|
|
await user.reload();
|
|
return {
|
|
first_name: user.firstName,
|
|
last_name: user.lastName,
|
|
};
|
|
}
|
|
|
|
@Post('avatar')
|
|
@UseGuards(JwtAuthGuard)
|
|
@UseInterceptors(FileInterceptor('file'))
|
|
async addAvatar(@User() user, @UploadedFile() file: Express.Multer.File) {
|
|
return this.usersService.addAvatar(user.id, file.buffer, file.originalname);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, PasswordRevalidateGuard)
|
|
@Patch('change_password')
|
|
async changePassword(@User() user, @Body('newPassword') newPassword) {
|
|
return await this.usersService.update(user.id, {
|
|
password: newPassword,
|
|
});
|
|
}
|
|
}
|