-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
66 lines (54 loc) · 1.59 KB
/
helper.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
import { client } from "./index.js";
import bcrypt from "bcrypt";
import { ObjectId } from "mongodb";
export async function getAllMovies(req) {
return await client
.db("b29wd")
.collection("movies")
.find(req.query)
.toArray();
}
export async function getMovieById(id) {
return await client
.db("b29wd")
.collection("movies")
.findOne({ _id: ObjectId(id) });
}
export async function deleteMovieById(id) {
return await client
.db("b29wd")
.collection("movies")
.deleteOne({ _id: ObjectId(id) });
}
export async function addMovies(newMovies) {
return await client
.db("b29wd")
.collection("movies")
.insertOne(newMovies);
}
export async function updateMovieById(id,updateMovie) {
// console.log(`id is ${id} movie is ${updateMovie}`)
return await client
.db("b29wd")
.collection("movies")
.updateOne({ _id: ObjectId(id) },{$set:updateMovie});
}
export async function genPassword(password) {
const salt = await bcrypt.genSalt(10)//genSalt(No.of.Rounds)
console.log(salt)
const hashedPassword = await bcrypt.hash(password,salt)
console.log(hashedPassword)
return hashedPassword
}
export async function createUser(username,hashedPassword) {
return await client
.db("b29wd")
.collection("users")
.insertOne({username:username,password:hashedPassword});
}
export async function getUserByName(username) {
return await client
.db("b29wd")
.collection("users")
.findOne({ username:username});
}