mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Co-authored-by: roesnerb <roesnerb@users.noreply.github.com> Co-authored-by: MathieuSevignyLavallee <MathieuSevignyLavallee@users.noreply.github.com>
44 lines
No EOL
967 B
JavaScript
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; |