-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.js
84 lines (70 loc) · 2.84 KB
/
auth.js
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
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors')
const bodyParser = require('body-parser')
const app = express();
app.use(cors())
app.use(bodyParser.json())
const userSchema = new mongoose.Schema({
cover : Buffer,
blog : Buffer,
title : String,
fName : String,
lName : String,
description : String,
location : String,
date : String,
time : String,
email : String,
phone : String,
approved : Boolean
});
const username = encodeURIComponent("avm121104");
const password = encodeURIComponent("crispr");
mongoose.connect(`mongodb+srv://${username}:${password}@cluster0.wxhnstv.mongodb.net/?retryWrites=true&w=majority`);
const Users = mongoose.model("Users",userSchema);
app.listen("8080",(req,res) => {
console.log("listening on 8080")
})
async function insert()
{
await Users.create({
title : 'ujbeewrw er g e ertherg errg jnwdfwef',
fName : 'ewgfer e eg re dfgdfwegwwqereg',
lName : 'ewfwdffgreegergerg errger dfgdfgewwwerert',
description : "The sun hung low in the sky, casting long shadows across the tranquil meadow. Birds chirped merrily, and a gentle breeze rustled the leaves in the nearby trees. As I walked along the winding path, I couldn't help but feel a sense of peace and serenityIn the distance, I saw a small cottage with a thatched roof, smoke curling from its chimney. It looked like something out of a storybook, a place where time stood still. I decided to explore further and discovered a garden bursting with colorful flowers and a bubbling brook that danced over smooth stones. The world seemed to slow down, and for a moment, I was lost in a dream.",
location : 'azxcvbn',
date : 'asdfghnj t st rthrthrthg',
time : 'dffg g eg reg erer gergdfgaze er rgtest',
email : 'tytergr errtrtyse ergg retgwer',
phone : 'wqasdgh df er ger gfgd fyiiup',
approved : true
})
}
// insert()
//saving the data from form to the database
app.post("/demo",async (req,res) => {
let user = new Users;
user.title = req.body.title;
user.fName = req.body.fname;
user.lName = req.body.lname;
user.description = req.body.description
user.location = req.body.location
user.date = req.body.date
user.time = req.body.time
user.email = req.body.email
user.phone = req.body.phone
user.approved = false;
await user.save();
})
//getting data for event display page
app.get('/demo', async(req,res) => {
const data = await Users.find({})
res.json(data)
})
app.put('/demo', async (req, res) => {
const { id, approvedStatus } = req.body;
const filter = { _id: id }
const update = { approved: approvedStatus }
await Users.updateOne(filter, update);
})