-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 차단리스트 엔티티 생성, makeBlockUser 라우터 추가, 차단 사용자 이벤트 필터링 실패에~
- Loading branch information
1 parent
0bedd82
commit cd01fd0
Showing
9 changed files
with
152 additions
and
4 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,35 @@ | ||
import {Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn} from 'typeorm' | ||
import User from './User' | ||
import {Infer} from '../common/utils/zod'; | ||
import {BlockUserResponseScheme} from './schemes'; | ||
import BaseBetterEntity from '../common/base/BaseBetterEntity'; | ||
|
||
@Entity() | ||
export default class BlockedList extends BaseBetterEntity { | ||
static relations = ['user']; | ||
|
||
@PrimaryGeneratedColumn({comment: '식별자.'}) | ||
id: number | ||
|
||
@ManyToOne(() => User, (u) => u.events) | ||
@JoinColumn() | ||
blockingUser: User; | ||
|
||
@ManyToOne(() => User, (u) => u.events) | ||
@JoinColumn() | ||
blockedUser: User; | ||
|
||
@CreateDateColumn({comment: '차단 일시.'}) | ||
createdAt: Date; | ||
|
||
|
||
async toResponse(userId?: number): Promise<Infer<typeof BlockUserResponseScheme>> { | ||
return { | ||
id: this.id, | ||
blockingUserId: this.blockingUser.id, | ||
blockedUserId: this.blockedUser.id, | ||
createdAt: this.createdAt | ||
|
||
} | ||
} | ||
} |
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,20 @@ | ||
import {defineSchema} from '../../libs/schema'; | ||
import {defineRoute} from '../../libs/route'; | ||
import {authorizer} from '../../middleware/authorizer'; | ||
import {BlockUserRequestScheme} from "../../../entity/schemes"; | ||
import BlockingService from "../../../service/BlockingService"; | ||
|
||
|
||
const schema = defineSchema({ | ||
summary: '차단할 사용자를 지정합니다.', | ||
description: '네.', | ||
|
||
body: BlockUserRequestScheme | ||
}); | ||
|
||
export default defineRoute('post', '/blockuser', schema, authorizer(), async (req, res) => { | ||
const userId = req.requireUserId(); | ||
await BlockingService.makeBlock(userId, req.body); | ||
|
||
res.send(); | ||
}); |
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,32 @@ | ||
import Event from '../entity/Event'; | ||
import {log} from '../common/utils/log'; | ||
import {preview} from '../server/libs/json'; | ||
import User from '../entity/User'; | ||
import Comment from '../entity/Comment'; | ||
import EventLike from '../entity/EventLike'; | ||
import EventNotification from '../entity/EventNotification'; | ||
import UserService from './UserService'; | ||
import SubscriptionService from './SubscriptionService'; | ||
import {Infer} from '../common/utils/zod'; | ||
import {BlockUserRequestScheme, EventRequestScheme} from '../entity/schemes'; | ||
import BlockedList from "../entity/BlockedList"; | ||
|
||
class BlockingService { | ||
|
||
async makeBlock(userId: number, body: Infer<typeof BlockUserRequestScheme>): Promise<BlockedList> { | ||
const blockingUser = await UserService.getUser(userId); | ||
|
||
const blockList = await BlockedList.create({ | ||
blockingUser: blockingUser, | ||
blockedUser: body.blockedUserId, | ||
}).save(); | ||
|
||
log(`[사용자${blockingUser.id}]가 [사용자${preview(body.blockedUserId)}] 를 차단합니다.`); | ||
return blockList; | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
export default new BlockingService(); |
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