Back to Bricks

Comments System

Social

Nested commenting system for any resource (Product, Post, etc). Supports parent/child relationships.

socialdiscussionreplythreadAuth Required
Backend:
prisma/schema.prismajavascript
1model Comment {
2 id String @id @default(uuid())
3 content String
4 userId String
5 targetId String
6 targetModel String
7 parentId String?
8 createdAt DateTime @default(now())
9}

Paste Guide

Copy files to:

prisma/schema.prisma (append models)repositories/comment.repo.jscontrollers/commentController.jsroutes/commentRoutes.js

Add to server.js:

app.use('/api/comment', require('./routes/commentRoutes'));

Stack

PrismaExpress

Test Examples

curl http://localhost:5000/api/comments/Post/POST_ID
curl -X POST http://localhost:5000/api/comments \
  -H "Authorization: Bearer TOKEN" \
  -d '{"content": "Nice!", "targetId": "ID", "targetModel": "Post"}'