added ModerationController

This commit is contained in:
SrGooglo 2023-02-24 14:43:44 +00:00
parent 9fb8282974
commit b39d250bcb
2 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,47 @@
import { Post, } from "@models"
import toogleLike from "../../PostsController/services/toogleLike"
export default {
method: "POST",
route: "/:post_id/mok_likes",
middlewares: ["withAuthentication", "onlyAdmin"],
fn: async (req, res) => {
const {
count,
interval = 100,
} = req.body
if (count < 1) {
return res.status(400).json({
error: "Invalid count, must be greater than 0",
})
}
let postData = await Post.findById(req.params.post_id)
if (!postData) {
return res.status(404).json({
error: "Post not found",
})
}
for (let i = 0; i < count; i++) {
const mokUserId = `mok_${i}_${count}`
toogleLike({
post_id: postData._id.toString(),
user_id: mokUserId,
to: true
})
await new Promise((resolve) => setTimeout(resolve, interval ?? 100))
continue
}
return res.status(200).json({
message: "Success",
data: postData
})
}
}

View File

@ -0,0 +1,10 @@
import { Controller } from "linebridge/dist/server"
import generateEndpointsFromDir from "linebridge/dist/server/lib/generateEndpointsFromDir"
export default class ModerationController extends Controller {
static refName = "ModerationController"
static useRoute = "/mod"
static reachable = false
httpEndpoints = generateEndpointsFromDir(__dirname + "/endpoints")
}