mirror of
https://github.com/spchcap/speech.capital.git
synced 2026-01-13 16:18:06 +00:00
Feat: Select post_type for post detail view
This commit is contained in:
@@ -7,7 +7,7 @@ const auth=async(req,db)=>{const c=req.headers.get('Cookie')||'',u=cookie(c),h=h
|
||||
export async function onRequestGet({request,env,params}){
|
||||
try{
|
||||
const id=params.id,user=await auth(request,env.D1_SPCHCAP);
|
||||
const post=await env.D1_SPCHCAP.prepare(`SELECT p.id,p.user_id,p.title,p.link,p.content,p.score,p.comment_count,p.created_at,u.username${user?',v.direction as voted':''} FROM posts p JOIN users u ON p.user_id=u.id ${user?'LEFT JOIN votes v ON v.post_id=p.id AND v.user_id=?':''} WHERE p.id=?`).bind(...(user?[user.id,id]:[id])).first();
|
||||
const post=await env.D1_SPCHCAP.prepare(`SELECT p.id,p.user_id,p.title,p.link,p.content,p.score,p.comment_count,p.created_at,p.post_type,u.username${user?',v.direction as voted':''} FROM posts p JOIN users u ON p.user_id=u.id ${user?'LEFT JOIN votes v ON v.post_id=p.id AND v.user_id=?':''} WHERE p.id=?`).bind(...(user?[user.id,id]:[id])).first();
|
||||
if(!post)return json({error:'Not found'},{status:404},request);
|
||||
|
||||
const{results}=await env.D1_SPCHCAP.prepare(`SELECT c.id,c.user_id,c.content,c.score,c.parent_id,c.created_at,u.username${user?',v.direction as voted':''} FROM comments c JOIN users u ON c.user_id=u.id ${user?'LEFT JOIN votes v ON v.comment_id=c.id AND v.user_id=?':''} WHERE c.post_id=? ORDER BY c.created_at ASC`).bind(...(user?[user.id,id]:[id])).all();
|
||||
|
||||
Reference in New Issue
Block a user