add delete and and page

This commit is contained in:
hatim boufnichel 2020-10-10 17:46:13 +02:00
parent 684c186224
commit 429bb85632
2 changed files with 37 additions and 8 deletions

View file

@ -1325,6 +1325,7 @@ const createPost = async (tags, title, content) => {
date: Date.now(), date: Date.now(),
status: 'publish', status: 'publish',
tags: tags.join('-'), tags: tags.join('-'),
page: pageIdx,
title title
}, },
ack => { ack => {
@ -1435,11 +1436,25 @@ const createPost = async (tags, title, content) => {
/** /**
* @param {string} postId * @param {string} postId
* @param {string} page
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
const deletePost = async postId => { const deletePost = async (postId, page) => {
await new Promise(res => { await new Promise((res, rej) => {
res(postId) require('../Mediator')
.getUser()
.get(Key.WALL)
.get(Key.PAGES)
.get(page)
.get(Key.POSTS)
.get(postId)
.put(null, ack => {
if (ack.err && typeof ack.err !== 'number') {
rej(new Error(ack.err))
} else {
res()
}
})
}) })
} }

View file

@ -2289,11 +2289,25 @@ module.exports = async (
} }
}) })
app.delete(`/api/gun/wall/:postID`, (_, res) => app.delete(`/api/gun/wall/:postInfo`, async (req, res) => {
res.status(200).json({ try {
const { postInfo } = req.params
const parts = postInfo.split('&')
const [page, postId] = parts
if (!page || !postId) {
throw new Error(`please provide a "postId" and a "page"`)
}
await GunActions.deletePost(postId, page)
return res.status(200).json({
ok: 'true' ok: 'true'
}) })
) } catch (e) {
return res.status(500).json({
errorMessage:
(typeof e === 'string' ? e : e.message) || 'Unknown error.'
})
}
})
///////////////////////////////// /////////////////////////////////
/** /**
* @template P * @template P