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

tuanicom / incap / 1885

22 Apr 2026 08:39PM UTC coverage: 94.154% (+0.4%) from 93.718%
1885

Pull #653

circleci

Tuani SIMETE
address CodeRabbit review comments
Pull Request #653: Fix SonarCloud code smell issues

243 of 265 branches covered (91.7%)

Branch coverage included in aggregate %.

71 of 77 new or added lines in 27 files covered. (92.21%)

659 of 693 relevant lines covered (95.09%)

5.37 hits per line

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

69.57
/apps/backend/src/comments/comment.model.ts
1
import mongoose, { Schema, Document, model, Model } from 'mongoose';
2

3
export interface Comment extends Document<string> {
4
    text: string;
5
    authorId: string;
6
    articleId: string;
7
    createdAt: string;
8
    updatedAt?: string;
9
}
10

11
export const commentSchema = new Schema({
4✔
12
    text: {
13
        type: String
14
    },
15
    authorId: {
16
        type: String
17
    },
18
    articleId: {
19
        type: String,
20
        index: true
21
    },
22
    createdAt: {
23
        type: String
24
    },
25
    updatedAt: {
26
        type: String
27
    }
28
});
29

30
function getCommentModel(): Model<Comment> {
31
    if ((mongoose as any).models?.Comment) {
6✔
32
        return (mongoose as any).models.Comment as Model<Comment>;
4✔
33
    }
34
    if (mongoose.modelNames?.().includes?.('Comment')) {
2!
35
        return mongoose.model('Comment') as Model<Comment>;
×
36
    }
37
    try {
2✔
38
        return model<Comment>('Comment', commentSchema);
2✔
39
    } catch (err: any) {
NEW
40
        if (err?.name === 'OverwriteModelError') {
×
41
            return (mongoose as any).models.Comment as Model<Comment>;
×
42
        }
43
        throw err;
×
44
    }
45
}
46

47
function commentModelFactory(this: any, ...args: any[]) {
48
    const M = getCommentModel();
2✔
49

50
    return new (M as any)(...args);
2✔
51
}
52

53
const staticMethods = ['find', 'findById', 'findOneAndDelete', 'findOne', 'create', 'findByIdAndUpdate', 'findOneAndUpdate', 'deleteOne'];
4✔
54
for (const name of staticMethods) {
4✔
55
    (commentModelFactory as any)[name] = (...args: any[]) => {
32✔
56
        const M = getCommentModel();
4✔
57
        return (M as any)[name](...args);
4✔
58
    };
59
}
60

61
export default (commentModelFactory as unknown) as Model<Comment>;
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