Files
bowlingManager/backend/utils/notificationExamples.js
2025-04-17 23:32:39 +09:00

161 lines
4.6 KiB
JavaScript

/**
* 알림 생성 예제 유틸리티
* 다양한 상황에서 알림을 생성하는 예제 함수들을 제공합니다.
*/
const notificationController = require('../controllers/notificationController');
/**
* 새 회원 가입 알림 생성
* @param {Object} clubOwner 클럽 소유자 정보
* @param {Object} newMember 새로 가입한 회원 정보
*/
exports.newMemberJoinNotification = async (clubOwner, newMember) => {
await notificationController.createSystemNotification(
clubOwner.id,
'새 회원 가입',
`${newMember.name}님이 클럽에 가입했습니다.`,
{
icon: 'pi pi-users',
type: 'success',
link: `/club/members/${newMember.id}`
}
);
};
/**
* 모임 생성 알림 생성
* @param {Array} members 알림을 받을 회원 목록
* @param {Object} meeting 생성된 모임 정보
*/
exports.newMeetingNotification = async (members, meeting) => {
for (const member of members) {
await notificationController.createSystemNotification(
member.id,
'새 모임 생성',
`새로운 모임 "${meeting.title}"이(가) 생성되었습니다. (${meeting.date})`,
{
icon: 'pi pi-calendar',
type: 'info',
link: `/meetings/${meeting.id}`
}
);
}
};
/**
* 점수 등록 알림 생성
* @param {Object} member 점수를 등록한 회원
* @param {Object} score 등록된 점수 정보
*/
exports.scoreRegisteredNotification = async (member, score) => {
await notificationController.createSystemNotification(
member.id,
'점수 등록 완료',
`게임 점수 ${score.score}점이 등록되었습니다.`,
{
icon: 'pi pi-chart-bar',
type: 'success',
link: `/scores/${score.id}`
}
);
};
/**
* 구독 만료 예정 알림 생성
* @param {Object} clubOwner 클럽 소유자 정보
* @param {Object} subscription 구독 정보
* @param {Number} daysLeft 만료까지 남은 일수
*/
exports.subscriptionExpiryNotification = async (clubOwner, subscription, daysLeft) => {
await notificationController.createSystemNotification(
clubOwner.id,
'구독 만료 예정',
`클럽 구독이 ${daysLeft}일 후에 만료됩니다. 갱신하시려면 결제를 진행해주세요.`,
{
icon: 'pi pi-clock',
type: 'warning',
link: '/subscription'
}
);
};
/**
* 시스템 유지보수 알림 생성
* @param {Array} users 알림을 받을 사용자 목록
* @param {String} maintenanceDate 유지보수 일자
* @param {String} maintenanceTime 유지보수 시간
*/
exports.systemMaintenanceNotification = async (users, maintenanceDate, maintenanceTime) => {
for (const user of users) {
await notificationController.createSystemNotification(
user.id,
'시스템 유지보수 안내',
`${maintenanceDate} ${maintenanceTime}에 시스템 유지보수가 예정되어 있습니다. 서비스 이용에 참고해주세요.`,
{
icon: 'pi pi-info-circle',
type: 'info'
}
);
}
};
/**
* 결제 완료 알림 생성
* @param {Object} user 결제한 사용자 정보
* @param {Object} payment 결제 정보
*/
exports.paymentCompletedNotification = async (user, payment) => {
await notificationController.createSystemNotification(
user.id,
'결제 완료',
`${payment.amount.toLocaleString()}원 결제가 완료되었습니다.`,
{
icon: 'pi pi-credit-card',
type: 'success',
link: '/payments/history'
}
);
};
/**
* 대회 일정 알림 생성
* @param {Array} participants 대회 참가자 목록
* @param {Object} tournament 대회 정보
*/
exports.tournamentReminderNotification = async (participants, tournament) => {
for (const participant of participants) {
await notificationController.createSystemNotification(
participant.id,
'대회 일정 안내',
`내일 "${tournament.title}" 대회가 ${tournament.location}에서 개최됩니다.`,
{
icon: 'pi pi-flag',
type: 'warning',
link: `/tournaments/${tournament.id}`
}
);
}
};
/**
* 오류 발생 알림 생성 (관리자용)
* @param {Array} admins 알림을 받을 관리자 목록
* @param {String} errorMessage 오류 메시지
* @param {String} errorLocation 오류 발생 위치
*/
exports.systemErrorNotification = async (admins, errorMessage, errorLocation) => {
for (const admin of admins) {
await notificationController.createSystemNotification(
admin.id,
'시스템 오류 발생',
`위치: ${errorLocation}\n오류: ${errorMessage}`,
{
icon: 'pi pi-exclamation-triangle',
type: 'error',
link: '/admin/logs'
}
);
}
};