EvalueTonSavoir/server/models/authProvider.js
Gabriel Matte 8f7c0a3ac9 Adds Oauths parsing
Co-authored-by: roesnerb <roesnerb@users.noreply.github.com>
Co-authored-by: MathieuSevignyLavallee <MathieuSevignyLavallee@users.noreply.github.com>
2024-10-01 10:55:48 -04:00

44 lines
No EOL
967 B
JavaScript

const db = require('../config/db.js')
const { ObjectId } = require('mongodb');
class AuthProvider {
constructor(name) {
this._id = new ObjectId();
this.name = name;
}
async getId(name){
await db.connect()
const conn = db.getConnection();
const collection = conn.collection('authprovider');
const existingauth = await collection.findOne({ name:name });
if(existingauth){
return existingauth._id
}
return null
}
async create(name) {
await db.connect()
const conn = db.getConnection();
const collection = conn.collection('authprovider');
const existingauth = await collection.findOne({ name:name });
if(existingauth){
return existingauth._id;
}
const newProvider = {
name:name
}
const result = await collection.insertOne(newProvider);
return result.insertedId;
}
}
module.exports = new AuthProvider;