Skip to content
Snippets Groups Projects
Unverified Commit 48c55c39 authored by Negin Moshki's avatar Negin Moshki Committed by GitHub
Browse files

Add ability to change account details (#27)


* Change data saved in backend

* Change return values

* Change path name

---------

Co-authored-by: default avatarDavid Phan <phan.david@gmx.de>
Co-authored-by: default avatarFlorian Raith <florianraith00@gmail.com>
parent c484bbd0
No related branches found
No related tags found
No related merge requests found
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
import { Body, Controller, Get, Post, Put, UseGuards } from '@nestjs/common';
import { AdminGuard } from '../common/guards/admin.guard';
import { AuthGuard } from '../auth/auth.guard';
import { UserService } from './user.service';
export type EditUser = {
id: number;
organization: string;
name: string;
email: string;
};
@Controller('user')
export class UserController {
constructor(private readonly userService: UserService) {}
@UseGuards(AuthGuard, AdminGuard)
@Get('findAll')
public async findAll() {
......@@ -17,4 +25,10 @@ export class UserController {
public async changeRole(@Body() data: { id: number }) {
return await this.userService.changeRole(data.id);
}
@UseGuards(AuthGuard)
@Put('changeUserData')
public async changeUserData(@Body() data: EditUser): Promise<boolean> {
return this.userService.changeUserData(data);
}
}
......@@ -5,6 +5,7 @@ import { User } from './user.entity';
import { InjectRepository } from '@mikro-orm/nestjs';
import { CreateUser } from '../auth/auth.dto';
import * as bcrypt from 'bcrypt';
import { EditUser } from './user.controller';
@Injectable()
export class UserService {
......@@ -49,6 +50,15 @@ export class UserService {
await this.repository.nativeDelete({ id });
}
public async changeUserData(data: EditUser): Promise<boolean> {
const user = await this.findOne(data.id);
user.name = data.name;
user.email = data.email;
user.organization = data.organization;
await this.em.persistAndFlush(user);
return true;
}
public async changeRole(id: number): Promise<User> {
const user = await this.repository.findOne({ id });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment