Mercurial Hosting > freedit
comparison src/delete.js.luan @ 16:bff178656073
delete function
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 06 Jul 2022 22:42:42 -0600 |
parents | |
children | 0c1b820fff34 |
comparison
equal
deleted
inserted
replaced
15:0edde02b908c | 16:bff178656073 |
---|---|
1 local Luan = require "luan:Luan.luan" | |
2 local error = Luan.error | |
3 local Io = require "luan:Io.luan" | |
4 local Http = require "luan:http/Http.luan" | |
5 local Post = require "site:/lib/Post.luan" | |
6 local Db = require "site:/lib/Db.luan" | |
7 | |
8 | |
9 return function() | |
10 local post = Http.request.parameters.post or error() | |
11 Db.run_in_transaction( function() | |
12 post = Post.get_by_id(post) or error() | |
13 post.author_is_current() or error() | |
14 post.is_deleted = true | |
15 post.save() | |
16 end ) | |
17 Io.stdout = Http.response.text_writer() | |
18 %> | |
19 let postDiv = document.querySelector('[post="<%=post.id%>"]'); | |
20 postDiv.querySelector('[output]').innerHTML = 'deleted'; | |
21 <% | |
22 end |