-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[GET] /notice/service?lastid=&size= 서비스 알림 조회
- Loading branch information
Showing
4 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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'); | ||
const { noticeDB } = require('../../../../db'); | ||
|
||
/** | ||
* @서비스_알림_조회 | ||
* @route GET /notice/service?lastid=&size= | ||
* @error | ||
*/ | ||
|
||
module.exports = async (req, res) => { | ||
const user = req.user; | ||
const userId = user.userId; | ||
const { lastid, size } = req.query; | ||
|
||
let client; | ||
|
||
try { | ||
client = await db.connect(req); | ||
|
||
const services = await noticeDB.getServicesByUserId(client, userId, lastid, size); | ||
|
||
const notices = services.map((s) => { | ||
const notice = {}; | ||
notice['noticeId'] = s.notificationId; | ||
notice['noticeTitle'] = s.title; | ||
notice['noticeImg'] = s.thumbnail; | ||
notice['noticeContent'] = s.content; | ||
notice['createdAt'] = s.createdAt.toISOString().split('T')[0].replace(/-/g, '/'); | ||
return notice; | ||
}); | ||
|
||
res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.SERVICE_GET_SUCCESS, { notices })); | ||
} 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(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters