Skip to content

Commit

Permalink
Add moderation API
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtyson123 committed Aug 2, 2024
1 parent 16cedc7 commit 15786e1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion website/src/pages/api/posts/moderate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default async function handler(

// Check if the user is permitted to access the API
const session = await getServerSession(request, response, authOptions)
const permission = await checkApiPermissions(request, response, session, client, makeQuery, "api:plants:moderate:access")
const permission = await checkApiPermissions(request, response, session, client, makeQuery, "api:admin:moderate:access")
if(!permission) return response.status(401).json({error: "Not Authorized"})


Expand All @@ -40,17 +40,40 @@ export default async function handler(

// Check if the data is being downloaded from the Postgres database
const tables = getTables()
let query = ""

switch (operation) {
case "list":


// List all the posts that need to be moderated
query = `SELECT * FROM posts WHERE ${tables.post_approved} = false;`;

break;

case "approve":

// Approve the post
query = `UPDATE posts SET ${tables.post_approved} = true WHERE ${tables.id} = ${id};`;

break;

case "deny":

// Deny the post
query = `DELETE FROM posts WHERE ${tables.id} = ${id};`;

break;

default:
return response.status(400).json({error: "Invalid operation"});
}

// Run the query
const data = await makeQuery(query, client)

return response.status(200).json({message: "Success", data: data});

} catch (error) {
return response.status(500).json({message: "ERROR IN SERVER", error: error });
} finally {
Expand Down

0 comments on commit 15786e1

Please sign in to comment.