1
0
mirror of https://github.com/byulmaru/quesdon synced 2024-11-30 15:58:01 +09:00

まだ回答する前の質問の削除に対応

This commit is contained in:
rinsuki 2017-12-11 19:58:49 +09:00
parent 731737c455
commit e881924ea6
2 changed files with 12 additions and 0 deletions

View File

@ -23,6 +23,7 @@ my-question
option(value="public") 公開
option(value="unlisted") 未収載
option(value="no") 投稿しない
button.btn.btn-danger(type="button",style="float:right;",onclick="{delete}") 削除
script.
this.submit = e => {
var formData = new FormData(e.target)
@ -33,4 +34,13 @@ my-question
alert("答えました")
location.reload()
})
}
this.delete = e => {
if(!confirm("質問を削除します。\n削除した質問は二度と元に戻せません。\n本当に質問を削除しますか?")) return
apiFetch("/api/web/questions/"+this.opts.question._id+"/delete", {
method: "POST"
}).then(r => r.json()).then(r => {
alert("削除しました")
location.reload()
})
}

View File

@ -54,6 +54,8 @@ router.post("/:id/delete", async ctx => {
const question = await Question.findById(ctx.params.id)
if (!question) return ctx.throw("not found", 404)
if (question.user.toString() != ctx.session!.user) return ctx.throw("not found", 404)
await question.remove()
ctx.body = {status: "ok"}
})
router.get("/:id", async ctx => {