• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Seniru / defendxstore / 14820180658

04 May 2025 10:12AM UTC coverage: 39.325% (-0.09%) from 39.419%
14820180658

Pull #87

github

web-flow
Merge 80f001877 into 4e7f6c756
Pull Request #87: [WIP] Forum and support updates

100 of 481 branches covered (20.79%)

Branch coverage included in aggregate %.

5 of 22 new or added lines in 3 files covered. (22.73%)

5 existing lines in 2 files now uncovered.

611 of 1327 relevant lines covered (46.04%)

8.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.18
/backend/src/controllers/forums.js
1
const { StatusCodes } = require("http-status-codes")
3✔
2
const createResponse = require("../utils/createResponse")
3✔
3
const ForumThread = require("../models/ForumThread")
3✔
4
const ForumThreadReply = require("../models/ForumThreadReply")
3✔
5
const User = require("../models/User")
3✔
6

7
const createThread = async (req, res, next) => {
3✔
8
    try {
×
9
        const { title, content, category } = req.body
×
NEW
10
        const user = await User.findOne({ username: req.user.username }).exec()
×
11
        const thread = new ForumThread({
×
12
            title,
13
            content,
14
            createdDate: Date.now(),
15
            edittedDate: null,
16
            category,
17
            createdUser: user._id,
18
        })
19
        await thread.save()
×
20
        return createResponse(res, StatusCodes.CREATED, thread)
×
21
    } catch (error) {
22
        next(error)
×
23
    }
24
}
25

26
const getAllThreads = async (req, res, next) => {
3✔
27
    try {
×
NEW
28
        const { q, category } = req.query
×
29

NEW
30
        const query = { title: { $regex: q || "", $options: "i" } }
×
NEW
31
        if (category) query.category = category
×
32

NEW
33
        const forums = await ForumThread.find(query)
×
34
            .populate({ path: "createdUser", select: "username" })
35
            .exec()
UNCOV
36
        return createResponse(res, StatusCodes.OK, forums)
×
37
    } catch (error) {
38
        next(error)
×
39
    }
40
}
41

42
const getThread = async (req, res, next) => {
3✔
43
    try {
×
44
        const { threadId } = req.params
×
NEW
45
        const thread = await ForumThread.findOne({ _id: threadId })
×
46
            .populate({ path: "createdUser", select: "username" })
47
            .populate({
48
                path: "replies",
49
                populate: { path: "createdUser", select: "username" },
50
            })
51
            .exec()
52
        if (!thread) return createResponse(res, StatusCodes.NOT_FOUND, "Thread not found")
×
53
        return createResponse(res, StatusCodes.OK, thread)
×
54
    } catch (error) {
55
        next(error)
×
56
    }
57
}
58

59
const editThread = async (req, res, next) => {
3✔
60
    try {
×
61
        const { threadId } = req.params
×
62
        const { title, content, category } = req.body
×
63
        const thread = await ForumThread.findOneAndUpdate(
×
64
            { _id: threadId },
65
            { title, content, category, editedDate: Date.now() },
66
        ).exec()
67
        if (!thread) return createResponse(res, StatusCodes.NOT_FOUND, "Thread not found")
×
68
        return createResponse(res, StatusCodes.OK, "Thread updated")
×
69
    } catch (error) {
70
        next(error)
×
71
    }
72
}
73

74
const deleteThread = async (req, res, next) => {
3✔
75
    try {
×
76
        const { threadId } = req.params
×
77
        const forumThread = await ForumThread.findOneAndDelete({ _id: threadId }).exec()
×
78
        if (!forumThread) return createResponse(res, StatusCodes.NOT_FOUND, "Thread not found")
×
79
        return createResponse(res, StatusCodes.OK, "Thread deleted")
×
80
    } catch (error) {
81
        next(error)
×
82
    }
83
}
84

85
const createReply = async (req, res, next) => {
3✔
NEW
86
    try {
×
NEW
87
        const { threadId } = req.params
×
NEW
88
        const { content } = req.body
×
NEW
89
        if (!content) return createResponse(res, StatusCodes.BAD_REQUEST, "Missing content")
×
90

NEW
91
        const user = await User.findOne({ username: req.user.username }).exec()
×
NEW
92
        const reply = await ForumThreadReply.create({
×
93
            threadId,
94
            content,
95
            createdDate: Date.now(),
96
            createdUser: user._id,
97
        })
98

NEW
99
        await ForumThread.findByIdAndUpdate(threadId, {
×
100
            $push: { replies: reply._id },
101
        }).exec()
102

NEW
103
        return createResponse(res, StatusCodes.CREATED, reply)
×
104
    } catch (error) {
NEW
105
        next(error)
×
106
    }
107
}
108

109
module.exports = {
3✔
110
    createThread,
111
    getAllThreads,
112
    getThread,
113
    editThread,
114
    deleteThread,
115
    createReply,
116
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc