Skip to content

Commit

Permalink
feat: token을 업데이트 하는 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JeongSH1 committed Dec 8, 2023
1 parent ebee1e4 commit 6b7ee67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions db/save-token.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { connection } from "./connection.js";
import { getTokenByUserId } from "./get-token.js";

export async function saveToken(userId, token) {
const [rows, fields] = await connection.execute('insert into tokens values(?, ?)', [userId, token]);
return rows;
const token = await getTokenByUserId(userId);

if (!token){
const [rows, fields] = await connection.execute('insert into tokens values(?, ?)', [userId, token]);
return rows;
} else {
const [rows, fields] = await connection.execute('update tokens set token = ? where userId = ?', [token, userId]);
return rows;
}
}
4 changes: 4 additions & 0 deletions noti.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ app.post('/send-notification', async (req, res) => {
const { userId, title = '무제', body = 'blank' } = req.body;

const token = await getTokenByUserId(userId);
console.log(userId, title, body, token);

const message = {
notification: {
Expand All @@ -63,6 +64,9 @@ app.post('/send-notification', async (req, res) => {
console.error('Error sending message:', error);
res.status(500).send('Error sending notification');
});



});

app.listen(port, () => {
Expand Down

0 comments on commit 6b7ee67

Please sign in to comment.