Merge pull request #212 from shocknet/feature/delete-post
add delete and and page
This commit is contained in:
commit
5e042fe3ea
2 changed files with 37 additions and 8 deletions
|
|
@ -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()
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
ok: 'true'
|
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'
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
return res.status(500).json({
|
||||||
|
errorMessage:
|
||||||
|
(typeof e === 'string' ? e : e.message) || 'Unknown error.'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
/**
|
/**
|
||||||
* @template P
|
* @template P
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue