Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ const productsData = require("./products");
const commentsData = require("./comments");
const categoryData = require("./category");
const ordersData = require("./orders");
// test
const mongoCollections = require('../config/mongoCollections');
const users = mongoCollections.users;

// test
const dbConnection = require('../config/mongoConnection');
// const data = require('./data/');
// const bandsData = data.bands;
Expand All @@ -16,28 +12,18 @@ const dbConnection = require('../config/mongoConnection');
const main = async () => {
const db = await dbConnection();
await db.dropDatabase();
const usersCollection = await users();

let basicInfo = {
lastName: "ma",
firstName: "dongming",
birthdate: "101010101"
}
let email = "123@123.com"
let email2 = "321@123.com"
// let address = {
// state: "NJ",
// city: "Hoboken",
// street: "9999999",
// zipCode: "114514"
// }
let test = await usersData.addUser(basicInfo,email,"weyywy")
// console.log(test)
// let test2 = await usersData.addUser(basicInfo,email2,"weyywy")
// console.log(test2)

// let user = await usersCollection.findOne({email:email})
// console.log(user)
let address = {
state: "NJ",
city: "Hoboken",
street: "9999999",
zipCode: "114514"
}
let test = await usersData.addUser(basicInfo,"123@123.com","weyywy")
// basicInfo.lastName = "JOJO"
// let test1 = await usersData.patchUser(test._id,{basicInfo})
// console.log(test.shoppingCart)
Expand Down
41 changes: 0 additions & 41 deletions data/test.js

This file was deleted.

11 changes: 2 additions & 9 deletions data/users.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const mongoCollections = require('../config/mongoCollections');
const users = mongoCollections.users;
const ObjectId = require('mongodb').ObjectID;
const bcrypt = require("bcrypt");
const saltRounds = 16;

// untilities
function checkStringInput(value, inputName, functionName) {
Expand Down Expand Up @@ -46,11 +44,7 @@ module.exports = {
checkStringInput(inputs[i], inputsname[i], 'addUser')
}
const usersCollection = await users();
const checkExist = await usersCollection.findOne({ email: email })
if (checkExist) {
throw `User already exists with that email ${email}`
}
let hashedPassword = await bcrypt.hash(password, saltRounds);

let newUser = {
basicInfo: {
lastName: basicInfo.lastName,
Expand All @@ -70,7 +64,7 @@ module.exports = {
street: "",
zipCode: ""
},
password: hashedPassword,
password: password,
shoppingCart: [],
wishList: [],
reviews: [],
Expand All @@ -81,7 +75,6 @@ module.exports = {
if (insertInfo.insertedCount === 0) throw 'Could not add user.';
const newId = insertInfo.insertedId;
const user = await this.getUserById(newId);
console.log("User has been added:",user)
return user;
},
async removeUser(id) {
Expand Down
Loading