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 user repo and profile get endpoint
- Loading branch information
1 parent
a9cd6e9
commit a60d4f6
Showing
5 changed files
with
56 additions
and
6 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 |
---|---|---|
@@ -1,19 +1,25 @@ | ||
import { Option } from 'tsoption' | ||
|
||
export class Profile { | ||
private name?: string | ||
public get name(): Option<string> { | ||
return Option.of(this._name) | ||
} | ||
|
||
private _name?: string | ||
|
||
public constructor(name?: string) { | ||
this.name = name | ||
this._name = name | ||
} | ||
|
||
public changeName(newName: string) { | ||
if (newName.length < 1) { | ||
// TODO: throw error | ||
} | ||
|
||
this.name = newName | ||
this._name = newName | ||
} | ||
|
||
public removeName() { | ||
this.name = undefined | ||
this._name = undefined | ||
} | ||
} |
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,26 @@ | ||
import { Injectable } from '@nestjs/common' | ||
import { InjectRepository } from '@nestjs/typeorm' | ||
import { Repository } from 'typeorm' | ||
|
||
import { User } from './User.entity' | ||
|
||
@Injectable() | ||
class UserRepo { | ||
public constructor( | ||
@InjectRepository(User) | ||
private readonly userRepo: Repository<User>, | ||
) {} | ||
|
||
public async getOne(login: string): Promise<User> { | ||
const user = await this.userRepo.findOne(login) | ||
|
||
if (!user) { | ||
// TODO: throw error | ||
} | ||
|
||
return user | ||
} | ||
} | ||
|
||
export const UserRepository = UserRepo | ||
export type UserRepository = UserRepo |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import { ApiModelPropertyOptional } from '@nestjs/swagger' | ||
|
||
import { Profile } from '@back/user/domain/Profile.vo' | ||
import { ProfileModel } from '@shared/models/user/ProfileModel' | ||
|
||
export class ProfileResponse implements ProfileModel { | ||
public static fromProfile(profile: Profile): ProfileResponse { | ||
return { | ||
name: profile.name.getOrElse(undefined), | ||
} | ||
} | ||
|
||
@ApiModelPropertyOptional({ example: 'Nick' }) | ||
public 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