Skip to content

Commit

Permalink
feat: add UserDto for user data transfer and update user service to r…
Browse files Browse the repository at this point in the history
…eturn UserDto
  • Loading branch information
tomast1337 committed Feb 10, 2025
1 parent b7270cd commit cd62317
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions server/src/user/dto/user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { User } from '../entity/user.entity';

export class UserDto {
username: string;
publicName: string;
email: string;
static fromEntity(user: User): UserDto {
const userDto: UserDto = {
username: user.username,
publicName: user.publicName,
email: user.email,
};

return userDto;
}
}
5 changes: 4 additions & 1 deletion server/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { UpdateUsernameDto } from '@shared/validation/user/dto/UpdateUsername.dt
import { validate } from 'class-validator';
import { Model } from 'mongoose';

import { UserDto } from './dto/user.dto';
import { User, UserDocument } from './entity/user.entity';

@Injectable()
Expand Down Expand Up @@ -147,6 +148,8 @@ export class UserService {

user.username = username;

return await user.save();
await user.save();

return UserDto.fromEntity(user);
}
}

0 comments on commit cd62317

Please sign in to comment.