-
-
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(profiles): implement profile use cases
- Loading branch information
1 parent
99c86d5
commit ffe1417
Showing
23 changed files
with
177 additions
and
37 deletions.
There are no files selected for viewing
Binary file not shown.
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 +1,2 @@ | ||
export * from './app.update'; | ||
export * from './register.wizard'; |
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,15 +1,15 @@ | ||
import { Profile } from '../entities'; | ||
|
||
abstract class IProfileService { | ||
abstract createProfile(profile: Profile): Promise<void>; | ||
abstract createProfile(profile: Profile): Promise<Profile>; | ||
|
||
abstract updateProfile(profileId: number, profile: Profile): Promise<void>; | ||
abstract updateProfile(profileId: number, profile: Profile): Promise<Profile>; | ||
|
||
abstract deleteProfile(profileId: number): Promise<void>; | ||
|
||
abstract findByUser(userId: number): Promise<Profile>; | ||
|
||
abstract findRecommended(user: Profile, skip: number): Promise<void>; | ||
abstract findRecommended(user: Profile, skip: number): Promise<Profile>; | ||
} | ||
|
||
export { IProfileService }; |
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,10 @@ | ||
import { autoImplement } from '../utils'; | ||
|
||
class CreateUserDto { | ||
chatId: number; | ||
userId: number; | ||
} | ||
|
||
class UpdateUserDto implements Partial<CreateUserDto> {} | ||
class UpdateUserDto extends autoImplement<Partial<CreateUserDto>>() {} | ||
|
||
export { CreateUserDto, UpdateUserDto }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './partial'; |
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,5 @@ | ||
function autoImplement<T>(): new () => T { | ||
return class {} as any; | ||
} | ||
|
||
export { autoImplement }; |
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
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmProfileModule } from 'src/frameworks/profile/typeorm'; | ||
|
||
@Module({ | ||
imports: [TypeOrmProfileModule], | ||
exports: [TypeOrmProfileModule], | ||
}) | ||
export class ProfileModule {} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CreateProfileDto, Profile, UpdateProfileDto } from 'src/core'; | ||
|
||
@Injectable() | ||
export class ProfileFactoryService { | ||
create(dto: CreateProfileDto): Profile { | ||
return Profile.create({ | ||
...dto, | ||
user: { | ||
id: dto.userId, | ||
}, | ||
games: dto.games.map((gameId) => ({ id: gameId })), | ||
}); | ||
} | ||
|
||
update(dto: UpdateProfileDto): Profile { | ||
return Profile.create({ | ||
...dto, | ||
user: { | ||
id: dto.userId, | ||
}, | ||
games: dto.games.map((gameId) => ({ id: gameId })), | ||
}); | ||
} | ||
} |
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,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ProfileModule } from 'src/services/profile/profile.module'; | ||
import { ProfileUseCases } from './profile.use-case'; | ||
import { ProfileFactoryService } from './profile-factory.service'; | ||
|
||
@Module({ | ||
imports: [ProfileModule], | ||
providers: [ProfileUseCases, ProfileFactoryService], | ||
exports: [ProfileUseCases], | ||
}) | ||
export class ProfileUseCasesModule {} |
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,37 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CreateProfileDto, IProfileService } from 'src/core'; | ||
import { ProfileFactoryService } from './profile-factory.service'; | ||
|
||
@Injectable() | ||
export class ProfileUseCases { | ||
constructor( | ||
private readonly profileService: IProfileService, | ||
private readonly profileFactory: ProfileFactoryService, | ||
) {} | ||
|
||
async findByUser(userId: number) { | ||
return this.profileService.findByUser(userId); | ||
} | ||
|
||
async createProfile(dto: CreateProfileDto) { | ||
const profile = this.profileFactory.create(dto); | ||
|
||
return this.profileService.createProfile(profile); | ||
} | ||
|
||
async updateProfile(profileId: number, dto: CreateProfileDto) { | ||
const profile = this.profileFactory.update(dto); | ||
|
||
return this.profileService.updateProfile(profileId, profile); | ||
} | ||
|
||
async deleteProfile(profileId: number) { | ||
return this.profileService.deleteProfile(profileId); | ||
} | ||
|
||
async findRecommended(userId: number, skip: number) { | ||
const profile = await this.profileService.findByUser(userId); | ||
|
||
return this.profileService.findRecommended(profile, skip); | ||
} | ||
} |
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