Last active
September 3, 2019 09:46
-
-
Save bankchart/d3b2bf91072349c97a8174e9d5fa76f3 to your computer and use it in GitHub Desktop.
cloud functions code
This file contains hidden or 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
| const admin = require('firebase-admin'); | |
| const appConstant = require('../../const'); | |
| exports = module.exports = async (req, res) => { | |
| let response = {}; | |
| try { | |
| const db = admin.firestore(); | |
| const postId = uuid4(); | |
| const currentDatetime = new Date(); | |
| await db.collection('post').doc(postId) | |
| .set({ | |
| id: postId, | |
| owner: { | |
| displayName: 'bank' | |
| }, | |
| subject: req.body.subject, | |
| body: req.body.content, | |
| postDatetime: currentDatetime, | |
| createdBy: 'bank', | |
| createdDatetime: currentDatetime, | |
| updatedBy: 'bank', | |
| updatedDatetime: currentDatetime | |
| }); | |
| res.json(appConstant.buildServiceSuccess(response)); | |
| } catch (err) { | |
| console.error(err); | |
| res.json(appConstant.buildServiceError(err, response)); | |
| } | |
| } |
This file contains hidden or 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
| const admin = require('firebase-admin'); | |
| const uuid4 = require('uuid/v4'); | |
| const appConstant = require('../../const'); | |
| exports = module.exports = async (req, res) => { | |
| let response = {}; | |
| try { | |
| const db = admin.firestore(); | |
| const postId = req.query.postId; | |
| if (!postId || !postId.trim()) { | |
| throw appConstant.B_ERROR.RequiredPostID(); | |
| } | |
| const postDoc = await db.collection('post').doc(postId).get(); | |
| const postDocResult = postDoc.data(); | |
| if (!postDocResult) { | |
| throw appConstant.B_ERROR.NotFoundPost(); | |
| } | |
| response.data = {}; | |
| Object.assign(response.data, postDocResult); | |
| res.json(appConstant.buildServiceSuccess(response)); | |
| } catch (err) { | |
| console.error(err); | |
| res.json(appConstant.buildServiceError(err, response)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment