Repository navigation
Expand file tree
/
Copy pathpresentation-controller.js
More file actions
105 lines (97 loc) · 4.13 KB
/
Copy pathpresentation-controller.js
File metadata and controls
105 lines (97 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// to keep all the callback functions in this folder and files
import dotenv from 'dotenv';
import nodemailer from 'nodemailer';
import Email from '../model/emailSchema.js';
import Presentation from '../model/presentationSchema.js';
dotenv.config();
/* addPresentation controller function */
export const addPresentation = async (request, response) => {
const presentation = request.body;
const newPresentation = new Presentation(presentation);
try {
await newPresentation.save();
let data = [];
const emails = await Email.find({});
for (let i = 0; i < emails.length; i++) {
data.push(emails[i].email);
}
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.USER,
pass: process.env.PASS
}
});
send();
async function send() {
const result = await transporter.sendMail({
from: data[0],
to: data,
subject: 'New Company Presentation Added!!! Check The NITJ\'s Jobify Portal',
html: "<html><body><div><h1 style='color:blue;'>Greetings From TPO NIT Jalandhar!!!</h1><p style='color:red;font-weight:bold;font-size:1.2em;'>New Companies Visiting The Institute For Hiring Are Having Ppt About Company And Have Been Added To The NITJ\'s Jobify Portal. All The Students Are Requested To Visit The Portal To Checkout The Details!!!</p></div></body></html>"
});
}
response.status(201).json(newPresentation);
} catch (error) {
response.status(409).json({ message: error.message });
}
}
/* getPresentations controller function */
export const getPresentations = async (request, response) => {
try {
const presentations = await Presentation.find({});
response.status(200).json(presentations);
} catch (error) {
response.status(404).json({ message: error.message });
}
}
/* getPresentation controller function */
export const getPresentation = async (request, response) => {
try {
const presentation = await Presentation.find({ _id: request.params.id });
response.status(200).json(presentation);
} catch (error) {
response.status(404).json({ message: error.message });
}
}
/* editPresentation controller function */
export const editPresentation = async (request, response) => {
let presentation = request.body;
let editPresentation = new Presentation(presentation);
try {
await Presentation.updateOne({ _id: request.params.id }, editPresentation);
let data = [];
const emails = await Email.find({});
for (let i = 0; i < emails.length; i++) {
data.push(emails[i].email);
}
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.USER,
pass: process.env.PASS
}
});
send();
async function send() {
const result = await transporter.sendMail({
from: data[0],
to: data,
subject: 'Company Presentation Details Edited!!! Check The NITJ\'s Jobify Portal',
html: "<html><body><div><h1 style='color:blue;'>Greetings From TPO NIT Jalandhar!!!</h1><p style='color:red;font-weight:bold;font-size:1.2em;'>New Companies Visiting The Institute For Hiring Are Having Ppt About Company And The Details Have Been Edited To The NITJ\'s Jobify Portal. All The Students Are Requested To Visit The Portal To Checkout The Details!!!</p></div></body></html>"
});
}
response.status(201).json(editPresentation);
} catch (error) {
response.status(409).json({ message: error.message });
}
}
/* deletePresentation controller function */
export const deletePresentation = async (request, response) => {
try {
await Presentation.deleteOne({ _id: request.params.id });
response.status(200).json({ message: 'Presentation deleted successfully' });
} catch (error) {
response.status(409).json({ message: error.message });
}
}