-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
41 lines (35 loc) · 1.16 KB
/
router.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
import express from 'express';
import bcrypt from 'bcrypt'
import { client } from './index.js';
var router = express.Router()
router.get("/",async function(req,res){
let result =await client.db("movie").collection("mov").find({})
.toArray()
res.send(result)
})
router.get("/:id",async function(req,res){
var {id} = req.params
let result =await client.db("movie").collection("mov").find({id:id}).toArray()
res.send(result)
})
router.put("/:id",async function(req,res){
var {id}=req.params
var data = req.body
let result =await client.db("movie").collection("mov").updateOne({id:id},{$set:data})
res.send(result)
})
async function passwordCreate (pass){
const salt = await bcrypt.genSalt(4)
const hash = await bcrypt.hash(pass,salt)
return hash;
}
router.post("/",async function(req,res){
var {username,password} = req.body
var pass = await passwordCreate(password)
let result =await client.db("movie").collection("users").insertOne({username,"password":pass})
res.send(result)
})
export const home = router
export const signup = router
export const bookYourSeats = router
export const getonemovie = router