feat: FCM 사용자별 타겟 알림 발송 기능 추가

- today_issues 테이블에 target_user_id 컬럼 추가 (마이그레이션)
- TodayIssue 모델: target_user_id 필드, targetUser 관계, forUser/targetedTo 스코프 추가
- TodayIssue 모델: 기안 상태 뱃지 상수 추가 (BADGE_DRAFT_APPROVED/REJECTED/COMPLETED)
- TodayIssueObserverService: createIssueWithFcm, sendFcmNotification, getEnabledUserTokens에 targetUserId 파라미터 추가
- TodayIssueObserverService: handleApprovalStepChange - 결재자에게만 발송
- TodayIssueObserverService: handleApprovalStatusChange 추가 - 기안자에게만 발송
- ApprovalIssueObserver 신규 생성 및 AppServiceProvider에 등록
- i18n: 기안 승인/반려/완료 알림 메시지 추가

결재요청은 결재자(ApprovalStep.user_id)에게만,
기안 승인/반려는 기안자(Approval.drafter_id)에게만 FCM 발송

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-28 13:52:43 +09:00
parent 518ae4657e
commit f74767563f
7 changed files with 244 additions and 9 deletions

View File

@@ -21,9 +21,11 @@ class TodayIssueService extends Service
public function summary(int $limit = 30, ?string $badge = null): array
{
$tenantId = $this->tenantId();
$userId = $this->apiUserId();
$query = TodayIssue::query()
->where('tenant_id', $tenantId)
->forUser($userId) // 본인 대상 또는 전체 브로드캐스트
->active() // 만료되지 않은 이슈만
->today() // 오늘 날짜 이슈만
->orderByDesc('created_at');
@@ -36,6 +38,7 @@ public function summary(int $limit = 30, ?string $badge = null): array
// 전체 개수 (필터 적용 전, 오늘 날짜만)
$totalQuery = TodayIssue::query()
->where('tenant_id', $tenantId)
->forUser($userId)
->active()
->today();
$totalCount = $totalQuery->count();
@@ -72,9 +75,11 @@ public function summary(int $limit = 30, ?string $badge = null): array
public function getUnreadList(int $limit = 10): array
{
$tenantId = $this->tenantId();
$userId = $this->apiUserId();
$issues = TodayIssue::query()
->where('tenant_id', $tenantId)
->forUser($userId) // 본인 대상 또는 전체 브로드캐스트
->unread()
->active()
->orderByDesc('created_at')
@@ -83,6 +88,7 @@ public function getUnreadList(int $limit = 10): array
$totalCount = TodayIssue::query()
->where('tenant_id', $tenantId)
->forUser($userId)
->unread()
->active()
->count();
@@ -115,9 +121,11 @@ public function getUnreadList(int $limit = 10): array
public function getUnreadCount(): int
{
$tenantId = $this->tenantId();
$userId = $this->apiUserId();
return TodayIssue::query()
->where('tenant_id', $tenantId)
->forUser($userId) // 본인 대상 또는 전체 브로드캐스트
->unread()
->active()
->count();
@@ -132,6 +140,7 @@ public function markAsRead(int $issueId): bool
$userId = $this->apiUserId();
$issue = TodayIssue::where('tenant_id', $tenantId)
->forUser($userId) // 본인 대상 또는 전체 브로드캐스트
->where('id', $issueId)
->first();
@@ -152,6 +161,7 @@ public function markAllAsRead(): int
return TodayIssue::query()
->where('tenant_id', $tenantId)
->forUser($userId) // 본인 대상 또는 전체 브로드캐스트
->unread()
->active()
->update([
@@ -177,9 +187,11 @@ public function dismiss(string $sourceType, int $sourceId): bool
public function countByBadge(): array
{
$tenantId = $this->tenantId();
$userId = $this->apiUserId();
$counts = TodayIssue::query()
->where('tenant_id', $tenantId)
->forUser($userId) // 본인 대상 또는 전체 브로드캐스트
->active()
->selectRaw('badge, COUNT(*) as count')
->groupBy('badge')