Skip to content

Commit

Permalink
database connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrique Sagara authored and Henrique Sagara committed Feb 19, 2024
1 parent 30be54e commit d7ce3c1
Show file tree
Hide file tree
Showing 9 changed files with 1,062 additions and 42 deletions.
17 changes: 17 additions & 0 deletions modules/data-service-auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { client, dbName, collectionName, connectToDatabase } from "./database.js";
import bcrypt from "bcrypt";
import dotenv from "dotenv";
dotenv.config();

const uri = process.env.MONGODB_URI;

const userSchema = new mongoose.Schema({
name: { type: String, required: true},
email: {type: String, required: true, unique: true},
password: {type: String, required: true},
manager: {type: String},
isManager: { type: Boolean, default: false},
});

let User;

4 changes: 2 additions & 2 deletions modules/data-service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { client, dbName, collectionName, connectToDatabase } from "../data-services/database.js";
import { client, dbName, collectionName, connectToDatabase } from "./database.js";

// Call the connectToDatabase function to establish the connection
connectToDatabase();
// connectToDatabase();

async function listDatabases(client) {
const databasesList = await client.db().admin().listDatabases();
Expand Down
3 changes: 2 additions & 1 deletion modules/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const uri = process.env.MONGODB_URI;
const client = new MongoClient(uri);
const dbName = "timesheet_app";
const collectionName = "hoursRecords";
const userCollection = "users"

// Function to connect to the MongoDB server
async function connectToDatabase() {
Expand All @@ -20,4 +21,4 @@ async function connectToDatabase() {
}


export { client, dbName, collectionName, connectToDatabase };
export { client, dbName, collectionName, userCollection,connectToDatabase };
13 changes: 0 additions & 13 deletions modules/user.js
Original file line number Diff line number Diff line change
@@ -1,13 +0,0 @@
import mongoose from "mongoose";

const userSchema = new mongoose.Schema({
name: { type: String, required: true},
email: {type: String, required: true, unique: true},
password: {type: String, required: true},
manager: {type: String},
isManager: { type: Boolean, default: false},
});

const User = mongoose.model('User', userSchema);

module.exports = User;
Loading

0 comments on commit d7ce3c1

Please sign in to comment.