55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
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이제 !내전 신청 <내전코드> 로 간단히 신청할 수 있습니다.`,
|
|
},
|
|
];
|
|
}
|
|
}
|