Skip to content

Commit

Permalink
Merge pull request #53 from TeamSparker/feature/pushAlarm
Browse files Browse the repository at this point in the history
[FEAT] PUSH ALARM Test Code
  • Loading branch information
youngkwon02 authored Jan 15, 2022
2 parents baa181c + 04cfc6b commit 2e42664
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions functions/api/routes/notice/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { checkUser } = require('../../../middlewares/auth');

router.use('/active', require('./active'));
router.use('/service', require('./service'));
router.use('/push', require('./push'));

router.delete('/:noticeId', checkUser, require('./noticeDELETE'));

Expand Down
6 changes: 6 additions & 0 deletions functions/api/routes/notice/push/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const express = require('express');
const router = express.Router();

router.get('/test', require('./pushTestGET'));

module.exports = router;
50 changes: 50 additions & 0 deletions functions/api/routes/notice/push/pushTestGET.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const admin = require('firebase-admin');
const functions = require('firebase-functions');
const util = require('../../../../lib/util');
const statusCode = require('../../../../constants/statusCode');
const responseMessage = require('../../../../constants/responseMessage');
const db = require('../../../../db/db');

/**
* @푸시알림_테스트
* @route GET /push/test
* @error
*/

module.exports = async (req, res) => {
let client;

try {
client = await db.connect(req);

const deviceToken = 'dviwPjY0Raek7xHgxxqAI8:APA91bEI8x3J9Zf86WlJrMPLUo6XVrInagEb-m1qNeo8ccTtG-mJ45cXkFk62ko1AQcQJZpCQXxLGYpByAiMKZfa57Ckt_6sl1BeiETbaXlTHUgoJmy3iUvJz3pK_KlSzWGkbYBnXNnf';
let message = {
data: {
title: '테스트 데이터 발송',
body: '데이터가 잘 가나요?',
hello: 'hh',
},
token: deviceToken,
};

admin
.messaging()
.send(message)
.then(function (response) {
console.log('Successfully sent message: : ', response);
return res.status(200).json({ success: true });
})
.catch(function (err) {
console.log('Error Sending message!!! : ', err);
return res.status(400).json({ success: false });
});

res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.PUSH_SEND_SUCCESS));
} catch (error) {
functions.logger.error(`[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl}`, `[CONTENT] ${error}`);
console.log(error);
res.status(statusCode.INTERNAL_SERVER_ERROR).send(util.fail(statusCode.INTERNAL_SERVER_ERROR, responseMessage.INTERNAL_SERVER_ERROR));
} finally {
client.release();
}
};
1 change: 1 addition & 0 deletions functions/constants/responseMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ module.exports = {
ACTIVE_GET_SUCCESS: '활동 알림 조회 완료',
NOTICE_DELETE_SUCCESS: '알림 삭제 완료',
NOTICE_ID_NOT_VALID: '유효하지 않은 알림 ID 입니다',
PUSH_SEND_SUCCESS: '푸시알림 전송 완료',
};
2 changes: 1 addition & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"eslint-config-prettier": "^8.3.0",
"express": "^4.17.2",
"firebase": "^9.5.0",
"firebase-admin": "^9.2.0",
"firebase-admin": "^9.12.0",
"firebase-functions": "^3.11.0",
"helmet": "^4.6.0",
"hpp": "^0.2.3",
Expand Down

0 comments on commit 2e42664

Please sign in to comment.