Metzploreur/models/post.js
clement callaert 31e8a4e726 Version 1
2023-11-01 03:00:36 +01:00

30 lines
635 B
JavaScript

const db = require('../data/database')
const mongodb = require('mongodb')
class Post {
constructor(title, content, id) {
this.title = title;
this.content = content;
if (id) {
this.id = new objectId
}
}
async insert() {
let result
if (this.id) {
result = await db.getDb().collection('posts').updateOne(
{_id: this.id},
{$set: {title: this.title, content: this.content}}
)
} else {
result = await db.getDb().collection('posts').insertOne({
title: this.title,
content: this.content,
});
}
return result
}
}
module.exports = Post;