-
-
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(profile repo): implement typeorm profile repo
- Loading branch information
1 parent
e23b25f
commit 3029505
Showing
5 changed files
with
55 additions
and
25 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,16 +1,15 @@ | ||
import { CreateProfileDto, UpdateProfileDto } from '../dtos'; | ||
import { User } from '../entities'; | ||
import { Profile } from '../entities'; | ||
|
||
abstract class IProfileService { | ||
abstract createProfile(dto: CreateProfileDto): Promise<void>; | ||
abstract createProfile(profile: Profile): Promise<void>; | ||
|
||
abstract updateProfile(dto: UpdateProfileDto): Promise<void>; | ||
abstract updateProfile(profileId: number, profile: Profile): Promise<void>; | ||
|
||
abstract deleteProfile(id: number): Promise<void>; | ||
abstract deleteProfile(profileId: number): Promise<void>; | ||
|
||
abstract findByUser(userId: number): Promise<void>; | ||
abstract findByUser(userId: number): Promise<Profile>; | ||
|
||
abstract findRecommended(user: User, skip: number): Promise<void>; | ||
abstract findRecommended(user: Profile, skip: number): Promise<void>; | ||
} | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './typeorm-profile.module'; | ||
export * from './typeorm-profile.service'; |
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,16 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { IProfileService, Profile } from 'src/core'; | ||
import { TypeOrmProfileService } from './typeorm-profile.service'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([Profile])], | ||
exports: [IProfileService], | ||
providers: [ | ||
{ | ||
provide: IProfileService, | ||
useClass: TypeOrmProfileService, | ||
}, | ||
], | ||
}) | ||
export class TypeOrmProfileModule {} |
45 changes: 29 additions & 16 deletions
45
src/frameworks/profile/typeorm/typeorm-profile.service.ts
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,30 +1,43 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { | ||
CreateProfileDto, | ||
IProfileService, | ||
UpdateProfileDto, | ||
User, | ||
} from 'src/core'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { IProfileService, Profile } from 'src/core'; | ||
import { Repository } from 'typeorm'; | ||
|
||
@Injectable() | ||
export class TypeOrmProfileService implements IProfileService { | ||
async createProfile(dto: CreateProfileDto): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
constructor( | ||
@InjectRepository(Profile) | ||
private readonly profileRepo: Repository<Profile>, | ||
) {} | ||
|
||
async findByUser(userId: number): Promise<Profile> { | ||
return this.profileRepo.findOne({ | ||
where: { | ||
user: { | ||
id: userId, | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
async updateProfile(dto: UpdateProfileDto): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
async createProfile(profile: Profile): Promise<void> { | ||
await this.profileRepo.insert(profile); | ||
} | ||
|
||
async deleteProfile(id: number): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
async updateProfile(profileId: number, profile: Profile): Promise<void> { | ||
await this.profileRepo.update(profileId, profile); | ||
} | ||
|
||
async findByUser(userId: number): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
async deleteProfile(profileId: number): Promise<void> { | ||
await this.profileRepo.delete(profileId); | ||
} | ||
|
||
async findRecommended(user: User, skip: number): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
// TODO | ||
async findRecommended(user: Profile, skip: number): Promise<void> { | ||
await this.profileRepo.find({ | ||
skip, | ||
take: 1, | ||
order: {}, | ||
}); | ||
} | ||
} |