Monday, 17 April 2017

SyntaxError: missing )

I'm new to node.js and I'm trying to create an application in it. When I tried to upload the application to test it I got this error: SyntaxError: missing ) after argument list. The code is:

var express = require("express");
var _ = require("underscore");
var https = require("https");
var url = require("url");
var querystring = require("querystring");
var MongoClient = require("mongodb").MongoClient;
var assert = require("assert");
var util= require("util");
var BodyParser = require("body-parser");
var ObjectId = require("mongodb").ObjectID;
var mongoose = require("mongoose");
var Credentials = require("credentials");
var url = "mongodb://localhost:27017/term project";

app.get("/",function(req,res){
    res.sendFile("main.html",{"root":__dirname + "/public"});
})
app.get("/products", function(req,res) { 
    res.render("/products");
    });
});

var Schema = mongoose.Schema, 
    ObjectID = Schema.ObjectID;

var Product = new Schema({
    name: String,
    Quantity: number,
    id: number,
    price: string,
    description: string
});
var Product = mongoose.model("Product", Product);


db.Product.save(Document, {name: "Rossignol", quantity: 20, id: 1, price: "99.99", description: "Rossignol skis" } function(err, records)  {
    console.log("Record added!");
}:
db.Product.save(Document, {name: "Solomon", quantity: 30 id: 2, price: "499.99", description: "Solomon skis"} function(err, records)  {
    console.log("Record added!");
}:
db.Product.save(Document, {name: "K1", quantity: 15, id: 3, price: "750.99", description: "K1 skis"} function(err, records)  {
    console.log("Record added!");
}:
db.Product.save(Document, {name: "Rossignol_boots", quantity: 50, id: 4, price: "299.99", description: "Rossignol boots"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "Solomon_Boots", quantity: 35, id: 5, price: "339.99", description: "Solomon boots"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "Lange_Boots", quantity: 5, id: 6, price: "400.00", description: "Lange boots"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "Oakley", quantity: 100, id: 7, price: "159.99", description: "Oakley goggles"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "Scott", quantity: 45, id: 8, price: "129.99", description: "Scott goggles"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "Smith", quantity: 200, id: 9, price: "139.99", description: "Smith goggles"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "Dragon", quantity: 50, id: 10, price: "109.99", description: "Dragon goggles"} function(err, records)  {
    console.log("Record added!");
};
db.Product.savet(Document, {name: "Anon", quantity: 40, id: 11, price: "99.99", description: "Anon goggles"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "Giro", quantity: 10, id: 12, price: "78.99", description: "Giro goggles"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "Burton", quantity: 100, id: 13, price: "399.99", description: "Burton snowboard"} function(err, records)  {
    console.log("Record added!");
};
db.Product.savet(Document, {name: "Burton_boots", quantity: 300, id: 14, price: "199.99", description: "Burton brand snowboard boots"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "ski_gloves", quantity: 500, id: 15, price: "29.99", description: "ski gloves"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "ski_hats", quantity: 100, id: 16, price: "19.99", description: "heavy ski hats"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "snowpants", quantity: 200, id: 17, price: "69.99", description: "heavy winter ski pants"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "hothands", quantity: 2000, id: 18, price: "19.99", description: "Chemical bags to help keep your hands warm and frostbite off"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "neckwarmers", quantity: 200, id: 19, price: "39.99", description: "neckwarmers to keep your neck warm"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "ski_jackets", quantity: 90, id: 20, price: "159.99", description: "winter jackets"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "ski_poles", quantity: 2000, id: 21, price: "50.99", description: "ski poles"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "wax", quantity: 500, id: 22, price: "9.99", description: "Wax for spring skiing to make your skis/boards smooth"} function(err, records)  {
    console.log("Record added!");
};
db.Product.save(Document, {name: "tunes", quantity: 10, id: 23, price: "35.00", description: "Tuning of skis and boards to get ready for the winter season"} function(err, records)  {
    console.log("Record added!");
};
db.createUser(admin) 
{ user: "admin", 
  pwd: "utahjazz03",
  CustomData: { orders }, 
  roles: [{"administrator", db: "Product"} | "administrator", 
  ....
  ]
}
db.createUser(bsayles) 
{ user: "bsayles", 
  pwd: "Celtics16",
  CustomData: { orders }, 
  roles: [{"customer", db: "Product"} | "customer", 
  ....
  ]
}
};

app.get("/admin/Product/new", function(req,res) {
    res.render("Add.html"), { 
        title: "New Product"
    };
};

app.get("/admin/Product/:id/edit", function(req,res) {
    Product.findById(req.params.id, function(err, doc) {
        res.render("Edit.html"), { 
            title: "Edit Existing Product View", 
            task: doc
        });
    });
});
app.put("/admin/product/:id", function(req,res) {   
    res.render("Add.html");
    Product.finById(req.params.id, function(err, doc) {
        doc.task= req.body, Product.task
        doc.save(function(err) { 
            if (!err) { 
                res.redirect("Products.html")
            }
            else: 
                // error handling
                console.log("Something went wrong.  Please try again.");
            }
        });
    });
app.del("/admin/product/:id", function(req,res) {
    res.render("Delete.html");
    Product.findById(req.params.id, function(err,doc) {
        if (!doc) 
            return next((new NotFound("Document not found.");
            doc.remove(function() { 
                res.redirect("Products.html");
            });
        });
    });
}); 
app.get("/products", function(req,res) { 
    res.render("Products.html");
    });

});
// shopping cart 

angular.module("cart", ['ngRoute']);

.config(["$routeProvider", function($routeProvider) {
    $routeProvider.when("/cart", {
    controller: "CartCtrl"
    });
    }])

    "use strict";

    angular.module("cart", ['ngRoute'])

    .config(["$routeProvider", function($routeProvider) {
        $routeProvider.when("/cart", {
        templateUrl: "public/cart/cart.html",
        controller: "CartCtrl"
    });
    }])

    .controller("CartCtrl", [function() {

        angular.module("shoppingCart", [
        "ngRoute",
        "cart"
        ]).

        "use strict";


        angular.module("shoppingCart", [
        "ngRoute",
        "cart"
        ]).
            config(["$routeProvider", function($routeProvider) {
                $routeProvider.otherwise({
                redirectTo: "/cart"
            });

            // create a check out view page

            "use strict";

            angular.module("checkout", ["ngRoute"])

            .config(["$routeProvider", function($routeProvider) {
                $routeProvider.when("/checkout", {
                templateUrl: 'users/Bryan/checkout.html",
                controller: "CheckoutCtrl"
            });
            }])

            .controller("CheckoutCtrl", ["$scope", function($scope) {

                }]);

                angular.module("shoppingCart", [
                "ngRoute",
                "cart",
                "checkout"
                ]).
                res.redirect("Checkout.html");


                // Search function
                ---
                ---
                    [
                
                });
                ]
                /Create a module using an IIFE

                ;(function(global,$) {
                    /*
                    Put ourselves into "strict" mode
                    This just helps us write cleaner JavaScript
                    */
                    "use strict";

                    Query.prototype = {
                    // this.q is our search query (for example, "javascript tutorial")
                    set: function(val) {
                        this.q = val;
                        return this;
                },
                // brings us to our search page with a query string attached
                goToLocation: function(route) {
                    if(typeof this.q !== "undefined" && typeof this.q === "string") {
                    document.location.href=route+"/?query="+this.q;
                }   else {
                        return;
                }
                },
                // returns our search query (for example, "javascript tutorial")
                get: function() {
                    return this.q;
                },
                // "grab" the query from the query string in the URL and set this.q to it
                setFromURL: function(name) {
                    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
                    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
                    results = regex.exec(location.search);

                    this.q = results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));

                    return this;        
                },
                // a wrapper for jQuery's $.get
                getJSON: function(file) {
                  return $.get(file);
                }   
                };

                // when we initialize a query, we have the option of giving it a query string
                function Query(q) {
                    if(typeof q !== "undefined" && typeof q == "string") {
                    this.q = q;
                }
            }

            // attach the Query object to the window
            global.Query = Query;
            })(this,$);

            // results.js   
            .done(function(data) {
                var searchIndex,
                results,
                $resultsCount = $(".search-results-count"),
                $results = $(".search-results"),
                totalScore = 0,
                percentOfTotal;

                // PIECE 1
                // set up the allowable fields
                searchIndex = lunr(function() {
                    this.field("name");
                    this.field("quantity");
                    this.field("price");
                    this.ref("url");
                    this.field("description");
                });

                // PIECE 2
                // add each item from posts.json to the index
                $.each(data,function(i,item) {
                    searchIndex.add(item);
                });

                // PIECE 3
                // search for the query and store the results as an array
                results = searchIndex.search(query.get());

                // PIECE 4
                // add the title of each post into each result, too (this doesn't come standard with lunr.js)
                for(var result in results) {
                results[result].title = data.filter(function(post) {
                    return post.url === results[result].ref;
                    })[0].title;
                }

                // show how many results there were, in the DOM
                $resultsCount.append(results.length + (results.length === 1 ? " result" : " results") + " for " + query.get() +""");

                // PIECE 5
                // get the total score of all items, so that we can divide each result into it, giving us a percentage
                $.each(results, function(i, result) {
                totalScore+=result.score;
                });

                // PIECE 6 & PIECE 7
                // append each result link, with a border that corresponds to a color with a strength equal to its percentage
                // of the total score
                $.each(results, function(i,result) {
                percentOfTotal = result.score/totalScore;

                $results.append("<li><a href=""+ site + result.ref +"">"+result.title+"</a></li>");
                $results.children("li").last().css({
                "border-left":"20px solid "+utils.shade("#ffffff",-percentOfTotal)
                });

                //Client search function
                // search.js
                $(function(Query) {
                    "use strict";

                    var query = new Query();

                    $(".search").on("submit",submit);   

                    function submit(e) {
                        // stop the form from doing its default behavior
                        e.preventDefault();

                        // set the query, and go to the search page with our query URL
                        query
                        .set($(".search-box").val().trim())
                        .goToLocation("/Search_Results");
                }
                }(Query));

                // results.js
                $(function(Query,utils) {
                    var query = new Query(),
                    site = location.protocol + "//" + location.host,
                    // some utility functions
                    utils = utils;

                    query
                    .setFromURL("query")
                    .getJSON("/posts.json")
                    .done(function(data) {
                        console.log(data);
                    // show our results
                }); 
                }(Query,utils));

            });     
            var options = url.parse("https://www.fraisr.com/api/v1/orders");

            options.method = "POST"
            options.auth = "api_key:api_secret"

            var req = https.request(options, function(res) {
                data = "";

                res.on("data", function(d) {
                data += d
            });

            res.on("end", function(){
                console.log(JSON.parse(data));
            });
        });
        var ShoppingCart = [];

        var data = {
                    product: "abcdef0123456789",
                    cause: "abcdef0123456789",
                    amount: "10",
                    price: "9.95",
                    donation: "25"
        };
        req.end(querystring.stringify(document));

        req.on("error", function(e) {
        console.error(e);

        function AddToCart() {
            counter == Product.quantity
            if Product.quantity > 0: 
            shoppingCart.push(Product)
            counter --
            res.redirect("Search_Results.html");    

            else: 
                console.log("Product is out of stock.  Please replace your order when product is in stock."
                res.redirect("Products.html"):
        });
    });
});
app.get("/users/review", function(req,res) { 
    res.render("Admin_Account_Review.html"), { 
        title: "Review all orders"
    });


    //User function to view all orders
    Product.Order.List(null, function(order) {
        console.log(id);
    },  
    function(error) {
        console.log("An error occurred");  
    },
    function(success) {
        console.log("Here is a list of your orders!");
        console.log(Orders);
    };
});
app.get("/admin/:id/reports", function(req,res) { 
    res.render("Admin_Account_Review.html"), { 
        title: "All orders for %id"
    },
    //Admin report to review orders
    Product.Order.List("<username>", {

        }, 
        function(order) {
            console.log(order);
        },
         function(error) {
            console.log("An error occurred");  
        },
        function(success)  
            console.log("Here is a list of the customer ID orders!");
            console.log(Orders);
        };
    });
});
app.get("/searchresults", { 
    res.render("Search_Results.html").  {
    var ShoppingCart = [],
        document.getElementById("addbutton").onclick = function() { 
            if addbutton.onclick == true: 
                append.ShoppingCart(singleItem);
            else: 
                console.log("Please choose a action.");
        });
    });
});
app.get("/checkout", function(req,res) {
    res.render("Checkout.html"), { 
        title: "Checkout"
    };

    var Orders = [];

    // create a check out view page

    use strict';

    angular.module("checkout", ["ngRoute"])

    .config(["$routeProvider", function($routeProvider) {
        $routeProvider.when("/checkout", {
        templateUrl: "public/checkout/checkout.html",
        controller: "CheckoutCtrl"
    });
    }])

    .controller("CheckoutCtrl", ["$scope", function($scope) {
    }]);

    angular.module("shoppingCart", [
                    "ngRoute",
                    "cart",
                    "checkout"
                    ]).

     Orders.push(ShoppingCart.id)
    });
});

app.listen("27017",function(){
    console.log("Server running at http://localhost:27017 !!")
};

I've created a jsfiddle: hmttps://jsfiddle.net/#&togetherjs=7Kx4rGUmBd Any ideas what is wrong? Thanks for your help.



via bsayles12

No comments:

Post a Comment