first commit

This commit is contained in:
2024-05-16 16:05:41 +02:00
commit adf8283ae0
197 changed files with 26666 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
const { ObjectId } = require('mongodb');
const connectDb = require("./db");
const SaleDb = class
{
constructor()
{
this.getCollection();
}
async getCollection()
{
const db = await connectDb();
if (!db) {
throw new Error('Database not connected');
}
this.collection = db.collection("Sales");
}
// CRUD
async get(id)
{
let result = await this.collection.findOne({_id: new ObjectId(id)});
return result;
}
async post(newDocument)
{
let result = await this.collection.insertOne(newDocument);
return result;
}
async put(id, data)
{
let result = await this.collection.updateOne({_id: new ObjectId(id)}, {$set: data});
return result;
}
async remove(id)
{
let result = await this.collection.deleteOne({_id: new ObjectId(id)});
return result;
}
// Fucntions
async getAll()
{
let result = await this.collection.find({}).toArray();
return result;
}
async getByUrl(url)
{
let result = await this.collection.findOne({url: url});
return result;
}
async getByIDPlatform(idSalePlatform, platformName)
{
let result = await this.collection.findOne({idPlatform: String(idSalePlatform), platform: String(platformName)});
return result;
}
}
module.exports = { SaleDb };