2024-09-30 23:05:00 -04:00
|
|
|
const db = require('../config/db.js')
|
|
|
|
|
const { ObjectId } = require('mongodb');
|
|
|
|
|
|
|
|
|
|
class AuthProvider {
|
|
|
|
|
constructor(name) {
|
|
|
|
|
this._id = new ObjectId();
|
|
|
|
|
this.name = name;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-01 10:55:48 -04:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-30 23:05:00 -04:00
|
|
|
async create(name) {
|
|
|
|
|
await db.connect()
|
|
|
|
|
const conn = db.getConnection();
|
|
|
|
|
|
|
|
|
|
const collection = conn.collection('authprovider');
|
|
|
|
|
|
|
|
|
|
const existingauth = await collection.findOne({ name:name });
|
|
|
|
|
|
2024-10-01 00:14:55 -04:00
|
|
|
if(existingauth){
|
2024-09-30 23:05:00 -04:00
|
|
|
return existingauth._id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const newProvider = {
|
|
|
|
|
name:name
|
|
|
|
|
}
|
2024-10-01 00:14:55 -04:00
|
|
|
const result = await collection.insertOne(newProvider);
|
2024-09-30 23:05:00 -04:00
|
|
|
return result.insertedId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = new AuthProvider;
|