This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): add editing user profile
- Loading branch information
1 parent
a60d4f6
commit a1f0c73
Showing
5 changed files
with
52 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Injectable } from '@nestjs/common' | ||
|
||
import { EntitySaver } from '@back/db/EntitySaver' | ||
|
||
import { User } from '../domain/User.entity' | ||
import { UserRepository } from '../domain/UserRepository' | ||
import { ProfileFields } from './dto/ProfileFields' | ||
|
||
@Injectable() | ||
export class ProfileEditor { | ||
public constructor( | ||
private readonly userRepo: UserRepository, | ||
private readonly entitySaver: EntitySaver, | ||
) {} | ||
|
||
public async edit(login: string, fields: ProfileFields): Promise<void> { | ||
const user = await this.userRepo.getOne(login) | ||
|
||
this.editName(user, fields) | ||
|
||
await this.entitySaver.save(user) | ||
} | ||
|
||
private editName(user: User, { name }: ProfileFields): void { | ||
if (name.length > 1) { | ||
user.profile.changeName(name) | ||
} else { | ||
user.profile.removeName() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface ProfileFields { | ||
readonly name?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters