Compare commits
4
Commits
release/66
...
994a9fcad0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
994a9fcad0 | ||
|
|
2dae3c7cae | ||
|
|
a896342429 | ||
|
|
7b636ee793 |
No files matched your search
@@ -0,0 +1,116 @@
|
||||
import { ConnectionService } from '../global/database/connection.service';
|
||||
import { NatsService } from '../global/nats/nats.service';
|
||||
import { DakaoOutboxService } from './dakao-outbox.service';
|
||||
import { DakaoResultSubjects } from './dakao.types';
|
||||
|
||||
function execResult<T>(value: T) {
|
||||
return { exec: jest.fn().mockResolvedValue(value) };
|
||||
}
|
||||
|
||||
function makeService(outboxModel: Record<string, unknown>) {
|
||||
const connectionService = {
|
||||
getModel: jest.fn().mockResolvedValue(outboxModel),
|
||||
} as unknown as ConnectionService;
|
||||
const natsService = {
|
||||
publishJetStream: jest.fn().mockResolvedValue(undefined),
|
||||
} as unknown as NatsService;
|
||||
|
||||
return {
|
||||
service: new DakaoOutboxService(connectionService, natsService),
|
||||
connectionService,
|
||||
natsService,
|
||||
};
|
||||
}
|
||||
|
||||
describe('DakaoOutboxService', () => {
|
||||
it('persists result subjects when enqueuing send-message commands', async () => {
|
||||
const outboxModel = {
|
||||
findOneAndUpdate: jest.fn().mockReturnValue(execResult({})),
|
||||
updateOne: jest.fn().mockReturnValue(execResult({})),
|
||||
};
|
||||
const { service, natsService } = makeService(outboxModel);
|
||||
const resultSubjects: DakaoResultSubjects = {
|
||||
succeeded: 'staging.lolympus.dakao.chat.send-message.succeeded.v1',
|
||||
failed: 'staging.lolympus.dakao.chat.send-message.failed.v1',
|
||||
};
|
||||
|
||||
await service.enqueueAndPublish({
|
||||
subject: 'staging.dakao.chat.send-message.v1',
|
||||
eventId: 'lolympus:chat.send-message:chat-log-1',
|
||||
envelope: {
|
||||
schema: 'dakao.command.v1',
|
||||
eventId: 'lolympus:chat.send-message:chat-log-1',
|
||||
type: 'chat.send-message',
|
||||
eventSource: 'lolympus',
|
||||
correlationId: 'chat-log-1',
|
||||
resultSubjects,
|
||||
payload: {
|
||||
chatroomId: '18474390111480678',
|
||||
segments: [{ kind: 'text', text: 'done' }],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(outboxModel.findOneAndUpdate).toHaveBeenCalledWith(
|
||||
{ eventId: 'lolympus:chat.send-message:chat-log-1' },
|
||||
expect.objectContaining({
|
||||
$setOnInsert: expect.objectContaining({ resultSubjects }),
|
||||
}),
|
||||
expect.any(Object),
|
||||
);
|
||||
expect(natsService.publishJetStream).toHaveBeenCalledWith(
|
||||
'staging.dakao.chat.send-message.v1',
|
||||
expect.objectContaining({ resultSubjects }),
|
||||
{ messageId: 'lolympus:chat.send-message:chat-log-1' },
|
||||
);
|
||||
});
|
||||
|
||||
it('restores send-message result subjects when sweeping legacy stale rows', async () => {
|
||||
const previousNodeEnv = process.env.NODE_ENV;
|
||||
process.env.NODE_ENV = 'staging';
|
||||
|
||||
try {
|
||||
const exec = jest.fn().mockResolvedValue([
|
||||
{
|
||||
eventId: 'lolympus:chat.send-message:chat-log-1',
|
||||
type: 'chat.send-message',
|
||||
eventSource: 'lolympus',
|
||||
subject: 'staging.dakao.chat.send-message.v1',
|
||||
correlationId: 'chat-log-1',
|
||||
payload: {
|
||||
chatroomId: '18474390111480678',
|
||||
segments: [{ kind: 'text', text: 'done' }],
|
||||
},
|
||||
},
|
||||
]);
|
||||
const lean = jest.fn().mockReturnValue({ exec });
|
||||
const limit = jest.fn().mockReturnValue({ lean });
|
||||
const sort = jest.fn().mockReturnValue({ limit });
|
||||
const outboxModel = {
|
||||
find: jest.fn().mockReturnValue({ sort }),
|
||||
};
|
||||
const { service } = makeService(outboxModel);
|
||||
const enqueue = jest
|
||||
.spyOn(service, 'enqueueAndPublish')
|
||||
.mockResolvedValue(undefined);
|
||||
|
||||
await expect(service.sweepStale({ staleMs: 1, limit: 1 })).resolves.toBe(
|
||||
1,
|
||||
);
|
||||
|
||||
expect(enqueue).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
envelope: expect.objectContaining({
|
||||
resultSubjects: {
|
||||
succeeded:
|
||||
'staging.lolympus.dakao.chat.send-message.succeeded.v1',
|
||||
failed: 'staging.lolympus.dakao.chat.send-message.failed.v1',
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
} finally {
|
||||
process.env.NODE_ENV = previousNodeEnv;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,13 +1,23 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { ConnectionService } from '../global/database/connection.service';
|
||||
import { NatsService } from '../global/nats/nats.service';
|
||||
import { DakaoCommandEnvelope, DakaoResultEnvelope } from './dakao.types';
|
||||
import { resolveDakaoNatsNames } from './dakao.nats-names';
|
||||
import {
|
||||
DakaoCommandEnvelope,
|
||||
DakaoResultEnvelope,
|
||||
DakaoResultSubjects,
|
||||
} from './dakao.types';
|
||||
|
||||
const CHAT_SEND_MESSAGE_TYPE = 'chat.send-message';
|
||||
const TERMINAL_STATES = ['sent', 'failed'] as const;
|
||||
|
||||
@Injectable()
|
||||
export class DakaoOutboxService {
|
||||
private readonly logger = new Logger(DakaoOutboxService.name);
|
||||
private readonly chatSendMessageResultSubjects = {
|
||||
succeeded: resolveDakaoNatsNames().subjects.chatSendMessageSucceeded,
|
||||
failed: resolveDakaoNatsNames().subjects.chatSendMessageFailed,
|
||||
};
|
||||
|
||||
constructor(
|
||||
private readonly connectionService: ConnectionService,
|
||||
@@ -30,6 +40,7 @@ export class DakaoOutboxService {
|
||||
type: params.envelope.type,
|
||||
subject: params.subject,
|
||||
correlationId: params.envelope.correlationId,
|
||||
resultSubjects: params.envelope.resultSubjects,
|
||||
payload: params.envelope.payload as Record<string, unknown>,
|
||||
state: 'pending',
|
||||
publishAttempts: 0,
|
||||
@@ -161,6 +172,8 @@ export class DakaoOutboxService {
|
||||
type: row.type,
|
||||
eventSource: row.eventSource,
|
||||
correlationId: row.correlationId,
|
||||
resultSubjects:
|
||||
row.resultSubjects ?? this.resolveDefaultResultSubjects(row.type),
|
||||
payload: row.payload,
|
||||
},
|
||||
});
|
||||
@@ -168,4 +181,11 @@ export class DakaoOutboxService {
|
||||
|
||||
return rows.length;
|
||||
}
|
||||
|
||||
private resolveDefaultResultSubjects(
|
||||
type: string,
|
||||
): DakaoResultSubjects | undefined {
|
||||
if (type !== CHAT_SEND_MESSAGE_TYPE) return undefined;
|
||||
return this.chatSendMessageResultSubjects;
|
||||
}
|
||||
}
|
||||
@@ -350,6 +350,10 @@ export interface DakaoOutboxMessage extends MongooseTimestamps {
|
||||
type: string;
|
||||
subject: string;
|
||||
correlationId?: string;
|
||||
resultSubjects?: {
|
||||
succeeded: string;
|
||||
failed: string;
|
||||
};
|
||||
payload: Record<string, unknown>;
|
||||
state: DakaoOutboxMessageState;
|
||||
publishAttempts: number;
|
||||
@@ -960,6 +964,10 @@ export const DakaoOutboxMessageSchema = new Schema<DakaoOutboxMessage>(
|
||||
type: { type: String, required: true },
|
||||
subject: { type: String, required: true },
|
||||
correlationId: { type: String },
|
||||
resultSubjects: {
|
||||
succeeded: { type: String },
|
||||
failed: { type: String },
|
||||
},
|
||||
payload: { type: Schema.Types.Mixed, required: true },
|
||||
state: {
|
||||
type: String,
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"start:dev": "vite --mode development",
|
||||
"start:staging": "vite --mode staging",
|
||||
"build": "tsc -b && vite build",
|
||||
"build:staging": "tsc -b && vite build --mode staging",
|
||||
"build:prod": "tsc -b && vite build --mode production",
|
||||
|
||||
@@ -3,6 +3,9 @@ import { mapApiMatchToMatchDetail } from '../api/mappers';
|
||||
import { useMatches, useMe } from '../api/hooks';
|
||||
import { DEFAULT_COMMUNITY_ID } from '../config';
|
||||
|
||||
const UPCOMING_GRID_MATCH_LIMIT = 3;
|
||||
const UPCOMING_MATCH_LIST_LIMIT = UPCOMING_GRID_MATCH_LIMIT + 1;
|
||||
|
||||
function StatusBadge({ status }: { status: string }) {
|
||||
const styles: Record<string, string> = {
|
||||
모집중: 'bg-green-500/15 text-green-500 border-green-500/20',
|
||||
@@ -44,7 +47,10 @@ function getStatusLabel(status: string) {
|
||||
}
|
||||
|
||||
export default function HomePage() {
|
||||
const upcomingMatchesQuery = useMatches({ limit: 20 }, DEFAULT_COMMUNITY_ID);
|
||||
const upcomingMatchesQuery = useMatches(
|
||||
{ limit: UPCOMING_MATCH_LIST_LIMIT },
|
||||
DEFAULT_COMMUNITY_ID,
|
||||
);
|
||||
const finishedMatchesQuery = useMatches(
|
||||
{ status: 'finished', limit: 10 },
|
||||
DEFAULT_COMMUNITY_ID,
|
||||
@@ -84,7 +90,10 @@ export default function HomePage() {
|
||||
const finishedMatches =
|
||||
finishedMatchesQuery.data?.map(mapApiMatchToMatchDetail) ?? [];
|
||||
const nextMatch = upcomingMatches[0];
|
||||
const upcomingCards = nextMatch ? upcomingMatches.slice(1) : upcomingMatches;
|
||||
const upcomingCards = (nextMatch
|
||||
? upcomingMatches.slice(1)
|
||||
: upcomingMatches
|
||||
).slice(0, UPCOMING_GRID_MATCH_LIMIT);
|
||||
const currentUser =
|
||||
meQuery.data?.memberships.find(
|
||||
(membership) => membership.community?._id === DEFAULT_COMMUNITY_ID,
|
||||
|
||||
@@ -24,6 +24,7 @@ import { DEFAULT_COMMUNITY_ID, useAuthUserId } from "../config";
|
||||
import { apiFetch, ApiError } from "../lib/api";
|
||||
import { profileIconUrl } from "../lib/ddragon";
|
||||
import {
|
||||
POSITION_ORDER,
|
||||
positionIcon,
|
||||
positionLabel,
|
||||
sideShortLabel,
|
||||
@@ -52,6 +53,38 @@ type CaptainSelection = {
|
||||
const DEFAULT_AUCTION_MAX_TIMER_SECONDS = 30;
|
||||
const DEFAULT_AUCTION_BID_EXTENSION_SECONDS = 5;
|
||||
const MAX_AUCTION_TIMER_SECONDS = 3600;
|
||||
const ALL_PARTICIPANT_FILTER = "all";
|
||||
|
||||
type ParticipantPositionFilter = Position | typeof ALL_PARTICIPANT_FILTER;
|
||||
type ParticipantTierFilter = string | typeof ALL_PARTICIPANT_FILTER;
|
||||
|
||||
const PARTICIPANT_TIER_FILTERS = [
|
||||
"CHALLENGER",
|
||||
"GRANDMASTER",
|
||||
"MASTER",
|
||||
"DIAMOND",
|
||||
"EMERALD",
|
||||
"PLATINUM",
|
||||
"GOLD",
|
||||
"SILVER",
|
||||
"BRONZE",
|
||||
"IRON",
|
||||
"UNRANKED",
|
||||
] as const;
|
||||
|
||||
const PARTICIPANT_TIER_LABELS: Record<string, string> = {
|
||||
CHALLENGER: "챌린저",
|
||||
GRANDMASTER: "그랜드마스터",
|
||||
MASTER: "마스터",
|
||||
DIAMOND: "다이아몬드",
|
||||
EMERALD: "에메랄드",
|
||||
PLATINUM: "플래티넘",
|
||||
GOLD: "골드",
|
||||
SILVER: "실버",
|
||||
BRONZE: "브론즈",
|
||||
IRON: "아이언",
|
||||
UNRANKED: "언랭크",
|
||||
};
|
||||
|
||||
function captainSlotKey(slot: CaptainSelectionSlot) {
|
||||
return String(slot.teamIndex);
|
||||
@@ -270,6 +303,19 @@ function statusBadge(status: MatchDetailView["status"]) {
|
||||
}
|
||||
}
|
||||
|
||||
function participantTierFilterValue(participant: ParticipantView) {
|
||||
return participant.tier?.tier ?? "UNRANKED";
|
||||
}
|
||||
|
||||
// PARTICIPANT_TIER_FILTERS는 높은 티어 → 낮은 티어 순서이므로
|
||||
// 인덱스가 작을수록 상위 티어. (없는 값은 최하위로 취급)
|
||||
function tierRank(tier: string) {
|
||||
const index = PARTICIPANT_TIER_FILTERS.indexOf(
|
||||
tier as (typeof PARTICIPANT_TIER_FILTERS)[number],
|
||||
);
|
||||
return index === -1 ? PARTICIPANT_TIER_FILTERS.length : index;
|
||||
}
|
||||
|
||||
function ParticipantRow({
|
||||
participant,
|
||||
index,
|
||||
@@ -353,6 +399,47 @@ function ParticipantTable({
|
||||
onJoin: () => void;
|
||||
isJoining: boolean;
|
||||
}) {
|
||||
const [positionFilter, setPositionFilter] =
|
||||
useState<ParticipantPositionFilter>(ALL_PARTICIPANT_FILTER);
|
||||
const [tierFilter, setTierFilter] = useState<ParticipantTierFilter>(
|
||||
ALL_PARTICIPANT_FILTER,
|
||||
);
|
||||
const filteredParticipants = participants.filter((participant) => {
|
||||
const matchesPosition =
|
||||
positionFilter === ALL_PARTICIPANT_FILTER ||
|
||||
participant.mainPosition === positionFilter;
|
||||
const matchesTier =
|
||||
tierFilter === ALL_PARTICIPANT_FILTER ||
|
||||
tierRank(participantTierFilterValue(participant)) <= tierRank(tierFilter);
|
||||
|
||||
return matchesPosition && matchesTier;
|
||||
});
|
||||
const isFiltered =
|
||||
positionFilter !== ALL_PARTICIPANT_FILTER ||
|
||||
tierFilter !== ALL_PARTICIPANT_FILTER;
|
||||
const positionFilteredParticipants = participants.filter(
|
||||
(participant) =>
|
||||
positionFilter === ALL_PARTICIPANT_FILTER ||
|
||||
participant.mainPosition === positionFilter,
|
||||
);
|
||||
// "이상" 임계값으로 쓸 수 있는 티어 = 참가자 중 실제 존재하는 티어.
|
||||
// 언랭크는 "이상" 기준으로 전체와 동일하므로 임계값 후보에서 제외한다.
|
||||
const presentTiers = new Set(
|
||||
positionFilteredParticipants.map(participantTierFilterValue),
|
||||
);
|
||||
const availableTiers = PARTICIPANT_TIER_FILTERS.filter(
|
||||
(tier) => tier !== "UNRANKED" && presentTiers.has(tier),
|
||||
);
|
||||
const tierAtOrAboveCounts = new Map<string, number>(
|
||||
availableTiers.map((tier) => [
|
||||
tier,
|
||||
positionFilteredParticipants.filter(
|
||||
(participant) =>
|
||||
tierRank(participantTierFilterValue(participant)) <= tierRank(tier),
|
||||
).length,
|
||||
]),
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="border border-base-content/10 bg-base-100 overflow-hidden">
|
||||
<div className="px-4 py-2.5 border-b border-base-content/10 bg-base-200/40 flex items-center justify-between gap-3">
|
||||
@@ -368,6 +455,84 @@ function ParticipantTable({
|
||||
{joined ? "참가 완료" : isJoining ? "신청 중..." : "참가 신청"}
|
||||
</button>
|
||||
</div>
|
||||
<div className="border-b border-base-content/10 bg-base-100 px-4 py-2.5">
|
||||
<div className="flex flex-wrap items-center gap-x-3 gap-y-2">
|
||||
<div className="inline-flex items-center gap-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setPositionFilter(ALL_PARTICIPANT_FILTER)}
|
||||
className={`inline-flex h-8 items-center px-2.5 text-[11px] font-semibold border transition-colors ${
|
||||
positionFilter === ALL_PARTICIPANT_FILTER
|
||||
? "border-primary/30 bg-primary/5 text-primary"
|
||||
: "border-base-content/10 text-base-content/40 hover:text-base-content/70"
|
||||
}`}
|
||||
>
|
||||
전체
|
||||
</button>
|
||||
{POSITION_ORDER.map((position) => {
|
||||
const active = positionFilter === position;
|
||||
return (
|
||||
<button
|
||||
key={position}
|
||||
type="button"
|
||||
title={positionLabel[position]}
|
||||
aria-label={positionLabel[position]}
|
||||
aria-pressed={active}
|
||||
onClick={() =>
|
||||
setPositionFilter(
|
||||
active ? ALL_PARTICIPANT_FILTER : position,
|
||||
)
|
||||
}
|
||||
className={`inline-flex h-8 items-center gap-1 px-2 text-[11px] font-semibold border transition-colors ${
|
||||
active
|
||||
? "border-primary/30 bg-primary/5 text-primary"
|
||||
: "border-base-content/10 text-base-content/40 hover:text-base-content/70"
|
||||
}`}
|
||||
>
|
||||
<img
|
||||
src={positionIcon[position]}
|
||||
alt=""
|
||||
className="h-3.5 w-3.5 object-contain"
|
||||
/>
|
||||
<span className="hidden sm:inline">
|
||||
{positionLabel[position]}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<select
|
||||
className="h-8 border border-base-content/10 bg-base-100 px-2 text-xs text-base-content focus:border-primary/30 focus:outline-none"
|
||||
value={tierFilter}
|
||||
onChange={(event) => setTierFilter(event.target.value)}
|
||||
>
|
||||
<option value={ALL_PARTICIPANT_FILTER}>티어 전체</option>
|
||||
{availableTiers.map((tier) => (
|
||||
<option key={tier} value={tier}>
|
||||
{PARTICIPANT_TIER_LABELS[tier]} 이상 (
|
||||
{tierAtOrAboveCounts.get(tier)})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="ml-auto flex items-center gap-2 text-[11px] text-base-content/35">
|
||||
<span>
|
||||
{filteredParticipants.length}/{participants.length}명
|
||||
</span>
|
||||
{isFiltered && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-xs h-8 min-h-8 px-2 text-[11px] text-base-content/40"
|
||||
onClick={() => {
|
||||
setPositionFilter(ALL_PARTICIPANT_FILTER);
|
||||
setTierFilter(ALL_PARTICIPANT_FILTER);
|
||||
}}
|
||||
>
|
||||
초기화
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left">
|
||||
<thead>
|
||||
@@ -380,13 +545,24 @@ function ParticipantTable({
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{participants.map((participant, index) => (
|
||||
<ParticipantRow
|
||||
key={participant.id}
|
||||
participant={participant}
|
||||
index={index}
|
||||
/>
|
||||
))}
|
||||
{filteredParticipants.length > 0 ? (
|
||||
filteredParticipants.map((participant, index) => (
|
||||
<ParticipantRow
|
||||
key={participant.id}
|
||||
participant={participant}
|
||||
index={index}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td
|
||||
colSpan={5}
|
||||
className="px-3 py-8 text-center text-sm text-base-content/35"
|
||||
>
|
||||
조건에 맞는 참가자가 없습니다.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
"start:api:staging": "pnpm --filter api start:staging",
|
||||
"start:api:prod": "pnpm --filter api start:prod",
|
||||
"start:api": "pnpm --filter api start:prod",
|
||||
"start:web:dev": "pnpm --filter web start:dev",
|
||||
"start:web:staging": "pnpm --filter web start:staging",
|
||||
"build:api": "pnpm --filter api build",
|
||||
"dev:web": "pnpm --filter web dev",
|
||||
"build:web:staging": "pnpm --filter web build:staging",
|
||||
|
||||
Reference in new issue
Block a user