feat(api): handle Dakao registrations
This commit is contained in:
1 parent
404f7713b9
commit
3b2ac601a0
8 files changed
+2383
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import mongoose from 'mongoose';
|
||||
import { Position } from '../../global/database/schema';
|
||||
import { DakaoSegment } from '../dakao.types';
|
||||
import { DakaoUserService } from '../dakao-user.service';
|
||||
|
||||
const POSITION_LABELS: Record<Position, string> = {
|
||||
TOP: '탑',
|
||||
JGL: '정글',
|
||||
MID: '미드',
|
||||
ADC: '원딜',
|
||||
SUP: '서포터',
|
||||
};
|
||||
|
||||
interface PreferredPositionRegisterHandlerParams {
|
||||
communityId: mongoose.Types.ObjectId;
|
||||
senderUserId: string;
|
||||
senderNickname: string;
|
||||
positions: Position[];
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class PreferredPositionRegisterHandler {
|
||||
constructor(private readonly dakaoUserService: DakaoUserService) {}
|
||||
|
||||
public async handle(
|
||||
params: PreferredPositionRegisterHandlerParams,
|
||||
): Promise<DakaoSegment[]> {
|
||||
const user = await this.dakaoUserService.registerPreferredPositions({
|
||||
communityId: params.communityId,
|
||||
kakaoTalkId: params.senderUserId,
|
||||
kakaoTalkNickname: params.senderNickname,
|
||||
positions: params.positions,
|
||||
});
|
||||
|
||||
return [
|
||||
{
|
||||
kind: 'mention',
|
||||
userId: params.senderUserId,
|
||||
displayText: params.senderNickname,
|
||||
},
|
||||
{
|
||||
kind: 'text',
|
||||
text:
|
||||
` 선호 포지션 등록 완료` +
|
||||
`\n포지션: ${user.preferredPositions
|
||||
.sort((left, right) => left.priority - right.priority)
|
||||
.map((entry) => POSITION_LABELS[entry.position])
|
||||
.join(', ')}` +
|
||||
`\n이제 !내전 신청 <내전코드> 로 간단히 신청할 수 있습니다.`,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user