- Phase 1: 모든 서비스 헤더에 알림 벨 UI 추가 (notification-bell.js) - Phase 2: VAPID Web Push 구독/전송 (push-sw.js, pushSubscription API) - Phase 3: 내부 알림 API + notifyHelper로 서비스간 알림 연동 - tksafety: 출입 승인/반려, 안전교육 완료, 방문자 체크인 - tkpurchase: 일용공 신청, 작업보고서 제출 - system2-report: 신고 접수/확인/처리완료 - Phase 4: 30일 이상 알림 자동 정리 cron, Redis 캐싱 - CORS에 tkuser/tkpurchase/tksafety 서브도메인 추가 - HTML cache busting 버전 갱신 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
// models/pushSubscriptionModel.js
|
|
const { getDb } = require('../dbPool');
|
|
|
|
const pushSubscriptionModel = {
|
|
async subscribe(userId, subscription) {
|
|
const db = await getDb();
|
|
const { endpoint, keys } = subscription;
|
|
await db.query(
|
|
`INSERT INTO push_subscriptions (user_id, endpoint, p256dh, auth)
|
|
VALUES (?, ?, ?, ?)
|
|
ON DUPLICATE KEY UPDATE user_id = VALUES(user_id), p256dh = VALUES(p256dh), auth = VALUES(auth)`,
|
|
[userId, endpoint, keys.p256dh, keys.auth]
|
|
);
|
|
},
|
|
|
|
async unsubscribe(endpoint) {
|
|
const db = await getDb();
|
|
await db.query('DELETE FROM push_subscriptions WHERE endpoint = ?', [endpoint]);
|
|
},
|
|
|
|
async getByUserId(userId) {
|
|
const db = await getDb();
|
|
const [rows] = await db.query(
|
|
'SELECT * FROM push_subscriptions WHERE user_id = ?',
|
|
[userId]
|
|
);
|
|
return rows;
|
|
},
|
|
|
|
async getByUserIds(userIds) {
|
|
if (!userIds || userIds.length === 0) return [];
|
|
const db = await getDb();
|
|
const [rows] = await db.query(
|
|
'SELECT * FROM push_subscriptions WHERE user_id IN (?)',
|
|
[userIds]
|
|
);
|
|
return rows;
|
|
},
|
|
|
|
async getAll() {
|
|
const db = await getDb();
|
|
const [rows] = await db.query('SELECT * FROM push_subscriptions');
|
|
return rows;
|
|
},
|
|
|
|
async deleteByEndpoint(endpoint) {
|
|
const db = await getDb();
|
|
await db.query('DELETE FROM push_subscriptions WHERE endpoint = ?', [endpoint]);
|
|
}
|
|
};
|
|
|
|
module.exports = pushSubscriptionModel;
|