-
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.
Browse files
Browse the repository at this point in the history
[feat] νμ μ°¨λ¨ κΈ°λ₯ μΆκ°
- Loading branch information
Showing
11 changed files
with
135 additions
and
7 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
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,38 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { Block } from './entities/block.entity'; | ||
import { BLOCK_REPOSITORY } from './users.constants'; | ||
import { Repository } from 'typeorm'; | ||
import { User } from './entities/user.entity'; | ||
|
||
@Injectable() | ||
export class BlockRepository { | ||
constructor( | ||
@Inject(BLOCK_REPOSITORY) | ||
private blockRepository: Repository<Block> | ||
) {} | ||
|
||
save(blocker: User, blocked: User) { | ||
return this.blockRepository.save({ blocker, blocked }); | ||
} | ||
|
||
findByBlocker(blocker: string) { | ||
return this.blockRepository | ||
.createQueryBuilder('b') | ||
.leftJoinAndSelect('b.blocker', 'x') | ||
.leftJoinAndSelect('b.blocked', 'y') | ||
.where('b.blocker = :blocker', { blocker }) | ||
.getMany(); | ||
} | ||
|
||
findByBlockerAndBlocked(blocker: string, blocked: string) { | ||
return this.blockRepository | ||
.createQueryBuilder('b') | ||
.leftJoinAndSelect('b.blocker', 'x') | ||
.leftJoinAndSelect('b.blocked', 'y') | ||
.where('b.blocker = :blocker AND b.blocked = :blocked', { | ||
blocker, | ||
blocked, | ||
}) | ||
.getOne(); | ||
} | ||
} |
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 { Entity, PrimaryGeneratedColumn, ManyToOne, JoinColumn } from 'typeorm'; | ||
import { User } from './user.entity'; | ||
|
||
@Entity() | ||
export class Block { | ||
@PrimaryGeneratedColumn('uuid') | ||
id: string; | ||
|
||
@ManyToOne(() => User, (user) => user.blockers, { nullable: false }) | ||
@JoinColumn({ name: 'blocker', referencedColumnName: 'id' }) | ||
blocker: User; | ||
|
||
@ManyToOne(() => User, (user) => user.blockeds, { nullable: false }) | ||
@JoinColumn({ name: 'blocked', referencedColumnName: 'id' }) | ||
blocked: User; | ||
} |
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,2 +1,3 @@ | ||
export const DATA_SOURCE = 'DATA_SOURCE'; | ||
export const USERS_REPOSITORY = 'USERS_REPOSITORY'; | ||
export const BLOCK_REPOSITORY = 'BLOCK_REPOSITORY'; |
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 |
---|---|---|
@@ -1,11 +1,21 @@ | ||
import { Block } from './entities/block.entity'; | ||
import { User } from './entities/user.entity'; | ||
import { DataSource } from 'typeorm'; | ||
import { DATA_SOURCE, USERS_REPOSITORY } from './users.constants'; | ||
import { | ||
BLOCK_REPOSITORY, | ||
DATA_SOURCE, | ||
USERS_REPOSITORY, | ||
} from './users.constants'; | ||
|
||
export const usersProvider = [ | ||
{ | ||
provide: USERS_REPOSITORY, | ||
useFactory: (dataSource: DataSource) => dataSource.getRepository(User), | ||
inject: [DATA_SOURCE], | ||
}, | ||
{ | ||
provide: BLOCK_REPOSITORY, | ||
useFactory: (dataSource: DataSource) => dataSource.getRepository(Block), | ||
inject: [DATA_SOURCE], | ||
}, | ||
]; |
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