diff --git a/src/models/nostrEvent.ts b/src/models/nostrEvent.ts index 2d223f4..954f0bf 100644 --- a/src/models/nostrEvent.ts +++ b/src/models/nostrEvent.ts @@ -1,10 +1,10 @@ export class NostrEvent { constructor( - public id: string, - public pubkey: string, - public created_at: number, - public kind: number, - public tags: [string][], - public content: string + public nostrId: string, // nostr unique identifier + public pubkey: string, // public key of the event creator + public created_at: number, // timestamp + public kind: number, // event type, e.g., review, article, comment + public tags: [string][], // array of keywords or hashtags + public content: string // text content of the event ) {} } diff --git a/src/models/review.ts b/src/models/review.ts index edf353d..85b32c6 100644 --- a/src/models/review.ts +++ b/src/models/review.ts @@ -2,11 +2,11 @@ import { ObjectId } from 'mongodb' export class Review { constructor( - public eventId: string, - public productId: string, - public rating: number, - public reviewText: string, - public testingNotes: string[], - public id?: ObjectId + public eventId: string, // foreign key referencing the nostrEvents collection + public productId: string, // unique identifier for the product + public rating: number, // numerical rating, e.g., 1-100 + public reviewText: string, // text content of the review + public tastingNotes: string[], // array of tasting notes, e.g., flavours, aromas + public id?: ObjectId // database object id ) {} } diff --git a/src/routes/reviews.router.ts b/src/routes/reviews.router.ts index 7040cf4..5ca69f2 100644 --- a/src/routes/reviews.router.ts +++ b/src/routes/reviews.router.ts @@ -3,12 +3,12 @@ import { collections } from '../services/database.service' import { Review } from '../models' // Global Config -export const reviewRouter = express.Router() +export const reviewsRouter = express.Router() -reviewRouter.use(express.json()) +reviewsRouter.use(express.json()) // GET -reviewRouter.get('/', async (_req: Request, res: Response) => { +reviewsRouter.get('/', async (_req: Request, res: Response) => { try { const reviews = await collections.reviews?.find({}).toArray() @@ -23,9 +23,10 @@ reviewRouter.get('/', async (_req: Request, res: Response) => { }) // POST -reviewRouter.post('/', async (req: Request, res: Response) => { +reviewsRouter.post('/', async (req: Request, res: Response) => { try { const review = req.body as Review + const result = await collections.reviews?.insertOne(review) if (result) {