|
|
@ -138,25 +138,6 @@ router.post(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
router.get<{ key: string }>(
|
|
|
|
|
|
|
|
'/:key/pushSubscription',
|
|
|
|
|
|
|
|
async (req, res, next) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const userPushSubRepository = getRepository(UserPushSubscription);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const userPushSub = await userPushSubRepository.findOneOrFail({
|
|
|
|
|
|
|
|
where: {
|
|
|
|
|
|
|
|
p256dh: req.params.key,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json(userPushSub);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
next({ status: 404, message: 'User subscription not found.' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
router.post<
|
|
|
|
router.post<
|
|
|
|
never,
|
|
|
|
never,
|
|
|
|
unknown,
|
|
|
|
unknown,
|
|
|
@ -199,14 +180,43 @@ router.post<
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
router.delete<{ key: string }>(
|
|
|
|
router.get<{ userId: number; key: string }>(
|
|
|
|
'/:key/pushSubscription',
|
|
|
|
'/:userId/pushSubscription/:key',
|
|
|
|
async (req, res, next) => {
|
|
|
|
async (req, res, next) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const userPushSubRepository = getRepository(UserPushSubscription);
|
|
|
|
const userPushSubRepository = getRepository(UserPushSubscription);
|
|
|
|
|
|
|
|
|
|
|
|
const userPushSub = await userPushSubRepository.findOneOrFail({
|
|
|
|
const userPushSub = await userPushSubRepository.findOneOrFail({
|
|
|
|
where: { p256dh: req.params.key },
|
|
|
|
relations: {
|
|
|
|
|
|
|
|
user: true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
where: {
|
|
|
|
|
|
|
|
user: { id: req.params.userId },
|
|
|
|
|
|
|
|
p256dh: req.params.key,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json(userPushSub);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
next({ status: 404, message: 'User subscription not found.' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
router.delete<{ userId: number; key: string }>(
|
|
|
|
|
|
|
|
'/:userId/pushSubscription/:key',
|
|
|
|
|
|
|
|
async (req, res, next) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const userPushSubRepository = getRepository(UserPushSubscription);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const userPushSub = await userPushSubRepository.findOneOrFail({
|
|
|
|
|
|
|
|
relations: {
|
|
|
|
|
|
|
|
user: true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
where: {
|
|
|
|
|
|
|
|
user: { id: req.params.userId },
|
|
|
|
|
|
|
|
p256dh: req.params.key,
|
|
|
|
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
await userPushSubRepository.remove(userPushSub);
|
|
|
|
await userPushSubRepository.remove(userPushSub);
|
|
|
|