Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
PricetonB committed May 25, 2024
1 parent 0d3b505 commit 51f2fb5
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 71 deletions.
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
# MowManApp
push notification app for lawn care companys
push notification app for lawn care companys.
uses google oauth to login and mongoDB to connect
check out the site here http://ec2-3-144-135-34.us-east-2.compute.amazonaws.com/userHub
WARNING: website uses http and is not encrypted. Any private information entered could be exposed.

HOW TO USE:
1. use git clone "https://github.com/PricetonB/MowManApp.git" to clone the code to your directory
2. create .env file with the following parameters

GOOGLE_CLIENT_ID=""
GOOGLE_CLIENT_SECRET=""
can be obtained from google cloud console in "apis" under "credentials" after creating account and setting u keys



SMTP_HOST="smtp.gmail.com"
SMTP_PORT="587"
these are default credentials for gmail

SMTP_USER=""
SMTP_PASS=""
you need to create a gmail account for your app.
Enable two factor authentication and create "App Password" in settings.
user will be your app email address and pass will be your App Password (Gmail account password will not work)


EXPRESS_SESSION_SECRET="ght42d8c5970f662658f705fd5jv8tk30d589b7ed0ea9740e56dgkty78290f28"
EXPRESS_LISTENING_PORT=3000
create a random string for express session secret and specify port you want to use

MONGO_URL="mongodb+srv://username.randomletters"
create a database on mongoDB Atlas website and get url for the database.
You may also need to add your ip address to mongoDB Atlas whitelist.


3. in the "auth.js" file set the baseUrl if your not using local host:3000.

4. in the "public" directory set the baseUrl at the top of every .js file if your not using localhost:3000

5. type npm install in MowManApp directory.

6. type npm start in the MowManApp directory.
2 changes: 2 additions & 0 deletions auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const GoogleStrategy = require('passport-google-oauth2').Strategy;

require('dotenv').config();



GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID;
GOOGLE_CLIENT_SECRET = process.env.GOOGLE_CLIENT_SECRET;

Expand Down
6 changes: 5 additions & 1 deletion database.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const express = require("express");
const mongoose = require("mongoose");
const app = express();
require('dotenv').config();


MONGO_URL = process.env.MONGO_URL;


// Connect to MongoDB
mongoose.connect(
"mongodb+srv://pricetonbraswell:[email protected]/Node-API?retryWrites=true&w=majority&appName=MowManDB",
MONGO_URL,
{ useNewUrlParser: true, useUnifiedTopology: true }
).then(() => {
console.log("Connected to MongoDB MowManDB!");
Expand Down
1 change: 0 additions & 1 deletion notes.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@



AWS DNS CALLBACK: http://ec2-3-144-135-34.us-east-2.compute.amazonaws.com:80/google/callback
AWS DNS URL: http://ec2-3-144-135-34.us-east-2.compute.amazonaws.com:80

pm2 start app.js --watch
Expand Down
55 changes: 0 additions & 55 deletions routes/customers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,59 +37,4 @@ router.delete('/deleteCustomer/:customerId', isLoggedIn, customerController.dele
module.exports = router;


/*

route.get /userHub/customers - returns html file that has list of customers
route.get /userHub/customers/:id - returns html file that has specific customer info and delete button
route.get /userHub/customers/:id/delete - deletes customer from database
const express = require('express');
const path = require('path');
const mongoose = require('mongoose');
const router = express.Router();
const { User, Profile, Customer } = require('../database');
// Middleware to check if the user is logged in
function isLoggedIn(req, res, next) {
if (req.user) {
return next();
} else {
res.sendStatus(401);
}
}
// GET route to serve the customers HTML file
router.get('/customersHTML', isLoggedIn, (req, res) => {
res.sendFile(path.join(__dirname, '../public', 'customers.html'));
});
// GET route to fetch customers data
router.get('/customersData', isLoggedIn, async (req, res) => {
try {
const profileId = req.user.profile_id; // Assuming `req.user.profile_id` is available
const profile = await Profile.findById(profileId).populate('customers');
if (!profile) {
console.log('Profile not found when getting customer data');
return res.status(404).json({ message: 'Profile not found' });
}
const customers = await Customer.find({ _id: { $in: profile.customers } });
res.status(200).json({ customers });
console.log("customers found and sent to client side heres customers:");
console.log(customers);
} catch (error) {
console.error('Error fetching customers:', error);
res.status(500).json({ message: 'Error fetching customers', error });
}
});
module.exports = router;
*/
2 changes: 0 additions & 2 deletions routes/userHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ router.get('/userHub', isLoggedIn, (req, res) => {
res.sendFile(path.join(__dirname, '../public', 'userHub.html'));
});



// POST route to add a new customer
router.post('/user', isLoggedIn, (req, res) => {
res.send('Post request successful');
Expand Down
5 changes: 5 additions & 0 deletions services/appointmentService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { Appointment, Profile } = require('../database');


// addAppointment function to add a new appointment to the database
const addAppointment = async (appointmentData) => {
try {
// Create a new appointment instance using the provided data
Expand All @@ -22,6 +24,7 @@ const addAppointment = async (appointmentData) => {
}
};

// setAppointmentInactive function to set an appointment to inactive in the database
const setAppointmentInactive = async (appointmentID) => {
try {
// Logic to set appointment to inactive in the database
Expand All @@ -32,6 +35,7 @@ const setAppointmentInactive = async (appointmentID) => {
}
};

// deleteAppointment function to delete an appointment from the database
const deleteAppointment = async (appointmentID) => {
try {
// Logic to delete the appointment from the database
Expand All @@ -48,6 +52,7 @@ const deleteAppointment = async (appointmentID) => {
}
};

// getUsersAppointments function to fetch all appointments associated with a user's profile
const getUsersAppointments = async (profileId) => {
try {
// Fetch appointments for the given profile ID
Expand Down
9 changes: 0 additions & 9 deletions services/customerService.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// services/customerService.js
const { Profile, Customer } = require('../database');




// Add a new customer to the database
const addCustomer = async (customerData, user) => {
const { name, email, phone } = customerData;
Expand All @@ -25,9 +22,6 @@ const addCustomer = async (customerData, user) => {
);
};




// Get all customers associated with the user's profile
const getCustomersData = async (user) => {
const profileId = user.profile_id; // Assuming `user.profile_id` is available
Expand All @@ -41,9 +35,6 @@ const getCustomersData = async (user) => {
return customers;
};




// Delete a customer by ID
const deleteCustomer = async (customerId) => {
await Customer.findByIdAndDelete(customerId);
Expand Down
4 changes: 2 additions & 2 deletions services/emailService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const nodemailer = require('nodemailer');
const { Profile, Customer, Setting, Appointment } = require('../database');


// Set up the Nodemailer transport
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
Expand All @@ -12,6 +13,7 @@ const transporter = nodemailer.createTransport({
}
});

// Function to send email notifications to customers
const sendEmailNotification = async (appointmentID) => {
try {
// Fetch the appointment document by appointmentID
Expand Down Expand Up @@ -64,8 +66,6 @@ const sendEmailNotification = async (appointmentID) => {
};




module.exports = {
sendEmailNotification
};

0 comments on commit 51f2fb5

Please sign in to comment.