ToolJet/server/src/controllers/users.controller.ts
Arpit 26c9cc655c
Fix linting errors across the app (#785)
* eslint-setup: rules for frontend and server

* setup pre-commit:hook

* frontend:eslint fixes

* frontend eslint errors and warning fixed

* eslint:fix for ./server

* fix server/test: expectatin string lint/error

* pre-commit:updated

* removed unwanted install cmd from docker file

* recommended settings and extension for vscode

* husky prepare script added

* updated extension recommendations

* added prettier as recommended extension

* added pre-commit to package.json

* remove .prettierrc file

* resolve changes

* resolve changes
2021-09-21 19:18:28 +05:30

34 lines
1.1 KiB
TypeScript

import { Body, Controller, Post, Patch, Request, UseGuards } from '@nestjs/common';
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';
@Controller('users')
export class UsersController {
constructor(private usersService: UsersService) {}
@Post('set_password_from_token')
async create(@Request() req) {
const result = await this.usersService.setupAccountFromInvitationToken(req.body);
return result;
}
@UseGuards(JwtAuthGuard)
@Patch('update')
async update(@Request() req, @Body() body) {
const { firstName, lastName } = body;
await this.usersService.update(req.user.id, { firstName, lastName });
await req.user.reload();
return {
first_name: req.user.firstName,
last_name: req.user.lastName,
};
}
@UseGuards(JwtAuthGuard, PasswordRevalidateGuard)
@Patch('change_password')
async changePassword(@Request() req, @Body() body) {
const { newPassword } = body;
return await this.usersService.update(req.user.id, { password: newPassword });
}
}