-
Notifications
You must be signed in to change notification settings - Fork 0
Worked on email templete #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 8 commits
e4769bf
55b2ca8
3009f9f
08f0559
89081f2
27d5070
5e13288
b455df2
71be255
de15739
4de8d8d
221b653
9db0fe7
1e7b685
9bb471e
ffec875
57aaa7a
9c4bf8d
f67023e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,7 @@ const nodemailer = require("nodemailer"); | |
const bcryptjs = require("bcryptjs"); | ||
const jwt = require("jsonwebtoken"); | ||
|
||
const transporter = nodemailer.createTransport({ | ||
service: "gmail", | ||
auth: { | ||
user: "[email protected]", | ||
pass: "*Saheb13*", | ||
}, | ||
}); | ||
const {transporter} = require('../utils/transporter') | ||
|
||
const signup = async (req, res) => { | ||
const { username, password, email, phoneNo } = req.body; | ||
|
@@ -33,7 +27,7 @@ const signup = async (req, res) => { | |
from: "[email protected]", | ||
to: email, | ||
subject: "Account activation link", | ||
html: `<h2>PLease click on given link to activate your account</h2> | ||
html: `<h2>Account activation link</h2> | ||
<p>http://localhost:2000/api/activate/${token}</p> | ||
`, | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,46 @@ | ||
const mongoose = require("mongoose"); | ||
const { Survey } = require("../models/survey"); | ||
const {transporter} = require('../utils/transporter') | ||
|
||
const createSurvey = async (req, res) => { | ||
const survey = await Survey.create(req.body); | ||
const { title, category,subject, body, recipients } = req.body; | ||
const survey = await Survey.create({ | ||
title, | ||
category, | ||
subject, | ||
body, | ||
recipients, | ||
dateSent: Date.now(), | ||
}); | ||
|
||
const data = { | ||
from: "[email protected]", | ||
to: recipients, | ||
subject: "Account activation link", | ||
html: ` <html> | ||
<body> | ||
<div style="text-align: center;"> | ||
<h3>I'd like your input!</h3> | ||
<p>Please answer the following question:</p> | ||
<p>${survey.body}</p> | ||
<div> | ||
<a href="/">Yes</a> | ||
</div> | ||
<div> | ||
<a href="/">No</a> | ||
</div> | ||
</div> | ||
</body> | ||
</html> | ||
`, | ||
}; | ||
|
||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should try-catch the whole function, and return the error. Anything could fail not just the mail. |
||
await transporter.sendMail(data); | ||
console.log("Email sent Successfully! survey"); | ||
} catch (err) { | ||
console.log("error occured while sending email!", err); | ||
} | ||
res.send(survey); | ||
}; | ||
module.exports = { createSurvey }; | ||
module.exports = { createSurvey }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = (req, res, next) => { | ||
if (!req.user.credits <1) { | ||
return res.status(403).send({ error: " You do Not have enough Credits!" }); | ||
} | ||
next(); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = (req, res, next) => { | ||
if (!req.user) { | ||
return res.status(401).send({ error: 'You must log in!' }); | ||
} | ||
|
||
next(); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const mongoose = require("mongoose"); | ||
const { Schema } = mongoose; | ||
const recipientSchema = new Schema({ | ||
email: String, | ||
responded: { type: Boolean, default: false }, | ||
}); | ||
|
||
module.exports = recipientSchema; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
|
||
const mongoose=require('mongoose') | ||
|
||
const surveySchema=mongoose.Schema({ | ||
title:{ | ||
type:String | ||
}, | ||
type:{ | ||
type:String | ||
}, | ||
|
||
questionsSet:[ | ||
{ | ||
ques:{ | ||
type: String | ||
}, | ||
ans:{ | ||
type: [Boolean] | ||
} | ||
} | ||
] | ||
|
||
}) | ||
//created the survey api now | ||
const Survey = mongoose.model("Survey",surveySchema) | ||
module.exports={Survey} | ||
const mongoose = require("mongoose"); | ||
const recipientSchema= require('./recipient') | ||
const surveySchema = mongoose.Schema({ | ||
title: { | ||
type: String, | ||
}, | ||
category: { | ||
type: String, | ||
}, | ||
body: { | ||
type: String, | ||
}, | ||
subject: { | ||
type: String, | ||
}, | ||
recipients:[ | ||
String | ||
], | ||
yes: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
No: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
_user:{ | ||
type:mongoose.Schema.Types.ObjectId, | ||
ref:'User' | ||
}, | ||
dateSent: Date, | ||
lastResponded: Date | ||
}); | ||
const Survey = mongoose.models.Survey||mongoose.model("Survey", surveySchema); | ||
module.exports = { Survey }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
const express = require("express"); | ||
const { createSurvey } = require("../controllers/survey"); | ||
const router = express.Router(); | ||
const { createSurvey } = require("../controllers/survey"); | ||
|
||
router.post("/createsurvey", createSurvey); | ||
|
||
module.exports = router; | ||
module.exports = router; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const nodemailer = require('nodemailer') | ||
|
||
const transporter = nodemailer.createTransport({ | ||
service: "gmail", | ||
auth: { | ||
user: "[email protected]", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to use any credentials used in config files or default.json. Can be used at multiple places and will have to update at one place only, if needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay |
||
pass: "*Saheb13*", | ||
}, | ||
}); | ||
|
||
module.exports ={ | ||
transporter | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be /survey. Filename case should match always.