├── client ├── typings │ ├── tsd.d.ts │ └── socket.io-client │ │ └── socket.io-client.d.ts ├── tsd.json ├── tsconfig.json ├── build │ ├── app │ │ ├── components │ │ │ ├── rate │ │ │ │ ├── rate.html │ │ │ │ └── rateComponent.js │ │ │ ├── socket │ │ │ │ ├── socket.html │ │ │ │ ├── socketComponent.js │ │ │ │ └── socketService.js │ │ │ ├── home │ │ │ │ ├── home.html │ │ │ │ └── homeComponent.js │ │ │ ├── category │ │ │ │ ├── category.html │ │ │ │ └── categoryComponent.js │ │ │ ├── selling │ │ │ │ ├── selling.html │ │ │ │ └── sellingComponent.js │ │ │ ├── form │ │ │ │ ├── customValidator.js │ │ │ │ ├── form.html │ │ │ │ └── formComponent.js │ │ │ ├── product │ │ │ │ ├── product.html │ │ │ │ └── productComponent.js │ │ │ ├── inventry │ │ │ │ ├── inventry.html │ │ │ │ └── inventryComponent.js │ │ │ ├── testApi │ │ │ │ └── apiComponent.js │ │ │ └── app │ │ │ │ ├── app.html │ │ │ │ └── appComponent.js │ │ └── boot.js │ └── index.html └── src │ ├── app │ ├── components │ │ ├── rate │ │ │ ├── rate.html │ │ │ └── rateComponent.ts │ │ ├── socket │ │ │ ├── socketComponent.ts │ │ │ ├── socket.html │ │ │ └── socketService.ts │ │ ├── home │ │ │ ├── home.html │ │ │ └── homeComponent.ts │ │ ├── category │ │ │ ├── category.html │ │ │ └── categoryComponent.ts │ │ ├── testApi │ │ │ └── apiComponent.ts │ │ ├── form │ │ │ ├── customValidator.ts │ │ │ ├── formComponent.ts │ │ │ └── form.html │ │ ├── selling │ │ │ ├── selling.html │ │ │ └── sellingComponent.ts │ │ ├── product │ │ │ ├── product.html │ │ │ └── productComponent.ts │ │ ├── app │ │ │ ├── appComponent.ts │ │ │ └── app.html │ │ └── inventry │ │ │ ├── inventry.html │ │ │ └── inventryComponent.ts │ └── boot.ts │ └── index.html ├── server ├── tsconfig.json ├── typings │ ├── tsd.d.ts │ ├── mime │ │ └── mime.d.ts │ ├── serve-static │ │ └── serve-static.d.ts │ ├── body-parser │ │ └── body-parser.d.ts │ └── q │ │ └── Q.d.ts ├── build │ ├── rate │ │ ├── rateRouter.js │ │ ├── rateController.js │ │ └── rateModel.js │ ├── user │ │ ├── userRouter.js │ │ ├── userController.js │ │ └── userModel.js │ ├── selling │ │ ├── sellingRouter.js │ │ ├── sellingController.js │ │ └── sellingModel.js │ ├── category │ │ ├── categoryRouter.js │ │ ├── categoryController.js │ │ └── categoryModel.js │ ├── inventry │ │ ├── inventryRouter.js │ │ ├── inventryController.js │ │ └── inventryModel.js │ ├── product │ │ ├── productRouter.js │ │ ├── productController.js │ │ └── productModel.js │ ├── helpers │ │ └── helper.js │ └── app.js ├── src │ ├── rate │ │ ├── rateRouter.ts │ │ ├── rateController.ts │ │ └── rateModel.ts │ ├── user │ │ ├── userRouter.ts │ │ ├── userController.ts │ │ └── userModel.ts │ ├── selling │ │ ├── sellingRouter.ts │ │ ├── sellingController.ts │ │ └── sellingModel.ts │ ├── category │ │ ├── categoryRouter.ts │ │ ├── categoryController.ts │ │ └── categoryModel.ts │ ├── inventry │ │ ├── inventryRouter.ts │ │ ├── inventryController.ts │ │ └── inventryModel.ts │ ├── product │ │ ├── productRouter.ts │ │ ├── productController.ts │ │ └── productModel.ts │ ├── helpers │ │ └── helper.ts │ └── app.ts └── tsd.json ├── README.md ├── package.json └── gulpfile.js /client/typings/tsd.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /server/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES5", 4 | "module": "commonjs" 5 | }, 6 | "exclude": [ 7 | "node_modules" 8 | ] 9 | } -------------------------------------------------------------------------------- /client/tsd.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v4", 3 | "repo": "borisyankov/DefinitelyTyped", 4 | "ref": "master", 5 | "path": "typings", 6 | "bundle": "typings/tsd.d.ts", 7 | "installed": { 8 | "socket.io-client/socket.io-client.d.ts": { 9 | "commit": "0d622d857f97d44ea7dcad2b3edec1f23c48fe9e" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ng2seed 2 | Typed Nodejs/Express & Angular2 3 | 4 | Sample Code using: NodeJS, ExpressJS, Angular2 (routing, form validation, http), Socket 5 | 6 | for run this application... 7 | 8 | 1. open terminal / command prompt 9 | 2. type: npm install 10 | 3. type: npm start 11 | 4. open your browser and type: http://localhost:4000 12 | -------------------------------------------------------------------------------- /client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES5", 4 | "module": "system", 5 | "moduleResolution": "node", 6 | "sourceMap": true, 7 | "emitDecoratorMetadata": true, 8 | "experimentalDecorators": true, 9 | "removeComments": false, 10 | "noImplicitAny": false 11 | }, 12 | "exclude": [ 13 | "node_modules" 14 | ] 15 | } -------------------------------------------------------------------------------- /client/build/app/components/rate/rate.html: -------------------------------------------------------------------------------- 1 |

Rate List

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /client/src/app/components/rate/rate.html: -------------------------------------------------------------------------------- 1 |

Rate List

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /server/typings/tsd.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | /// 8 | /// 9 | -------------------------------------------------------------------------------- /server/build/rate/rateRouter.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | var express = require("express"); 4 | var router = express.Router(); 5 | //import controller 6 | var controller = require("./rateController"); 7 | //Get 8 | // router.get('/', controller.Index_get) 9 | ; 10 | //router.post('/', controller.UserSave_post); 11 | router.get('/getRate', controller.getRate); 12 | router.post('/Rate', controller.RateSave_post); 13 | module.exports = router; 14 | -------------------------------------------------------------------------------- /server/build/user/userRouter.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | var express = require("express"); 4 | var router = express.Router(); 5 | //import controller 6 | var controller = require("./userController"); 7 | //Get 8 | // router.get('/', controller.Index_get) 9 | ; 10 | //router.post('/', controller.UserSave_post); 11 | router.get('/getUser', controller.getAllUsers); 12 | router.post('/User', controller.UserSave_post); 13 | module.exports = router; 14 | -------------------------------------------------------------------------------- /server/build/selling/sellingRouter.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | var express = require("express"); 4 | var router = express.Router(); 5 | //import controller 6 | var controller = require("./sellingController"); 7 | //Get 8 | // router.get('/', controller.Index_get) 9 | ; 10 | //router.post('/', controller.UserSave_post); 11 | router.get('/getSellers', controller.getSeller); 12 | router.post('/Selling', controller.sellingSave_post); 13 | module.exports = router; 14 | -------------------------------------------------------------------------------- /server/build/category/categoryRouter.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | var express = require("express"); 4 | var router = express.Router(); 5 | //import controller 6 | var controller = require("./categoryController"); 7 | //Get 8 | // router.get('/', controller.Index_get) 9 | ; 10 | //router.post('/', controller.UserSave_post); 11 | router.get('/getCategory', controller.getAllUsers); 12 | router.post('/Category', controller.CategorySave_post); 13 | module.exports = router; 14 | -------------------------------------------------------------------------------- /server/build/inventry/inventryRouter.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | var express = require("express"); 4 | var router = express.Router(); 5 | //import controller 6 | var controller = require("./inventryController"); 7 | //Get 8 | // router.get('/', controller.Index_get) 9 | ; 10 | //router.post('/', controller.UserSave_post); 11 | router.get('/getInventry', controller.getInventry); 12 | router.post('/Inventry', controller.InventrySave_post); 13 | module.exports = router; 14 | -------------------------------------------------------------------------------- /server/build/product/productRouter.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /// 3 | var express = require("express"); 4 | var router = express.Router(); 5 | //import controller 6 | var controller = require("./productController"); 7 | //Get 8 | // router.get('/', controller.Index_get) 9 | ; 10 | //router.post('/', controller.UserSave_post); 11 | router.get('/getProducts', controller.getAllgetProducts); 12 | router.post('/Category', controller.ProductSave_post); 13 | module.exports = router; 14 | -------------------------------------------------------------------------------- /server/src/rate/rateRouter.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import express = require("express"); 3 | var router : express.Router = express.Router(); 4 | 5 | //import controller 6 | import * as controller from "./rateController"; 7 | 8 | //Get 9 | // router.get('/', controller.Index_get) 10 | ; 11 | //router.post('/', controller.UserSave_post); 12 | router.get('/getRate', controller.getRate); 13 | router.post('/Rate', controller.RateSave_post); 14 | // router.post('/signin', controller.UserSigin_post); 15 | // router.put('/updateUserStatus',controller.updateUserStatus); 16 | 17 | 18 | export = router; -------------------------------------------------------------------------------- /server/src/user/userRouter.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import express = require("express"); 3 | var router : express.Router = express.Router(); 4 | 5 | //import controller 6 | import * as controller from "./userController"; 7 | 8 | //Get 9 | // router.get('/', controller.Index_get) 10 | ; 11 | //router.post('/', controller.UserSave_post); 12 | router.get('/getUser', controller.getAllUsers); 13 | router.post('/User', controller.UserSave_post); 14 | // router.post('/signin', controller.UserSigin_post); 15 | // router.put('/updateUserStatus',controller.updateUserStatus); 16 | 17 | 18 | export = router; -------------------------------------------------------------------------------- /server/src/selling/sellingRouter.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import express = require("express"); 3 | var router : express.Router = express.Router(); 4 | 5 | //import controller 6 | import * as controller from "./sellingController"; 7 | 8 | //Get 9 | // router.get('/', controller.Index_get) 10 | ; 11 | //router.post('/', controller.UserSave_post); 12 | router.get('/getSellers', controller.getSeller); 13 | router.post('/Selling', controller.sellingSave_post); 14 | // router.post('/signin', controller.UserSigin_post); 15 | // router.put('/updateUserStatus',controller.updateUserStatus); 16 | 17 | 18 | export = router; -------------------------------------------------------------------------------- /server/src/category/categoryRouter.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import express = require("express"); 3 | var router : express.Router = express.Router(); 4 | 5 | //import controller 6 | import * as controller from "./categoryController"; 7 | 8 | //Get 9 | // router.get('/', controller.Index_get) 10 | ; 11 | //router.post('/', controller.UserSave_post); 12 | router.get('/getCategory', controller.getAllUsers); 13 | router.post('/Category', controller.CategorySave_post); 14 | // router.post('/signin', controller.UserSigin_post); 15 | // router.put('/updateUserStatus',controller.updateUserStatus); 16 | 17 | 18 | export = router; -------------------------------------------------------------------------------- /server/src/inventry/inventryRouter.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import express = require("express"); 3 | var router : express.Router = express.Router(); 4 | 5 | //import controller 6 | import * as controller from "./inventryController"; 7 | 8 | //Get 9 | // router.get('/', controller.Index_get) 10 | ; 11 | //router.post('/', controller.UserSave_post); 12 | router.get('/getInventry', controller.getInventry); 13 | router.post('/Inventry', controller.InventrySave_post); 14 | // router.post('/signin', controller.UserSigin_post); 15 | // router.put('/updateUserStatus',controller.updateUserStatus); 16 | 17 | 18 | export = router; -------------------------------------------------------------------------------- /server/src/product/productRouter.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import express = require("express"); 3 | var router : express.Router = express.Router(); 4 | 5 | //import controller 6 | import * as controller from "./productController"; 7 | 8 | //Get 9 | // router.get('/', controller.Index_get) 10 | ; 11 | //router.post('/', controller.UserSave_post); 12 | router.get('/getProducts', controller.getAllgetProducts); 13 | router.post('/Category', controller.ProductSave_post); 14 | // router.post('/signin', controller.UserSigin_post); 15 | // router.put('/updateUserStatus',controller.updateUserStatus); 16 | 17 | 18 | export = router; -------------------------------------------------------------------------------- /client/src/app/components/socket/socketComponent.ts: -------------------------------------------------------------------------------- 1 | import { Component } from "angular2/core"; 2 | import { SocketService } from "./socketService"; 3 | 4 | 5 | @Component({ 6 | selector: "socket", 7 | templateUrl: "./app/components/socket/socket.html" 8 | //providers: [SocketService] 9 | }) 10 | export class SocketComponent { 11 | socket: any; 12 | fruitz: Array; 13 | 14 | // constructor 15 | constructor(private io: SocketService) { 16 | this.fruitz = this.io.getAllFruits(); 17 | } 18 | 19 | add(name) { 20 | if(name.trim().length > 2){ 21 | this.io.add(name); 22 | } 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /client/build/app/components/socket/socket.html: -------------------------------------------------------------------------------- 1 |

Scoket Sample

2 | 3 |

Add Fruits

4 | 5 |
6 |
7 | 8 |
9 | 10 |
11 |
12 | 13 |
14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 |
{{i}} - {{f}}
23 |
-------------------------------------------------------------------------------- /client/src/app/components/home/home.html: -------------------------------------------------------------------------------- 1 |

Home Page

2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 15 | 16 | 17 |
    18 |
  • 19 | Name: {{get.fName}}
    20 | Dec: {{get.lName}}
    21 | Type: {{get.type}} 22 |
  • 23 | 24 |
-------------------------------------------------------------------------------- /client/src/app/components/socket/socket.html: -------------------------------------------------------------------------------- 1 |

Scoket Sample

2 | 3 |

Add Fruits

4 | 5 |
6 |
7 | 8 |
9 | 10 |
11 |
12 | 13 |
14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 |
{{i}} - {{f}}
23 |
-------------------------------------------------------------------------------- /client/build/app/components/home/home.html: -------------------------------------------------------------------------------- 1 |

Home Page

2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 15 | 16 | 17 |
    18 |
  • 19 | Name: {{get.fName}}
    20 | Dec: {{get.lName}}
    21 | Type: {{get.type}} 22 |
  • 23 | 24 |
-------------------------------------------------------------------------------- /server/typings/mime/mime.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for mime 2 | // Project: https://github.com/broofa/node-mime 3 | // Definitions by: Jeff Goddard 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | // Imported from: https://github.com/soywiz/typescript-node-definitions/mime.d.ts 7 | 8 | declare module "mime" { 9 | export function lookup(path: string): string; 10 | export function extension(mime: string): string; 11 | export function load(filepath: string): void; 12 | export function define(mimes: Object): void; 13 | 14 | interface Charsets { 15 | lookup(mime: string): string; 16 | } 17 | 18 | export var charsets: Charsets; 19 | export var default_type: string; 20 | } 21 | -------------------------------------------------------------------------------- /client/build/app/components/category/category.html: -------------------------------------------------------------------------------- 1 |

Category

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
Name: {{get.categoryName}} Dec: {{get.categoryDec}}
24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /client/src/app/components/category/category.html: -------------------------------------------------------------------------------- 1 |

Category

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
Name: {{get.categoryName}} Dec: {{get.categoryDec}}
24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /client/src/app/components/testApi/apiComponent.ts: -------------------------------------------------------------------------------- 1 | import { Component } from "angular2/core"; 2 | import { Http, Response, RequestOptions, Headers } from 'angular2/http'; //for http request (rest API) 3 | 4 | @Component({ 5 | selector: 'test-api', 6 | template: '

Api

 {{receivedFromServer | json}} 
', 7 | }) 8 | export class ApiComponent { 9 | receivedFromServer: any 10 | 11 | constructor(private http: Http) { 12 | //constructor 13 | 14 | //calling test api (testing) 15 | this.testApi(); 16 | } 17 | 18 | testApi(): void { 19 | this.http.request('http://localhost:4000/api/test') 20 | .subscribe((res: Response) => { 21 | this.receivedFromServer = res.json(); 22 | }); //http.request 23 | } 24 | 25 | 26 | } -------------------------------------------------------------------------------- /client/src/app/boot.ts: -------------------------------------------------------------------------------- 1 | 2 | //Builtin Methods 3 | import { provide } from "angular2/core" ; 4 | import { bootstrap } from "angular2/platform/browser" ; 5 | import { HTTP_PROVIDERS } from "angular2/http"; // getting http compnent 6 | import { ROUTER_PROVIDERS, LocationStrategy, HashLocationStrategy} from "angular2/router"; // with hash on url 7 | import {FORM_PROVIDERS} from "angular2/common"; // getting form_providers for form validation (not required its work without importing also) 8 | import { SocketService } from "./components/socket/socketService"; 9 | 10 | // Import Components 11 | import {AppComponent} from "./components/app/appComponent"; 12 | 13 | // Bootstraping 14 | bootstrap(AppComponent, [ 15 | ROUTER_PROVIDERS, 16 | HTTP_PROVIDERS, 17 | FORM_PROVIDERS, 18 | SocketService, 19 | provide(LocationStrategy, { useClass: HashLocationStrategy }) // angular hashing urls 20 | // form builder for form validations 21 | ]); -------------------------------------------------------------------------------- /server/tsd.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v4", 3 | "repo": "borisyankov/DefinitelyTyped", 4 | "ref": "master", 5 | "path": "typings", 6 | "bundle": "typings/tsd.d.ts", 7 | "installed": { 8 | "body-parser/body-parser.d.ts": { 9 | "commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4" 10 | }, 11 | "express/express.d.ts": { 12 | "commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4" 13 | }, 14 | "node/node.d.ts": { 15 | "commit": "552fe5d3e45ef9c8ecd3eda2b6a24d2546c438f4" 16 | }, 17 | "serve-static/serve-static.d.ts": { 18 | "commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4" 19 | }, 20 | "mime/mime.d.ts": { 21 | "commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4" 22 | }, 23 | "q/Q.d.ts": { 24 | "commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4" 25 | }, 26 | "mongoose/mongoose.d.ts": { 27 | "commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4" 28 | }, 29 | "socket.io/socket.io.d.ts": { 30 | "commit": "552fe5d3e45ef9c8ecd3eda2b6a24d2546c438f4" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /server/build/helpers/helper.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var _User = require('./../category/categoryModel'); 3 | function CreateCategory(cb) { 4 | var u1 = { categoryName: 'MuZz', categoryDec: "Something" }; 5 | var userObj = new _User.User(u1); 6 | //checking user exists or not 7 | _User.User.isUserExists(userObj.categoryName, function (error, result) { 8 | console.log('user -- exists?', error); 9 | if (!error) { 10 | userObj.create(userObj, function (err, data) { 11 | if (err) { 12 | console.log('User Create Err'); 13 | console.log(err); 14 | cb(false); 15 | } 16 | else { 17 | console.log('User Created'); 18 | console.log(data); 19 | } 20 | }); //userObj.create 21 | } 22 | else { 23 | console.log('User/Member not created...Err!'); 24 | console.log(error); 25 | cb(false); 26 | } 27 | }); //User.isUserExists 28 | } //CreateUserAndMember 29 | -------------------------------------------------------------------------------- /server/build/rate/rateController.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var RateModel_1 = require("./RateModel"); //import Member Class 3 | var user = new RateModel_1.User(); 4 | //Object 5 | var Controller = { 6 | RateSave_post: function (req, res) { 7 | console.log(req.body, "rrrrrrrrrrrrrrrrrrrrrrrrrrrrr"); 8 | var Obj = req.body; 9 | user.create(Obj, function (err, data) { 10 | if (err) { 11 | res.json({ 'success': false, 'data': null, 'error': err }); 12 | } 13 | else { 14 | res.json({ 'success': true, 'data': data, 'error': null }); 15 | } 16 | }); 17 | }, 18 | getRate: function (req, res) { 19 | RateModel_1.RateModel.find({}, function (err, data) { 20 | console.log('controller err', err); 21 | console.log('controller data', data); 22 | if (err) { 23 | res.send({ 'success': false, 'data': null, 'error': err }); 24 | } 25 | else { 26 | res.send({ 'success': true, 'data': data, 'error': err }); 27 | } 28 | }); 29 | }, 30 | }; 31 | module.exports = Controller; 32 | -------------------------------------------------------------------------------- /server/build/user/userController.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var userModel_1 = require("./userModel"); //import Member Class 3 | var user = new userModel_1.User(); 4 | //Object 5 | var Controller = { 6 | UserSave_post: function (req, res) { 7 | console.log(req.body, "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu"); 8 | var userObj = req.body; 9 | user.create(userObj, function (err, data) { 10 | if (err) { 11 | res.json({ 'success': false, 'data': null, 'error': err }); 12 | } 13 | else { 14 | res.json({ 'success': true, 'data': data, 'error': null }); 15 | } 16 | }); 17 | }, 18 | getAllUsers: function (req, res) { 19 | userModel_1.userModel.find({}, function (err, data) { 20 | console.log('controller err', err); 21 | console.log('controller data', data); 22 | if (err) { 23 | res.send({ 'success': false, 'data': null, 'error': err }); 24 | } 25 | else { 26 | res.send({ 'success': true, 'data': data, 'error': err }); 27 | } 28 | }); 29 | }, 30 | }; 31 | module.exports = Controller; 32 | -------------------------------------------------------------------------------- /client/src/app/components/form/customValidator.ts: -------------------------------------------------------------------------------- 1 | import {Control} from "angular2/common"; 2 | 3 | // Custom form validation 4 | // Of course we can also write our own custom validators. 5 | // Here is an example of a validator that checks if the first character is not a number: 6 | 7 | interface ValidationResult { 8 | [key: string]: boolean; 9 | } 10 | 11 | export class UsernameValidator { 12 | 13 | static startsWithNumber (control: Control): ValidationResult { 14 | if ( control.value !== "" && !isNaN(control.value.charAt(0)) ) { 15 | return { "startsWithNumber" : true }; 16 | } 17 | return null; 18 | } 19 | 20 | static emailValidation(control: Control): ValidationResult { 21 | let pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/; 22 | if ( control.value !== "" && !control.value.match(pattern) ) { 23 | return { "emailValidation": true }; 24 | } 25 | return null; 26 | } 27 | } 28 | 29 | 30 | // One weird thing you might notice is that returning null actually means the validation is valid. 31 | // If we find a number at the first position of the string we return the validation error { “startsWithNumber”: true } -------------------------------------------------------------------------------- /server/build/selling/sellingController.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var sellingModel_1 = require("./sellingModel"); //import Member Class 3 | var user = new sellingModel_1.User(); 4 | //Object 5 | var Controller = { 6 | sellingSave_post: function (req, res) { 7 | console.log(req.body, "ssssssssssssssssssssssss"); 8 | var Obj = req.body; 9 | user.create(Obj, function (err, data) { 10 | if (err) { 11 | res.json({ 'success': false, 'data': null, 'error': err }); 12 | } 13 | else { 14 | res.json({ 'success': true, 'data': data, 'error': null }); 15 | } 16 | }); 17 | }, 18 | getSeller: function (req, res) { 19 | sellingModel_1.sellingModel.find({}, function (err, data) { 20 | console.log('controller err', err); 21 | console.log('controller data', data); 22 | if (err) { 23 | res.send({ 'success': false, 'data': null, 'error': err }); 24 | } 25 | else { 26 | res.send({ 'success': true, 'data': data, 'error': err }); 27 | } 28 | }); 29 | }, 30 | }; 31 | module.exports = Controller; 32 | -------------------------------------------------------------------------------- /server/build/inventry/inventryController.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var InventryModel_1 = require("./InventryModel"); //import Member Class 3 | var user = new InventryModel_1.User(); 4 | //Object 5 | var Controller = { 6 | InventrySave_post: function (req, res) { 7 | console.log(req.body, "iiiiiiiiiiiiiiiiiiiiiiiiiiiiii"); 8 | var Obj = req.body; 9 | user.create(Obj, function (err, data) { 10 | if (err) { 11 | res.json({ 'success': false, 'data': null, 'error': err }); 12 | } 13 | else { 14 | res.json({ 'success': true, 'data': data, 'error': null }); 15 | } 16 | }); 17 | }, 18 | getInventry: function (req, res) { 19 | InventryModel_1.InventryModel.find({}, function (err, data) { 20 | console.log('controller err', err); 21 | console.log('controller data', data); 22 | if (err) { 23 | res.send({ 'success': false, 'data': null, 'error': err }); 24 | } 25 | else { 26 | res.send({ 'success': true, 'data': data, 'error': err }); 27 | } 28 | }); 29 | }, 30 | }; 31 | module.exports = Controller; 32 | -------------------------------------------------------------------------------- /server/build/product/productController.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var ProductModel_1 = require("./ProductModel"); //import Member Class 3 | var user = new ProductModel_1.User(); 4 | //Object 5 | var Controller = { 6 | ProductSave_post: function (req, res) { 7 | console.log(req.body, "pppppppppppppppppppppppppppp"); 8 | var Obj = req.body; 9 | user.create(Obj, function (err, data) { 10 | if (err) { 11 | res.json({ 'success': false, 'data': null, 'error': err }); 12 | } 13 | else { 14 | res.json({ 'success': true, 'data': data, 'error': null }); 15 | } 16 | }); 17 | }, 18 | getAllgetProducts: function (req, res) { 19 | ProductModel_1.ProductModel.find({}, function (err, data) { 20 | console.log('controller err', err); 21 | console.log('controller data', data); 22 | if (err) { 23 | res.send({ 'success': false, 'data': null, 'error': err }); 24 | } 25 | else { 26 | res.send({ 'success': true, 'data': data, 'error': err }); 27 | } 28 | }); 29 | }, 30 | }; 31 | module.exports = Controller; 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angularstarter", 3 | "version": "0.1.0", 4 | "description": "Angular2 Starter", 5 | "main": "app.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start2": "node ./server/build/app", 9 | "start": "gulp start" 10 | }, 11 | "keywords": [ 12 | "Angular2 Starter App", 13 | "Angular2 Starter Seed with Server", 14 | "Typed Angular2 Starter Seed with Server", 15 | "Typed Angular2 Stater App with Server" 16 | ], 17 | "author": "Yousuf Qutubuddin", 18 | "license": "ISC", 19 | "dependencies": { 20 | "angular2": "2.0.0-beta.3", 21 | "body-parser": "^1.14.2", 22 | "del": "^2.2.0", 23 | "es6-promise": "^3.0.2", 24 | "es6-shim": "^0.33.3", 25 | "express": "^4.13.4", 26 | "gulp": "^3.9.1", 27 | "gulp-nodemon": "^2.0.6", 28 | "gulp-open": "^1.0.0", 29 | "gulp-sequence": "^0.4.4", 30 | "gulp-typescript": "^2.10.0", 31 | "gulp-webserver": "^0.9.1", 32 | "mongoose": "^4.4.2", 33 | "reflect-metadata": "0.1.2", 34 | "rxjs": "5.0.0-beta.0", 35 | "socket.io": "^1.4.5", 36 | "socket.io-client": "^1.4.5", 37 | "systemjs": "0.19.6", 38 | "zone.js": "0.5.11" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /server/build/category/categoryController.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var categoryModel_1 = require("./categoryModel"); //import Member Class 3 | var user = new categoryModel_1.User(); 4 | //Object 5 | var Controller = { 6 | CategorySave_post: function (req, res) { 7 | console.log(req.body, "ccccccccccccccccccccccccccc"); 8 | var categoryObj = req.body; 9 | user.create(categoryObj, function (err, data) { 10 | if (err) { 11 | res.json({ 'success': false, 'data': null, 'error': err }); 12 | } 13 | else { 14 | res.json({ 'success': true, 'data': data, 'error': null }); 15 | } 16 | }); 17 | }, 18 | getAllUsers: function (req, res) { 19 | categoryModel_1.categoryModel.find({}, function (err, data) { 20 | console.log('controller err', err); 21 | console.log('controller data', data); 22 | if (err) { 23 | res.send({ 'success': false, 'data': null, 'error': err }); 24 | } 25 | else { 26 | res.send({ 'success': true, 'data': data, 'error': err }); 27 | } 28 | }); 29 | }, 30 | }; 31 | module.exports = Controller; 32 | -------------------------------------------------------------------------------- /client/src/app/components/rate/rateComponent.ts: -------------------------------------------------------------------------------- 1 | import { Component } from "angular2/core" ; 2 | import { Http, Response, RequestOptions, Headers } from 'angular2/http'; //for http request (rest API) 3 | 4 | @Component({ 5 | selector : 'home', 6 | templateUrl : "./app/components/rate/rate.html" 7 | }) 8 | export class RateComponent{ 9 | rate : {} 10 | getData; 11 | constructor(public http: Http) { 12 | this.rate = { 13 | rates : "", 14 | rateDec: "" 15 | } 16 | this.http.get('/api/rate/getRate') 17 | .subscribe((res: Response) => { 18 | this.getData = res.json().data 19 | console.log(res.json().data) 20 | }) 21 | } 22 | 23 | 24 | send(rate): void { 25 | let headers: Headers = new Headers(); 26 | headers.append('Content-Type', 'application/json'); 27 | let options: RequestOptions = new RequestOptions(); 28 | options.headers = headers; 29 | 30 | this.http.post('/api/rate/Rate' ,JSON.stringify(rate), options) 31 | 32 | .subscribe((res: Response) => { 33 | console.log(res) 34 | 35 | }); 36 | 37 | ; //http.post 38 | 39 | } 40 | // } 41 | 42 | } -------------------------------------------------------------------------------- /server/build/selling/sellingModel.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var mongoose = require('mongoose'); //import mongodb 3 | //////////////////// Mongoose //////////////////////// 4 | //Creating Schema for User in MongoDB 5 | var userSchema = new mongoose.Schema({ 6 | productName: String, 7 | unit: String 8 | }); 9 | exports.sellingModel = mongoose.model("Selling", userSchema); //Create Collection with the name of Users (in db it shows Todos) 10 | //user class 11 | var User = (function () { 12 | function User() { 13 | } 14 | //constructor 15 | // constructor(user?: IUser) { 16 | // if (user) { 17 | // this.categoryName = user.categoryName 18 | // this.productName = user.productName 19 | // this.rate = user.rate 20 | // this.userName = user.userName 21 | // this.unit = user.unit 22 | // } 23 | // } 24 | //create user 25 | User.prototype.create = function (user, cb) { 26 | var Obj = new exports.sellingModel(user); 27 | Obj.save(function (error, data) { 28 | if (error) { 29 | cb(error, null); 30 | } 31 | cb(null, data); 32 | }); 33 | }; 34 | ; 35 | return User; 36 | }()); 37 | exports.User = User; 38 | -------------------------------------------------------------------------------- /server/src/rate/rateController.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import express = require("express"); 3 | import {User, IUser,RateModel} from "./RateModel"; //import Member Class 4 | 5 | 6 | let user = new User(); 7 | 8 | //Object 9 | let Controller = { 10 | 11 | RateSave_post: (req: express.Request, res: express.Response) => { 12 | console.log(req.body,"rrrrrrrrrrrrrrrrrrrrrrrrrrrrr") 13 | var Obj: IUser = req.body; 14 | user.create(Obj, (err, data) => { 15 | if (err) { 16 | res.json({ 'success': false, 'data': null, 'error': err }); 17 | } else { 18 | res.json({ 'success': true, 'data': data, 'error': null }); 19 | } 20 | }); 21 | }, 22 | 23 | getRate(req:express.Request, res:express.Response){ 24 | RateModel.find({},(err,data) => { 25 | console.log('controller err',err) 26 | console.log('controller data',data) 27 | if(err){ 28 | res.send({'success': false , 'data': null, 'error': err}) 29 | } 30 | else{ 31 | res.send({'success': true,'data': data, 'error': err }) 32 | } 33 | }) 34 | 35 | }, 36 | 37 | }; 38 | 39 | //export controller object 40 | export = Controller; 41 | -------------------------------------------------------------------------------- /client/src/app/components/home/homeComponent.ts: -------------------------------------------------------------------------------- 1 | import { Component } from "angular2/core" ; 2 | import { Http, Response, RequestOptions, Headers } from 'angular2/http'; //for http request (rest API) 3 | 4 | @Component({ 5 | selector : 'home', 6 | templateUrl : "./app/components/home/home.html" 7 | }) 8 | export class HomeComponent{ 9 | user : {} 10 | getData; 11 | constructor(public http: Http) { 12 | this.user = { 13 | fName : "", 14 | lName: "", 15 | type : "" 16 | } 17 | this.http.get('/api/user/getUser') 18 | .subscribe((res: Response) => { 19 | this.getData = res.json().data 20 | console.log(res.json().data) 21 | }) 22 | } 23 | 24 | 25 | send(user): void { 26 | let headers: Headers = new Headers(); 27 | headers.append('Content-Type', 'application/json'); 28 | let options: RequestOptions = new RequestOptions(); 29 | options.headers = headers; 30 | 31 | this.http.post('/api/user/User' ,JSON.stringify(user), options) 32 | 33 | .subscribe((res: Response) => { 34 | console.log("Create User :",res) 35 | 36 | }); 37 | 38 | ; //http.post 39 | 40 | } 41 | // } 42 | 43 | } -------------------------------------------------------------------------------- /server/src/user/userController.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import express = require("express"); 3 | import {User, IUser,userModel} from "./userModel"; //import Member Class 4 | 5 | 6 | let user = new User(); 7 | 8 | //Object 9 | let Controller = { 10 | 11 | UserSave_post: (req: express.Request, res: express.Response) => { 12 | console.log(req.body,"uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu") 13 | var userObj: IUser = req.body; 14 | user.create(userObj, (err, data) => { 15 | if (err) { 16 | res.json({ 'success': false, 'data': null, 'error': err }); 17 | } else { 18 | res.json({ 'success': true, 'data': data, 'error': null }); 19 | } 20 | }); 21 | }, 22 | 23 | getAllUsers(req:express.Request, res:express.Response){ 24 | userModel.find({},(err,data) => { 25 | console.log('controller err',err) 26 | console.log('controller data',data) 27 | if(err){ 28 | res.send({'success': false , 'data': null, 'error': err}) 29 | } 30 | else{ 31 | res.send({'success': true,'data': data, 'error': err }) 32 | } 33 | }) 34 | 35 | }, 36 | 37 | }; 38 | 39 | //export controller object 40 | export = Controller; 41 | -------------------------------------------------------------------------------- /client/src/app/components/category/categoryComponent.ts: -------------------------------------------------------------------------------- 1 | import { Component } from "angular2/core" ; 2 | import { Http, Response, RequestOptions, Headers } from 'angular2/http'; //for http request (rest API) 3 | 4 | @Component({ 5 | selector : 'home', 6 | templateUrl : "./app/components/category/category.html" 7 | }) 8 | export class CategoryComponent{ 9 | user : {} 10 | getData; 11 | constructor(public http: Http) { 12 | this.user = { 13 | categoryName : "", 14 | categoryDec: "" 15 | } 16 | this.http.get('/api/getCategory') 17 | .subscribe((res: Response) => { 18 | this.getData = res.json().data 19 | console.log(res.json().data) 20 | }) 21 | } 22 | 23 | 24 | send(user): void { 25 | let headers: Headers = new Headers(); 26 | headers.append('Content-Type', 'application/json'); 27 | let options: RequestOptions = new RequestOptions(); 28 | options.headers = headers; 29 | 30 | this.http.post('/api/Category' ,JSON.stringify(user), options) 31 | 32 | .subscribe((res: Response) => { 33 | console.log("Create Category : ",res) 34 | 35 | }); 36 | 37 | ; //http.post 38 | 39 | } 40 | // } 41 | 42 | } -------------------------------------------------------------------------------- /server/src/product/productController.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import express = require("express"); 3 | import {User, IUser,ProductModel} from "./ProductModel"; //import Member Class 4 | 5 | 6 | let user = new User(); 7 | 8 | //Object 9 | let Controller = { 10 | 11 | ProductSave_post: (req: express.Request, res: express.Response) => { 12 | console.log(req.body,"pppppppppppppppppppppppppppp") 13 | var Obj: IUser = req.body; 14 | user.create(Obj, (err, data) => { 15 | if (err) { 16 | res.json({ 'success': false, 'data': null, 'error': err }); 17 | } else { 18 | res.json({ 'success': true, 'data': data, 'error': null }); 19 | } 20 | }); 21 | }, 22 | 23 | getAllgetProducts(req:express.Request, res:express.Response){ 24 | ProductModel.find({},(err,data) => { 25 | console.log('controller err',err) 26 | console.log('controller data',data) 27 | if(err){ 28 | res.send({'success': false , 'data': null, 'error': err}) 29 | } 30 | else{ 31 | res.send({'success': true,'data': data, 'error': err }) 32 | } 33 | }) 34 | 35 | }, 36 | 37 | }; 38 | 39 | //export controller object 40 | export = Controller; 41 | -------------------------------------------------------------------------------- /server/src/selling/sellingController.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import express = require("express"); 3 | import {User, IUser,sellingModel} from "./sellingModel"; //import Member Class 4 | 5 | 6 | let user = new User(); 7 | 8 | //Object 9 | let Controller = { 10 | 11 | sellingSave_post: (req: express.Request, res: express.Response) => { 12 | console.log(req.body,"ssssssssssssssssssssssss") 13 | var Obj: IUser = req.body; 14 | 15 | user.create(Obj, (err, data) => { 16 | if (err) { 17 | res.json({ 'success': false, 'data': null, 'error': err }); 18 | } else { 19 | res.json({ 'success': true, 'data': data, 'error': null }); 20 | } 21 | }); 22 | }, 23 | 24 | getSeller(req:express.Request, res:express.Response){ 25 | sellingModel.find({},(err,data) => { 26 | console.log('controller err',err) 27 | console.log('controller data',data) 28 | if(err){ 29 | res.send({'success': false , 'data': null, 'error': err}) 30 | } 31 | else{ 32 | res.send({'success': true,'data': data, 'error': err }) 33 | } 34 | }) 35 | 36 | }, 37 | 38 | }; 39 | 40 | //export controller object 41 | export = Controller; 42 | -------------------------------------------------------------------------------- /server/build/inventry/inventryModel.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var mongoose = require('mongoose'); //import mongodb 3 | //////////////////// Mongoose //////////////////////// 4 | //Creating Schema for User in MongoDB 5 | var userSchema = new mongoose.Schema({ 6 | categoryName: String, 7 | productName: String, 8 | rate: String, 9 | userName: String, 10 | unit: String 11 | }); 12 | exports.InventryModel = mongoose.model("Inventry", userSchema); //Create Collection with the name of Users (in db it shows Todos) 13 | //user class 14 | var User = (function () { 15 | //constructor 16 | function User(user) { 17 | if (user) { 18 | this.categoryName = user.categoryName; 19 | this.productName = user.productName; 20 | this.rate = user.rate; 21 | this.userName = user.userName; 22 | this.unit = user.unit; 23 | } 24 | } 25 | //create user 26 | User.prototype.create = function (user, cb) { 27 | var Obj = new exports.InventryModel(user); 28 | console.log("Checking DATA", Obj); 29 | Obj.save(function (error, data) { 30 | if (error) { 31 | cb(error, null); 32 | } 33 | cb(null, data); 34 | }); 35 | }; 36 | ; 37 | return User; 38 | }()); 39 | exports.User = User; 40 | -------------------------------------------------------------------------------- /server/src/category/categoryController.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import express = require("express"); 3 | import {User, IUser,categoryModel} from "./categoryModel"; //import Member Class 4 | 5 | 6 | let user = new User(); 7 | 8 | //Object 9 | let Controller = { 10 | 11 | CategorySave_post: (req: express.Request, res: express.Response) => { 12 | console.log(req.body,"ccccccccccccccccccccccccccc") 13 | var categoryObj: IUser = req.body; 14 | user.create(categoryObj, (err, data) => { 15 | if (err) { 16 | res.json({ 'success': false, 'data': null, 'error': err }); 17 | } else { 18 | res.json({ 'success': true, 'data': data, 'error': null }); 19 | } 20 | }); 21 | }, 22 | 23 | getAllUsers(req:express.Request, res:express.Response){ 24 | categoryModel.find({},(err,data) => { 25 | console.log('controller err',err) 26 | console.log('controller data',data) 27 | if(err){ 28 | res.send({'success': false , 'data': null, 'error': err}) 29 | } 30 | else{ 31 | res.send({'success': true,'data': data, 'error': err }) 32 | } 33 | }) 34 | 35 | }, 36 | 37 | }; 38 | 39 | //export controller object 40 | export = Controller; 41 | -------------------------------------------------------------------------------- /server/src/inventry/inventryController.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import express = require("express"); 3 | import {User, IUser,InventryModel} from "./InventryModel"; //import Member Class 4 | 5 | 6 | let user = new User(); 7 | 8 | //Object 9 | let Controller = { 10 | 11 | InventrySave_post: (req: express.Request, res: express.Response) => { 12 | console.log(req.body,"iiiiiiiiiiiiiiiiiiiiiiiiiiiiii") 13 | var Obj: IUser = req.body; 14 | 15 | user.create(Obj, (err, data) => { 16 | if (err) { 17 | res.json({ 'success': false, 'data': null, 'error': err }); 18 | } else { 19 | res.json({ 'success': true, 'data': data, 'error': null }); 20 | } 21 | }); 22 | }, 23 | 24 | getInventry(req:express.Request, res:express.Response){ 25 | InventryModel.find({},(err,data) => { 26 | console.log('controller err',err) 27 | console.log('controller data',data) 28 | if(err){ 29 | res.send({'success': false , 'data': null, 'error': err}) 30 | } 31 | else{ 32 | res.send({'success': true,'data': data, 'error': err }) 33 | } 34 | }) 35 | 36 | }, 37 | 38 | }; 39 | 40 | //export controller object 41 | export = Controller; 42 | -------------------------------------------------------------------------------- /server/src/helpers/helper.ts: -------------------------------------------------------------------------------- 1 | import * as _User from './../category/categoryModel'; 2 | 3 | 4 | //create type for callback function 5 | export type CallBackFunction = (error, data) => void; 6 | 7 | //for response of api 8 | export type customServerResponseObject = { 'success': boolean, 'data': any, 'error': any }; 9 | 10 | 11 | 12 | 13 | 14 | 15 | function CreateCategory(cb) { 16 | var u1: _User.IUser = {categoryName: 'MuZz', categoryDec : "Something"}; 17 | var userObj = new _User.User(u1); 18 | 19 | //checking user exists or not 20 | _User.User.isUserExists(userObj.categoryName, (error, result) => { 21 | console.log('user -- exists?', error); 22 | if (!error) { 23 | userObj.create(userObj, (err, data: _User.IUser) => { 24 | if (err) { 25 | console.log('User Create Err'); 26 | console.log(err) 27 | cb(false); 28 | } else { 29 | console.log('User Created'); 30 | console.log(data); 31 | 32 | } 33 | }); //userObj.create 34 | } else { 35 | console.log('User/Member not created...Err!'); 36 | console.log(error); 37 | cb(false); 38 | } 39 | }); //User.isUserExists 40 | } //CreateUserAndMember -------------------------------------------------------------------------------- /client/src/app/components/form/formComponent.ts: -------------------------------------------------------------------------------- 1 | import {Component} from "angular2/core"; 2 | import {FormBuilder, Validators, ControlGroup, Control} from "angular2/common"; 3 | import {UsernameValidator} from "./customValidator"; 4 | 5 | 6 | 7 | 8 | 9 | @Component({ 10 | selector: "form-page", 11 | templateUrl: "./app/components/form/form.html" 12 | }) 13 | export class FormComponent { 14 | 15 | name: Control; 16 | email: Control; 17 | email2: Control; 18 | password: Control; 19 | 20 | loginForm: ControlGroup; 21 | 22 | constructor(private fb: FormBuilder) { 23 | this.email = new Control("", Validators.required); 24 | this.email2 = new Control("", UsernameValidator.emailValidation); 25 | this.name = new Control( "", Validators.compose([Validators.required, UsernameValidator.startsWithNumber]) ); 26 | this.password = new Control( "", Validators.compose([Validators.required, Validators.minLength(4)]) ); 27 | 28 | this.loginForm = this.fb.group({ 29 | "email": this.email, 30 | "email2": this.email2, 31 | "name": this.name, 32 | "password": this.password 33 | }); 34 | } 35 | 36 | doLogin(event) { 37 | if (this.loginForm.dirty && this.loginForm.valid) { 38 | console.log(this.loginForm.value); 39 | event.preventDefault(); 40 | } 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /client/src/app/components/selling/selling.html: -------------------------------------------------------------------------------- 1 |

Selling

2 | 3 |
4 | 5 |
6 | 10 | 11 | 15 | 16 | 17 | 18 |
19 | 20 | 21 |
22 |
23 | 24 | 25 |
26 |
27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 |
35 |

Storing Data

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
ProductsUnit
{{get.productName}}{{get.unit}}
50 |
-------------------------------------------------------------------------------- /client/build/app/components/selling/selling.html: -------------------------------------------------------------------------------- 1 |

Selling

2 | 3 |
4 | 5 |
6 | 10 | 11 | 15 | 16 | 17 | 18 |
19 | 20 | 21 |
22 |
23 | 24 | 25 |
26 |
27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 |
35 |

Storing Data

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
ProductsUnit
{{get.productName}}{{get.unit}}
50 |
-------------------------------------------------------------------------------- /client/build/app/components/form/customValidator.js: -------------------------------------------------------------------------------- 1 | System.register([], function(exports_1, context_1) { 2 | "use strict"; 3 | var __moduleName = context_1 && context_1.id; 4 | var UsernameValidator; 5 | return { 6 | setters:[], 7 | execute: function() { 8 | UsernameValidator = (function () { 9 | function UsernameValidator() { 10 | } 11 | UsernameValidator.startsWithNumber = function (control) { 12 | if (control.value !== "" && !isNaN(control.value.charAt(0))) { 13 | return { "startsWithNumber": true }; 14 | } 15 | return null; 16 | }; 17 | UsernameValidator.emailValidation = function (control) { 18 | var pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/; 19 | if (control.value !== "" && !control.value.match(pattern)) { 20 | return { "emailValidation": true }; 21 | } 22 | return null; 23 | }; 24 | return UsernameValidator; 25 | }()); 26 | exports_1("UsernameValidator", UsernameValidator); 27 | } 28 | } 29 | }); 30 | // One weird thing you might notice is that returning null actually means the validation is valid. 31 | // If we find a number at the first position of the string we return the validation error { “startsWithNumber”: true } 32 | -------------------------------------------------------------------------------- /client/build/app/components/product/product.html: -------------------------------------------------------------------------------- 1 |

Product

2 | 3 | 4 | 5 | 6 | 7 | 17 | 18 | 22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
Category: {{get.categoryName}} Name: {{get.productName}} Dec: {{get.productDec}}Unit : {{get.unit}}
45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /client/src/app/components/product/product.html: -------------------------------------------------------------------------------- 1 |

Product

2 | 3 | 4 | 5 | 6 | 7 | 17 | 18 | 22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
Category: {{get.categoryName}} Name: {{get.productName}} Dec: {{get.productDec}}Unit : {{get.unit}}
45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /client/src/app/components/socket/socketService.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from 'angular2/core'; 2 | 3 | declare var io: any; 4 | 5 | @Injectable() 6 | export class SocketService { 7 | 8 | socket: any; 9 | host: string; 10 | fruits: [string] = ['Pineapple']; 11 | 12 | constructor () { 13 | 14 | this.host = window.location.origin; 15 | console.log("WEBSOCKET connecting to", this.host); 16 | 17 | this.socket = io(); 18 | 19 | //getting all last record from server if restored or default array 20 | this.get(); 21 | 22 | //listing if add fruit on server then server emits the fruit name 23 | this.socket.on("addedFruit", (data) => { 24 | this.fruits.push(data); 25 | console.log('addedFruit this.fruits', this.fruits); 26 | }); 27 | } 28 | 29 | 30 | add(fruitName): void { 31 | this.socket.emit('addFruit', fruitName); 32 | } 33 | 34 | getAllFruits() { 35 | return this.fruits; 36 | } 37 | 38 | get(): void { 39 | 40 | //catching from sever when it emits (all fruits).. 41 | this.socket.on('getAllFruits', (data)=>{ 42 | ///this.fruits = data; 43 | console.log('getAllFruits: ', data); 44 | }); 45 | 46 | //sending request to fire all fruits from server and catching from server events (getAllFruits) 47 | this.socket.emit('getFruits', null); 48 | } 49 | 50 | 51 | } 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | // let host = window.location.origin; 60 | // console.log("WEBSOCKET connecting to", host); -------------------------------------------------------------------------------- /client/build/app/boot.js: -------------------------------------------------------------------------------- 1 | System.register(["angular2/core", "angular2/platform/browser", "angular2/http", "angular2/router", "angular2/common", "./components/socket/socketService", "./components/app/appComponent"], function(exports_1, context_1) { 2 | "use strict"; 3 | var __moduleName = context_1 && context_1.id; 4 | var core_1, browser_1, http_1, router_1, common_1, socketService_1, appComponent_1; 5 | return { 6 | setters:[ 7 | function (core_1_1) { 8 | core_1 = core_1_1; 9 | }, 10 | function (browser_1_1) { 11 | browser_1 = browser_1_1; 12 | }, 13 | function (http_1_1) { 14 | http_1 = http_1_1; 15 | }, 16 | function (router_1_1) { 17 | router_1 = router_1_1; 18 | }, 19 | function (common_1_1) { 20 | common_1 = common_1_1; 21 | }, 22 | function (socketService_1_1) { 23 | socketService_1 = socketService_1_1; 24 | }, 25 | function (appComponent_1_1) { 26 | appComponent_1 = appComponent_1_1; 27 | }], 28 | execute: function() { 29 | // Bootstraping 30 | browser_1.bootstrap(appComponent_1.AppComponent, [ 31 | router_1.ROUTER_PROVIDERS, 32 | http_1.HTTP_PROVIDERS, 33 | common_1.FORM_PROVIDERS, 34 | socketService_1.SocketService, 35 | core_1.provide(router_1.LocationStrategy, { useClass: router_1.HashLocationStrategy }) // angular hashing urls 36 | ]); 37 | } 38 | } 39 | }); 40 | -------------------------------------------------------------------------------- /client/src/app/components/app/appComponent.ts: -------------------------------------------------------------------------------- 1 | import { Component } from "angular2/core"; 2 | import { ROUTER_DIRECTIVES, RouteConfig} from "angular2/router"; 3 | 4 | // import { Menu } from "./../menu/menu"; 5 | import { HomeComponent } from "./../home/homeComponent"; 6 | import { ProductComponent } from "./../product/productComponent"; 7 | import { RateComponent } from "./../rate/rateComponent"; 8 | import { inventryComponent } from "./../inventry/inventryComponent"; 9 | import { CategoryComponent } from "./../category/categoryComponent"; 10 | import { ApiComponent } from "./../testApi/apiComponent"; 11 | import { SocketComponent } from "./../socket/socketComponent"; 12 | import { FormComponent } from "./../form/formComponent"; 13 | import {SellingComponent} from "./../selling/sellingComponent" 14 | 15 | @Component({ 16 | selector: "start-app", 17 | templateUrl: "./app/components/app/app.html", 18 | directives: [ROUTER_DIRECTIVES] 19 | }) 20 | @RouteConfig([ 21 | // { path : "/", redirectTo : ["Home"] }, 22 | { path: "/home", name: "Home", component: HomeComponent, useAsDefault: true }, 23 | { path: "/category", name: "Category", component: CategoryComponent }, 24 | { path: "/product", name: "Product", component: ProductComponent }, 25 | { path: "/rate", name: "Rate", component: RateComponent }, 26 | { path: "/inventry", name: "Inventry", component: inventryComponent }, 27 | {path : "/seller" , name : "Seller", component: SellingComponent}, 28 | { path: "/form", name: "Form", component: FormComponent }, 29 | { path: "/testApi", name: "TestApi", component: ApiComponent }, 30 | { path: "/scoket", name: "Socket", component: SocketComponent } 31 | ]) 32 | export class AppComponent { 33 | 34 | constructor() { 35 | 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /client/src/app/components/product/productComponent.ts: -------------------------------------------------------------------------------- 1 | import { Component } from "angular2/core" ; 2 | import { Http, Response, RequestOptions, Headers } from 'angular2/http'; //for http request (rest API) 3 | 4 | 5 | @Component({ 6 | selector : 'about', 7 | templateUrl : "./app/components/product/product.html" 8 | }) 9 | export class ProductComponent{ 10 | product : {} 11 | getProduct; 12 | getCategory; 13 | constructor(public http: Http) { 14 | this.product = { 15 | productName : "", 16 | priductDec: "", 17 | categoryName : "", 18 | unit : "" 19 | } 20 | 21 | this.http.get('/api/getProducts') /// get Products... 22 | .subscribe((res: Response) => { 23 | this.getProduct = res.json().data 24 | console.log(res.json().data) 25 | }) 26 | 27 | 28 | 29 | this.http.get('/api/getCategory') /// GEt Category.. 30 | .subscribe((res: Response) => { 31 | this.getCategory = res.json().data 32 | console.log(res.json().data) 33 | }) 34 | } 35 | 36 | 37 | send(product): void { 38 | console.log(product) 39 | let headers: Headers = new Headers(); 40 | headers.append('Content-Type', 'application/json'); 41 | let options: RequestOptions = new RequestOptions(); 42 | options.headers = headers; 43 | 44 | this.http.post('/api/Category' ,JSON.stringify(this.product), options) 45 | 46 | .subscribe((res: Response) => { 47 | console.log("Craete Products: ",res) 48 | 49 | }); 50 | 51 | ; //http.post 52 | 53 | } 54 | // } 55 | } -------------------------------------------------------------------------------- /server/src/selling/sellingModel.ts: -------------------------------------------------------------------------------- 1 | import mongoose = require('mongoose'); //import mongodb 2 | import * as helper from './../helpers/helper'; 3 | //import q = require('q'); 4 | //if using promise pattren 5 | 6 | //interface of user 7 | export interface IUser { 8 | productName: string; 9 | unit: string 10 | } 11 | 12 | 13 | 14 | 15 | //////////////////// Mongoose //////////////////////// 16 | //Creating Schema for User in MongoDB 17 | let userSchema = new mongoose.Schema({ //Create Schema for User Collection 18 | productName: String, 19 | unit: String 20 | }); 21 | 22 | export const sellingModel = mongoose.model("Selling", userSchema); //Create Collection with the name of Users (in db it shows Todos) 23 | 24 | 25 | 26 | //user class 27 | export class User implements IUser { 28 | productName: string; 29 | unit: string 30 | 31 | //constructor 32 | // constructor(user?: IUser) { 33 | // if (user) { 34 | // this.categoryName = user.categoryName 35 | // this.productName = user.productName 36 | // this.rate = user.rate 37 | // this.userName = user.userName 38 | // this.unit = user.unit 39 | // } 40 | // } 41 | 42 | 43 | 44 | //create user 45 | create(user: IUser, cb: helper.CallBackFunction): void { 46 | let Obj = new sellingModel(user); 47 | 48 | Obj.save((error, data: IUser) => { 49 | if (error) { 50 | cb(error, null); 51 | } 52 | cb(null, data); 53 | }); 54 | 55 | 56 | }; // create user 57 | 58 | 59 | 60 | 61 | // getInventry(req,res){ 62 | // InventryModel.find({}, (err,data) => { 63 | // if (err) { 64 | // //if error on finding user 65 | // res.send("Error") 66 | // } else { 67 | // res.send(data) 68 | // } 69 | 70 | // }); 71 | // }; 72 | } -------------------------------------------------------------------------------- /client/build/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Angular2 - Task Management 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 35 | 36 | 37 | 38 | 39 | Loading....... 40 | 41 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /client/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Angular2 - Task Management 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 35 | 36 | 37 | 38 | 39 | Loading....... 40 | 41 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /client/build/app/components/inventry/inventry.html: -------------------------------------------------------------------------------- 1 |

Inventry

2 | 3 | 4 |
5 |
6 | 7 |
11 |
12 |
16 |
17 |
21 |
22 | 26 |
27 | 28 | 29 |
30 |
31 | 32 | 33 |
34 |
35 | 36 | 37 |
38 | 39 | 40 | 41 | 42 | 43 |
44 |

Inventry Data

45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 |
User NameCategoreisProductsRateUnit
{{get.userName}}{{get.categoryName}}{{get.productName}}{{get.rate}}{{get.unit}}
65 |
-------------------------------------------------------------------------------- /client/src/app/components/inventry/inventry.html: -------------------------------------------------------------------------------- 1 |

Inventry

2 | 3 | 4 |
5 |
6 | 7 |
11 |
12 |
16 |
17 |
21 |
22 | 26 |
27 | 28 | 29 |
30 |
31 | 32 | 33 |
34 |
35 | 36 | 37 |
38 | 39 | 40 | 41 | 42 | 43 |
44 |

Inventry Data

45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 |
User NameCategoreisProductsRateUnit
{{get.userName}}{{get.categoryName}}{{get.productName}}{{get.rate}}{{get.unit}}
65 |
-------------------------------------------------------------------------------- /server/src/inventry/inventryModel.ts: -------------------------------------------------------------------------------- 1 | import mongoose = require('mongoose'); //import mongodb 2 | import * as helper from './../helpers/helper'; 3 | //import q = require('q'); 4 | //if using promise pattren 5 | 6 | //interface of user 7 | export interface IUser { 8 | categoryName: string; 9 | productName: string; 10 | rate: string; 11 | userName: string; 12 | unit: string 13 | } 14 | 15 | 16 | 17 | 18 | //////////////////// Mongoose //////////////////////// 19 | //Creating Schema for User in MongoDB 20 | let userSchema = new mongoose.Schema({ //Create Schema for User Collection 21 | categoryName: String, 22 | productName: String, 23 | rate: String, 24 | userName: String ; 25 | unit: String 26 | }); 27 | 28 | export const InventryModel = mongoose.model("Inventry", userSchema); //Create Collection with the name of Users (in db it shows Todos) 29 | 30 | 31 | 32 | //user class 33 | export class User implements IUser { 34 | categoryName: string; 35 | productName: string; 36 | rate: string; 37 | userName: string; 38 | unit: string 39 | 40 | //constructor 41 | constructor(user?: IUser) { 42 | if (user) { 43 | this.categoryName = user.categoryName 44 | this.productName = user.productName 45 | this.rate = user.rate 46 | this.userName = user.userName 47 | this.unit = user.unit 48 | } 49 | } 50 | 51 | 52 | 53 | //create user 54 | create(user: IUser, cb: helper.CallBackFunction): void { 55 | let Obj = new InventryModel(user); 56 | console.log("Checking DATA", Obj) 57 | 58 | Obj.save((error, data: IUser) => { 59 | if (error) { 60 | cb(error, null); 61 | } 62 | cb(null, data); 63 | }); 64 | 65 | 66 | }; // create user 67 | 68 | 69 | 70 | 71 | // getInventry(req,res){ 72 | // InventryModel.find({}, (err,data) => { 73 | // if (err) { 74 | // //if error on finding user 75 | // res.send("Error") 76 | // } else { 77 | // res.send(data) 78 | // } 79 | 80 | // }); 81 | // }; 82 | } -------------------------------------------------------------------------------- /client/src/app/components/inventry/inventryComponent.ts: -------------------------------------------------------------------------------- 1 | import { Component } from "angular2/core" ; 2 | import { Http, Response, RequestOptions, Headers } from 'angular2/http'; //for http request (rest API) 3 | 4 | @Component({ 5 | selector : 'home', 6 | templateUrl : "./app/components/inventry/inventry.html" 7 | }) 8 | export class inventryComponent{ 9 | add : {} 10 | getCategory 11 | getProducts; 12 | getUsers; 13 | getRates ; 14 | getInventry 15 | constructor(public http: Http) { 16 | this.add = { 17 | categoryName: "", 18 | productName : "", 19 | userName: "", 20 | rate : "", 21 | unit : "" 22 | } 23 | 24 | this.http.get('/api/getCategory') 25 | .subscribe((res: Response) => { 26 | this.getCategory = res.json().data 27 | }) 28 | 29 | this.http.get('/api/getProducts') 30 | .subscribe((res: Response) => { 31 | this.getProducts = res.json().data 32 | }) 33 | 34 | this.http.get('/api/user/getUser') 35 | .subscribe((res: Response) => { 36 | this.getUsers = res.json().data 37 | }) 38 | 39 | this.http.get('/api/rate/getRate') 40 | .subscribe((res: Response) => { 41 | this.getRates = res.json().data 42 | }) 43 | 44 | this.http.get('/api/inven/getInventry') 45 | .subscribe((res: Response) => { 46 | this.getInventry = res.json().data 47 | console.log(res.json().data) 48 | }) 49 | } 50 | 51 | 52 | 53 | send(add): void { 54 | console.log(add) 55 | let headers: Headers = new Headers(); 56 | headers.append('Content-Type', 'application/json'); 57 | let options: RequestOptions = new RequestOptions(); 58 | options.headers = headers; 59 | 60 | this.http.post('/api/inven/Inventry' ,JSON.stringify(add), options) 61 | 62 | .subscribe((res: Response) => { 63 | console.log("Craete Inventry: ",res) 64 | 65 | }); 66 | 67 | ; //http.post 68 | 69 | } 70 | 71 | 72 | 73 | 74 | } -------------------------------------------------------------------------------- /server/build/rate/rateModel.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var mongoose = require('mongoose'); //import mongodb 3 | //////////////////// Mongoose //////////////////////// 4 | //Creating Schema for User in MongoDB 5 | var userSchema = new mongoose.Schema({ 6 | rates: String, 7 | rateDec: String 8 | }); 9 | exports.RateModel = mongoose.model("Rate", userSchema); //Create Collection with the name of Users (in db it shows Todos) 10 | //user class 11 | var User = (function () { 12 | //constructor 13 | function User(user) { 14 | if (user) { 15 | this.rates = user.rates; 16 | this.rateDec = user.rateDec; 17 | } 18 | } 19 | //is user exists checking 20 | User.isUserExists = function (_name, cb) { 21 | exports.RateModel.findOne({ rates: _name }, function (err, user) { 22 | if (err) { 23 | cb(true, null); // err true 24 | } 25 | if (user && user.rates) { 26 | cb(true, null); //err true if user exists 27 | } 28 | else { 29 | cb(false, null); //err false if user not exixts 30 | } 31 | }); 32 | }; 33 | ; 34 | //create user 35 | User.prototype.create = function (user, cb) { 36 | User.isUserExists(user.rates, function (err, data) { 37 | if (err) { 38 | cb(err, null); 39 | } 40 | else { 41 | // delete user._id; 42 | var Obj = new exports.RateModel(user); 43 | Obj.save(function (error, data) { 44 | if (error) { 45 | cb(err, null); 46 | } 47 | cb(null, data); 48 | }); 49 | } 50 | }); //User.isUserExists 51 | }; 52 | ; 53 | User.prototype.getRates = function (req, res) { 54 | exports.RateModel.find({}, function (err, data) { 55 | console.log('Model Errrrrrrrrrrr', err); 56 | console.log('Model Dataaaaaaaaaaaaaaaaa', data); 57 | if (err) { 58 | //if error on finding user 59 | res.send("Error"); 60 | } 61 | else { 62 | res.send(data); 63 | } 64 | }); 65 | }; 66 | ; 67 | return User; 68 | }()); 69 | exports.User = User; 70 | -------------------------------------------------------------------------------- /client/src/app/components/form/form.html: -------------------------------------------------------------------------------- 1 |

Form Sample

2 | 3 |


4 | 5 | Form is invalid (you can not submit your form) 6 | Form is valid (now you can submit your form) 7 | 8 |


9 | 10 |
11 |
12 | 13 |
14 | * 15 |
16 |
17 |
18 | 19 |
20 | (optional) - (custom email validation) 21 |
22 |
23 |

Not a valid email address

24 |
25 |
26 |
27 | 28 |
29 | * name should be start with alphabet (custom validation) 30 |
31 |
32 |

Your name can't start with a number

33 |
34 |
35 |
36 | 37 |
38 | * 39 |
40 |
41 |

Your password needs to be at least 4 characters.

42 |
43 |
44 | 45 |
46 | 47 | -------------------------------------------------------------------------------- /client/build/app/components/form/form.html: -------------------------------------------------------------------------------- 1 |

Form Sample

2 | 3 |


4 | 5 | Form is invalid (you can not submit your form) 6 | Form is valid (now you can submit your form) 7 | 8 |


9 | 10 |
11 |
12 | 13 |
14 | * 15 |
16 |
17 |
18 | 19 |
20 | (optional) - (custom email validation) 21 |
22 |
23 |

Not a valid email address

24 |
25 |
26 |
27 | 28 |
29 | * name should be start with alphabet (custom validation) 30 |
31 |
32 |

Your name can't start with a number

33 |
34 |
35 |
36 | 37 |
38 | * 39 |
40 |
41 |

Your password needs to be at least 4 characters.

42 |
43 |
44 | 45 |
46 | 47 | -------------------------------------------------------------------------------- /client/build/app/components/socket/socketComponent.js: -------------------------------------------------------------------------------- 1 | System.register(["angular2/core", "./socketService"], function(exports_1, context_1) { 2 | "use strict"; 3 | var __moduleName = context_1 && context_1.id; 4 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 5 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 6 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 7 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 8 | return c > 3 && r && Object.defineProperty(target, key, r), r; 9 | }; 10 | var __metadata = (this && this.__metadata) || function (k, v) { 11 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 12 | }; 13 | var core_1, socketService_1; 14 | var SocketComponent; 15 | return { 16 | setters:[ 17 | function (core_1_1) { 18 | core_1 = core_1_1; 19 | }, 20 | function (socketService_1_1) { 21 | socketService_1 = socketService_1_1; 22 | }], 23 | execute: function() { 24 | SocketComponent = (function () { 25 | // constructor 26 | function SocketComponent(io) { 27 | this.io = io; 28 | this.fruitz = this.io.getAllFruits(); 29 | } 30 | SocketComponent.prototype.add = function (name) { 31 | if (name.trim().length > 2) { 32 | this.io.add(name); 33 | } 34 | }; 35 | SocketComponent = __decorate([ 36 | core_1.Component({ 37 | selector: "socket", 38 | templateUrl: "./app/components/socket/socket.html" 39 | }), 40 | __metadata('design:paramtypes', [socketService_1.SocketService]) 41 | ], SocketComponent); 42 | return SocketComponent; 43 | }()); 44 | exports_1("SocketComponent", SocketComponent); 45 | } 46 | } 47 | }); 48 | -------------------------------------------------------------------------------- /server/build/user/userModel.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var mongoose = require('mongoose'); //import mongodb 3 | //////////////////// Mongoose //////////////////////// 4 | //Creating Schema for User in MongoDB 5 | var userSchema = new mongoose.Schema({ 6 | fName: String, 7 | lName: String, 8 | type: String 9 | }); 10 | exports.userModel = mongoose.model("User", userSchema); //Create Collection with the name of Users (in db it shows Todos) 11 | //user class 12 | var User = (function () { 13 | //constructor 14 | function User(user) { 15 | if (user) { 16 | this.fName = user.fName; 17 | this.lName = user.lName; 18 | this.type = user.type; 19 | } 20 | } 21 | //is user exists checking 22 | User.isUserExists = function (_name, cb) { 23 | exports.userModel.findOne({ fName: _name }, function (err, user) { 24 | if (err) { 25 | cb(true, null); // err true 26 | } 27 | if (user && user.fName) { 28 | cb(true, null); //err true if user exists 29 | } 30 | else { 31 | cb(false, null); //err false if user not exixts 32 | } 33 | }); 34 | }; 35 | ; 36 | //create user 37 | User.prototype.create = function (user, cb) { 38 | User.isUserExists(user.fName, function (err, data) { 39 | if (err) { 40 | cb(err, null); 41 | } 42 | else { 43 | // delete user._id; 44 | var Obj = new exports.userModel(user); 45 | Obj.save(function (error, data) { 46 | if (error) { 47 | cb(err, null); 48 | } 49 | cb(null, data); 50 | }); 51 | } 52 | }); //User.isUserExists 53 | }; 54 | ; 55 | User.prototype.getAllUser = function (req, res) { 56 | exports.userModel.find({}, function (err, data) { 57 | console.log('Model Errrrrrrrrrrr', err); 58 | console.log('Model Dataaaaaaaaaaaaaaaaa', data); 59 | if (err) { 60 | //if error on finding user 61 | res.send("Error"); 62 | } 63 | else { 64 | res.send(data); 65 | } 66 | }); 67 | }; 68 | ; 69 | return User; 70 | }()); 71 | exports.User = User; 72 | -------------------------------------------------------------------------------- /server/build/category/categoryModel.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var mongoose = require('mongoose'); //import mongodb 3 | //////////////////// Mongoose //////////////////////// 4 | //Creating Schema for User in MongoDB 5 | var userSchema = new mongoose.Schema({ 6 | categoryName: String, 7 | categoryDec: [] 8 | }); 9 | exports.categoryModel = mongoose.model("Categorie", userSchema); //Create Collection with the name of Users (in db it shows Todos) 10 | //user class 11 | var User = (function () { 12 | //constructor 13 | function User(user) { 14 | if (user) { 15 | this.categoryName = user.categoryName; 16 | this.categoryDec = user.categoryDec; 17 | } 18 | } 19 | //is user exists checking 20 | User.isUserExists = function (_name, cb) { 21 | exports.categoryModel.findOne({ categoryName: _name }, function (err, user) { 22 | if (err) { 23 | cb(true, null); // err true 24 | } 25 | if (user && user.categoryName) { 26 | cb(true, null); //err true if user exists 27 | } 28 | else { 29 | cb(false, null); //err false if user not exixts 30 | } 31 | }); 32 | }; 33 | ; 34 | //create user 35 | User.prototype.create = function (user, cb) { 36 | User.isUserExists(user.categoryName, function (err, data) { 37 | if (err) { 38 | cb(err, null); 39 | } 40 | else { 41 | // delete user._id; 42 | var categoryObj = new exports.categoryModel(user); 43 | categoryObj.save(function (error, data) { 44 | if (error) { 45 | cb(err, null); 46 | } 47 | cb(null, data); 48 | }); 49 | } 50 | }); //User.isUserExists 51 | }; 52 | ; 53 | User.prototype.getAllUser = function (req, res) { 54 | exports.categoryModel.find({}, function (err, data) { 55 | console.log('Model Errrrrrrrrrrr', err); 56 | console.log('Model Dataaaaaaaaaaaaaaaaa', data); 57 | if (err) { 58 | //if error on finding user 59 | res.send("Error"); 60 | } 61 | else { 62 | res.send(data); 63 | } 64 | }); 65 | }; 66 | ; 67 | return User; 68 | }()); 69 | exports.User = User; 70 | -------------------------------------------------------------------------------- /server/build/product/productModel.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var mongoose = require('mongoose'); //import mongodb 3 | //////////////////// Mongoose //////////////////////// 4 | //Creating Schema for User in MongoDB 5 | var userSchema = new mongoose.Schema({ 6 | productName: String, 7 | productDec: String, 8 | categoryName: String, 9 | unit: String 10 | }); 11 | exports.ProductModel = mongoose.model("Product", userSchema); //Create Collection with the name of Users (in db it shows Todos) 12 | //user class 13 | var User = (function () { 14 | //constructor 15 | function User(user) { 16 | if (user) { 17 | this.productName = user.productName; 18 | this.productDec = user.productDec; 19 | } 20 | } 21 | //is user exists checking 22 | User.isUserExists = function (_name, cb) { 23 | exports.ProductModel.findOne({ productName: _name }, function (err, user) { 24 | if (err) { 25 | cb(true, null); // err true 26 | } 27 | if (user && user.productName) { 28 | cb(true, null); //err true if user exists 29 | } 30 | else { 31 | cb(false, null); //err false if user not exixts 32 | } 33 | }); 34 | }; 35 | ; 36 | //create user 37 | User.prototype.create = function (user, cb) { 38 | User.isUserExists(user.productName, function (err, data) { 39 | if (err) { 40 | cb(err, null); 41 | } 42 | else { 43 | // delete user._id; 44 | var Obj = new exports.ProductModel(user); 45 | Obj.save(function (error, data) { 46 | if (error) { 47 | cb(err, null); 48 | } 49 | cb(null, data); 50 | }); 51 | } 52 | }); //User.isUserExists 53 | }; 54 | ; 55 | User.prototype.getAllUser = function (req, res) { 56 | exports.ProductModel.find({}, function (err, data) { 57 | console.log('Model Errrrrrrrrrrr', err); 58 | console.log('Model Dataaaaaaaaaaaaaaaaa', data); 59 | if (err) { 60 | //if error on finding user 61 | res.send("Error"); 62 | } 63 | else { 64 | res.send(data); 65 | } 66 | }); 67 | }; 68 | ; 69 | return User; 70 | }()); 71 | exports.User = User; 72 | -------------------------------------------------------------------------------- /client/build/app/components/testApi/apiComponent.js: -------------------------------------------------------------------------------- 1 | System.register(["angular2/core", 'angular2/http'], function(exports_1, context_1) { 2 | "use strict"; 3 | var __moduleName = context_1 && context_1.id; 4 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 5 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 6 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 7 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 8 | return c > 3 && r && Object.defineProperty(target, key, r), r; 9 | }; 10 | var __metadata = (this && this.__metadata) || function (k, v) { 11 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 12 | }; 13 | var core_1, http_1; 14 | var ApiComponent; 15 | return { 16 | setters:[ 17 | function (core_1_1) { 18 | core_1 = core_1_1; 19 | }, 20 | function (http_1_1) { 21 | http_1 = http_1_1; 22 | }], 23 | execute: function() { 24 | ApiComponent = (function () { 25 | function ApiComponent(http) { 26 | //constructor 27 | this.http = http; 28 | //calling test api (testing) 29 | this.testApi(); 30 | } 31 | ApiComponent.prototype.testApi = function () { 32 | var _this = this; 33 | this.http.request('http://localhost:4000/api/test') 34 | .subscribe(function (res) { 35 | _this.receivedFromServer = res.json(); 36 | }); //http.request 37 | }; 38 | ApiComponent = __decorate([ 39 | //for http request (rest API) 40 | core_1.Component({ 41 | selector: 'test-api', 42 | template: '

Api

 {{receivedFromServer | json}} 
', 43 | }), 44 | __metadata('design:paramtypes', [http_1.Http]) 45 | ], ApiComponent); 46 | return ApiComponent; 47 | }()); 48 | exports_1("ApiComponent", ApiComponent); 49 | } 50 | } 51 | }); 52 | -------------------------------------------------------------------------------- /client/build/app/components/app/app.html: -------------------------------------------------------------------------------- 1 | 2 | 46 | 47 | 48 |
49 | 50 |
-------------------------------------------------------------------------------- /client/src/app/components/app/app.html: -------------------------------------------------------------------------------- 1 | 2 | 46 | 47 | 48 |
49 | 50 |
-------------------------------------------------------------------------------- /server/build/app.js: -------------------------------------------------------------------------------- 1 | /// 2 | "use strict"; 3 | var express = require("express"); 4 | var http = require("http"); 5 | var path = require("path"); 6 | var bodyParser = require("body-parser"); 7 | var socket = require("socket.io"); 8 | // if use mongoose 9 | var mongoose = require('mongoose'); 10 | mongoose.connect('mongodb://pos:pos@ds011933.mlab.com:11933/point_of_sale'); 11 | var port = process.env.PORT || 4000; 12 | var categoryRoutes = require("./category/categoryRouter"); 13 | var sellingRoutes = require("./selling/sellingRouter"); 14 | var userRoutes = require("./user/userRouter"); 15 | var productRoutes = require("./product/productRouter"); 16 | var InventryRoutes = require("./inventry/inventryRouter"); 17 | var rateRoutes = require("./rate/rateRouter"); 18 | //Server Creation 19 | var app = express(); 20 | var server = http.createServer(app); 21 | var io = socket(server); 22 | server.listen(port, function () { 23 | console.log('listening on http://localhost:' + port); 24 | }); 25 | app.use(bodyParser.json()); 26 | app.use(bodyParser.urlencoded({ extended: false })); 27 | // Middlewaress 28 | app.use('/api/user', userRoutes); 29 | app.use('/api', categoryRoutes); 30 | app.use('/api', productRoutes); 31 | app.use('/api/inven', InventryRoutes); 32 | app.use('/api/rate', rateRoutes); 33 | app.use('/api/sell', sellingRoutes); 34 | // res.header("Access-Control-Allow-Origin", "*"); 35 | // res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); 36 | // res.header('Access-Control-Allow-Headers', 'Content-type,Accept,X-Access-Token,X-Key'); 37 | // logger middle ware 38 | app.use(function (req, res, next) { 39 | console.log("Logging: " + req.method.toString() + ": " + req.url.toString()); 40 | next(); 41 | }); 42 | app.use(express.static(path.join(__dirname, "./../../client/build"))); 43 | // set vairiables in Express 44 | app.set("port", port); 45 | app.set("env", "development"); 46 | app.set("address", "localhost"); 47 | // Handle Routes after some middlewares 48 | app.get("/", function (req, res) { 49 | res.sendFile(path.join(__dirname, "./../../client/build/index.html")); 50 | }); 51 | app.get("/api/test", function (req, res) { 52 | res.json({ success: true, data: "Hello World" }); 53 | }); 54 | // For Socket creating array of Fruits 55 | var fruits = ['Apple', 'Banana']; 56 | io.sockets.on("connection", function (socket) { 57 | socket.emit("message", { message: "you are using socket.io" }); 58 | socket.on('addFruit', function (data) { 59 | io.sockets.emit('addedFruit', data); 60 | //fruits.push(data); 61 | }); 62 | socket.on('getFruits', function () { 63 | io.sockets.emit('getAllFruits', fruits); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /server/src/rate/rateModel.ts: -------------------------------------------------------------------------------- 1 | import mongoose = require('mongoose'); //import mongodb 2 | import * as helper from './../helpers/helper'; 3 | //import q = require('q'); 4 | //if using promise pattren 5 | 6 | //interface of user 7 | export interface IUser { 8 | rates: string; 9 | rateDec : string; 10 | } 11 | 12 | 13 | 14 | 15 | //////////////////// Mongoose //////////////////////// 16 | //Creating Schema for User in MongoDB 17 | let userSchema = new mongoose.Schema({ //Create Schema for User Collection 18 | rates : String, 19 | rateDec : String 20 | }); 21 | 22 | export const RateModel = mongoose.model("Rate", userSchema); //Create Collection with the name of Users (in db it shows Todos) 23 | 24 | 25 | 26 | //user class 27 | export class User implements IUser { 28 | rates: string; 29 | rateDec : string; 30 | 31 | //constructor 32 | constructor(user?: IUser) { 33 | if (user) { 34 | this.rates = user.rates 35 | this.rateDec = user.rateDec 36 | } 37 | } 38 | 39 | //is user exists checking 40 | static isUserExists(_name: string, cb: helper.CallBackFunction): void { 41 | RateModel.findOne({ rates: _name }, function(err, user: IUser) { 42 | if (err) { 43 | cb(true, null) // err true 44 | } 45 | if (user && user.rates) { 46 | cb(true, null) //err true if user exists 47 | } else { 48 | 49 | cb(false, null) //err false if user not exixts 50 | } 51 | }) 52 | }; 53 | 54 | 55 | //create user 56 | create(user: IUser, cb: helper.CallBackFunction): void { 57 | User.isUserExists(user.rates, (err, data) => { 58 | if (err) { 59 | cb(err, null); 60 | } else { 61 | // delete user._id; 62 | let Obj = new RateModel(user); 63 | Obj.save((error, data: IUser) => { 64 | if (error) { 65 | cb(err, null); 66 | } 67 | cb(null, data); 68 | }); 69 | } 70 | }); //User.isUserExists 71 | }; // create user 72 | 73 | 74 | getRates(req,res){ 75 | RateModel.find({}, (err,data) => { 76 | console.log('Model Errrrrrrrrrrr',err); 77 | console.log('Model Dataaaaaaaaaaaaaaaaa',data); 78 | if (err) { 79 | //if error on finding user 80 | res.send("Error") 81 | } else { 82 | res.send(data) 83 | } 84 | 85 | }); 86 | }; 87 | } -------------------------------------------------------------------------------- /server/src/user/userModel.ts: -------------------------------------------------------------------------------- 1 | import mongoose = require('mongoose'); //import mongodb 2 | import * as helper from './../helpers/helper'; 3 | //import q = require('q'); 4 | //if using promise pattren 5 | 6 | //interface of user 7 | export interface IUser { 8 | fName: string; 9 | lName : string; 10 | type : string; 11 | } 12 | 13 | 14 | 15 | 16 | //////////////////// Mongoose //////////////////////// 17 | //Creating Schema for User in MongoDB 18 | let userSchema = new mongoose.Schema({ //Create Schema for User Collection 19 | fName : String, 20 | lName : String, 21 | type : String 22 | }); 23 | 24 | export const userModel = mongoose.model("User", userSchema); //Create Collection with the name of Users (in db it shows Todos) 25 | 26 | 27 | 28 | //user class 29 | export class User implements IUser { 30 | fName: string; 31 | lName : string; 32 | type : string; 33 | 34 | //constructor 35 | constructor(user?: IUser) { 36 | if (user) { 37 | this.fName = user.fName 38 | this.lName = user.lName 39 | this.type = user.type 40 | 41 | } 42 | } 43 | 44 | //is user exists checking 45 | static isUserExists(_name: string, cb: helper.CallBackFunction): void { 46 | userModel.findOne({ fName: _name }, function(err, user: IUser) { 47 | if (err) { 48 | cb(true, null) // err true 49 | } 50 | if (user && user.fName) { 51 | cb(true, null) //err true if user exists 52 | } else { 53 | 54 | cb(false, null) //err false if user not exixts 55 | } 56 | }) 57 | }; 58 | 59 | 60 | //create user 61 | create(user: IUser, cb: helper.CallBackFunction): void { 62 | User.isUserExists(user.fName, (err, data) => { 63 | if (err) { 64 | cb(err, null); 65 | } else { 66 | // delete user._id; 67 | let Obj = new userModel(user); 68 | Obj.save((error, data: IUser) => { 69 | if (error) { 70 | cb(err, null); 71 | } 72 | cb(null, data); 73 | }); 74 | } 75 | }); //User.isUserExists 76 | }; // create user 77 | 78 | 79 | getAllUser(req,res){ 80 | userModel.find({}, (err,data) => { 81 | console.log('Model Errrrrrrrrrrr',err); 82 | console.log('Model Dataaaaaaaaaaaaaaaaa',data); 83 | if (err) { 84 | //if error on finding user 85 | res.send("Error") 86 | } else { 87 | res.send(data) 88 | } 89 | 90 | }); 91 | }; 92 | } -------------------------------------------------------------------------------- /server/src/category/categoryModel.ts: -------------------------------------------------------------------------------- 1 | import mongoose = require('mongoose'); //import mongodb 2 | import * as helper from './../helpers/helper'; 3 | //import q = require('q'); 4 | //if using promise pattren 5 | 6 | //interface of user 7 | export interface IUser { 8 | categoryName: string; 9 | categoryDec : string[]; 10 | } 11 | 12 | 13 | 14 | 15 | //////////////////// Mongoose //////////////////////// 16 | //Creating Schema for User in MongoDB 17 | let userSchema = new mongoose.Schema({ //Create Schema for User Collection 18 | categoryName : String, 19 | categoryDec : [] 20 | }); 21 | 22 | export const categoryModel = mongoose.model("Categorie", userSchema); //Create Collection with the name of Users (in db it shows Todos) 23 | 24 | 25 | 26 | //user class 27 | export class User implements IUser { 28 | categoryName: string; 29 | categoryDec : string[]; 30 | 31 | //constructor 32 | constructor(user?: IUser) { 33 | if (user) { 34 | this.categoryName = user.categoryName 35 | this.categoryDec = user.categoryDec 36 | 37 | } 38 | } 39 | 40 | //is user exists checking 41 | static isUserExists(_name: string, cb: helper.CallBackFunction): void { 42 | categoryModel.findOne({ categoryName: _name }, function(err, user: IUser) { 43 | if (err) { 44 | cb(true, null) // err true 45 | } 46 | if (user && user.categoryName) { 47 | cb(true, null) //err true if user exists 48 | } else { 49 | 50 | cb(false, null) //err false if user not exixts 51 | } 52 | }) 53 | }; 54 | 55 | 56 | //create user 57 | create(user: IUser, cb: helper.CallBackFunction): void { 58 | User.isUserExists(user.categoryName, (err, data) => { 59 | if (err) { 60 | cb(err, null); 61 | } else { 62 | // delete user._id; 63 | let categoryObj = new categoryModel(user); 64 | categoryObj.save((error, data: IUser) => { 65 | if (error) { 66 | cb(err, null); 67 | } 68 | cb(null, data); 69 | }); 70 | } 71 | }); //User.isUserExists 72 | }; // create user 73 | 74 | 75 | getAllUser(req,res){ 76 | categoryModel.find({}, (err,data) => { 77 | console.log('Model Errrrrrrrrrrr',err); 78 | console.log('Model Dataaaaaaaaaaaaaaaaa',data); 79 | if (err) { 80 | //if error on finding user 81 | res.send("Error") 82 | } else { 83 | res.send(data) 84 | } 85 | 86 | }); 87 | }; 88 | } -------------------------------------------------------------------------------- /client/src/app/components/selling/sellingComponent.ts: -------------------------------------------------------------------------------- 1 | import { Component } from "angular2/core"; 2 | import { Http, Response, RequestOptions, Headers } from 'angular2/http'; //for http request (rest API) 3 | 4 | 5 | @Component({ 6 | selector: 'selling', 7 | templateUrl: "./app/components/selling/selling.html" 8 | }) 9 | export class SellingComponent { 10 | sell: {} 11 | getSellings; 12 | getInventry; 13 | selectRate; 14 | 15 | constructor(public http: Http) { 16 | this.sell = { 17 | productName: "", 18 | unit: ""} 19 | 20 | 21 | this.http.get('api/sell/getSellers') /// get Sellers... 22 | .subscribe((res: Response) => { 23 | this.getSellings = res.json().data 24 | console.log(res.json().data) 25 | }) 26 | 27 | this.http.get('/api/inven/getInventry') 28 | .subscribe((res: Response) => { 29 | this.getInventry = res.json().data 30 | }) 31 | 32 | } 33 | 34 | 35 | 36 | 37 | 38 | 39 | onChange(deviceValue) { 40 | this.http.get('/api/inven/getInventry') 41 | .subscribe((res: Response) => { 42 | res.json().data.forEach(data => { 43 | if (data.productName === deviceValue) { 44 | this.selectRate = data.unit 45 | } 46 | else { 47 | console.log("ELSE......") 48 | } 49 | }); 50 | }) 51 | 52 | } 53 | 54 | 55 | send(sell): void { 56 | // console.log(sell.unit) 57 | let headers: Headers = new Headers(); 58 | headers.append('Content-Type', 'application/json'); 59 | let options: RequestOptions = new RequestOptions(); 60 | options.headers = headers; 61 | 62 | let corrent = sell.unit 63 | let total = this.selectRate 64 | let now = total - corrent 65 | 66 | console.log("Corrent ",corrent) 67 | console.log("Total ", total) 68 | console.log( "Now ", now) 69 | 70 | this.http.get('/api/inven/getInventry') 71 | .subscribe((res: Response) => { 72 | res.json().data.forEach(data => { 73 | // console.log("Subscribe ", data.unit) 74 | // if (data.productName === this.m) { 75 | // this.selectRate = data.unit 76 | // console.log("TM", this.selectRate) 77 | // } 78 | // else { 79 | // console.log("ELSE.fdffdffdfdfd.....") 80 | // } 81 | }); 82 | 83 | }) 84 | 85 | // this.http.post('/api/sell/Selling', JSON.stringify(sell), options) 86 | // .subscribe((res: Response) => { 87 | // console.log("Craete Seller: ", res) 88 | // }); 89 | } 90 | } -------------------------------------------------------------------------------- /server/src/product/productModel.ts: -------------------------------------------------------------------------------- 1 | import mongoose = require('mongoose'); //import mongodb 2 | import * as helper from './../helpers/helper'; 3 | //import q = require('q'); 4 | //if using promise pattren 5 | 6 | //interface of user 7 | export interface IUser { 8 | productName: string; 9 | productDec : string; 10 | categoryName : string; 11 | unit : string; 12 | } 13 | 14 | 15 | 16 | 17 | //////////////////// Mongoose //////////////////////// 18 | //Creating Schema for User in MongoDB 19 | let userSchema = new mongoose.Schema({ //Create Schema for User Collection 20 | productName : String, 21 | productDec : String, 22 | categoryName : String, 23 | unit : String; 24 | }); 25 | 26 | export const ProductModel = mongoose.model("Product", userSchema); //Create Collection with the name of Users (in db it shows Todos) 27 | 28 | 29 | 30 | //user class 31 | export class User implements IUser { 32 | productName: string; 33 | productDec : string; 34 | categoryName : string; 35 | unit : string; 36 | 37 | //constructor 38 | constructor(user?: IUser) { 39 | if (user) { 40 | this.productName = user.productName 41 | this.productDec = user.productDec 42 | } 43 | } 44 | 45 | //is user exists checking 46 | static isUserExists(_name: string, cb: helper.CallBackFunction): void { 47 | ProductModel.findOne({ productName: _name }, function(err, user: IUser) { 48 | if (err) { 49 | cb(true, null) // err true 50 | } 51 | if (user && user.productName) { 52 | cb(true, null) //err true if user exists 53 | } else { 54 | 55 | cb(false, null) //err false if user not exixts 56 | } 57 | }) 58 | }; 59 | 60 | 61 | //create user 62 | create(user: IUser, cb: helper.CallBackFunction): void { 63 | User.isUserExists(user.productName, (err, data) => { 64 | if (err) { 65 | cb(err, null); 66 | } else { 67 | // delete user._id; 68 | let Obj = new ProductModel(user); 69 | Obj.save((error, data: IUser) => { 70 | if (error) { 71 | cb(err, null); 72 | } 73 | cb(null, data); 74 | }); 75 | } 76 | }); //User.isUserExists 77 | }; // create user 78 | 79 | 80 | getAllUser(req,res){ 81 | ProductModel.find({}, (err,data) => { 82 | console.log('Model Errrrrrrrrrrr',err); 83 | console.log('Model Dataaaaaaaaaaaaaaaaa',data); 84 | if (err) { 85 | //if error on finding user 86 | res.send("Error") 87 | } else { 88 | res.send(data) 89 | } 90 | 91 | }); 92 | }; 93 | } -------------------------------------------------------------------------------- /server/src/app.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import express = require("express"); 4 | import http = require("http"); 5 | import path = require("path"); 6 | import bodyParser = require("body-parser"); 7 | import socket = require("socket.io"); 8 | import * as helper from './helpers/helper'; 9 | 10 | // if use mongoose 11 | import mongoose = require('mongoose'); 12 | mongoose.connect('mongodb://pos:pos@ds011933.mlab.com:11933/point_of_sale'); 13 | 14 | let port: number = process.env.PORT || 4000; 15 | import categoryRoutes = require("./category/categoryRouter"); 16 | import sellingRoutes = require("./selling/sellingRouter") 17 | import userRoutes = require("./user/userRouter"); 18 | import productRoutes = require("./product/productRouter"); 19 | import InventryRoutes = require("./inventry/inventryRouter"); 20 | import rateRoutes = require("./rate/rateRouter"); 21 | 22 | 23 | 24 | //Server Creation 25 | let app: express.Express = express(); 26 | let server: http.Server = http.createServer(app); 27 | let io: SocketIO.Server = socket(server); 28 | 29 | server.listen(port, () => { 30 | console.log('listening on http://localhost:' + port); 31 | }); 32 | 33 | 34 | 35 | 36 | app.use(bodyParser.json()); 37 | app.use(bodyParser.urlencoded({ extended: false })); 38 | // Middlewaress 39 | app.use('/api/user', userRoutes); 40 | app.use('/api', categoryRoutes); 41 | app.use('/api', productRoutes); 42 | app.use('/api/inven', InventryRoutes); 43 | app.use('/api/rate', rateRoutes); 44 | app.use('/api/sell' , sellingRoutes) 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | // res.header("Access-Control-Allow-Origin", "*"); 53 | // res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); 54 | // res.header('Access-Control-Allow-Headers', 'Content-type,Accept,X-Access-Token,X-Key'); 55 | 56 | // logger middle ware 57 | app.use((req, res, next) => { 58 | console.log("Logging: " + req.method.toString() + ": " + req.url.toString()); 59 | next(); 60 | }); 61 | 62 | app.use(express.static(path.join(__dirname, "./../../client/build"))); 63 | 64 | // set vairiables in Express 65 | app.set("port", port); 66 | app.set("env", "development"); 67 | app.set("address", "localhost"); 68 | 69 | // Handle Routes after some middlewares 70 | app.get("/", (req, res) => { 71 | res.sendFile(path.join(__dirname, "./../../client/build/index.html")); 72 | }); 73 | 74 | app.get("/api/test", (req, res) => { 75 | res.json({ success: true, data: "Hello World" }); 76 | }); 77 | 78 | 79 | // For Socket creating array of Fruits 80 | let fruits = ['Apple', 'Banana']; 81 | 82 | io.sockets.on("connection", function (socket) { 83 | 84 | socket.emit("message", { message: "you are using socket.io" }); 85 | 86 | socket.on('addFruit', (data) => { 87 | io.sockets.emit('addedFruit', data); 88 | //fruits.push(data); 89 | }); 90 | 91 | socket.on('getFruits', () => { 92 | io.sockets.emit('getAllFruits', fruits); 93 | }); 94 | 95 | }); 96 | -------------------------------------------------------------------------------- /client/build/app/components/rate/rateComponent.js: -------------------------------------------------------------------------------- 1 | System.register(["angular2/core", 'angular2/http'], function(exports_1, context_1) { 2 | "use strict"; 3 | var __moduleName = context_1 && context_1.id; 4 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 5 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 6 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 7 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 8 | return c > 3 && r && Object.defineProperty(target, key, r), r; 9 | }; 10 | var __metadata = (this && this.__metadata) || function (k, v) { 11 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 12 | }; 13 | var core_1, http_1; 14 | var RateComponent; 15 | return { 16 | setters:[ 17 | function (core_1_1) { 18 | core_1 = core_1_1; 19 | }, 20 | function (http_1_1) { 21 | http_1 = http_1_1; 22 | }], 23 | execute: function() { 24 | RateComponent = (function () { 25 | function RateComponent(http) { 26 | var _this = this; 27 | this.http = http; 28 | this.rate = { 29 | rates: "", 30 | rateDec: "" 31 | }; 32 | this.http.get('/api/rate/getRate') 33 | .subscribe(function (res) { 34 | _this.getData = res.json().data; 35 | console.log(res.json().data); 36 | }); 37 | } 38 | RateComponent.prototype.send = function (rate) { 39 | var headers = new http_1.Headers(); 40 | headers.append('Content-Type', 'application/json'); 41 | var options = new http_1.RequestOptions(); 42 | options.headers = headers; 43 | this.http.post('/api/rate/Rate', JSON.stringify(rate), options) 44 | .subscribe(function (res) { 45 | console.log(res); 46 | }); 47 | ; //http.post 48 | }; 49 | RateComponent = __decorate([ 50 | //for http request (rest API) 51 | core_1.Component({ 52 | selector: 'home', 53 | templateUrl: "./app/components/rate/rate.html" 54 | }), 55 | __metadata('design:paramtypes', [http_1.Http]) 56 | ], RateComponent); 57 | return RateComponent; 58 | }()); 59 | exports_1("RateComponent", RateComponent); 60 | } 61 | } 62 | }); 63 | -------------------------------------------------------------------------------- /client/build/app/components/home/homeComponent.js: -------------------------------------------------------------------------------- 1 | System.register(["angular2/core", 'angular2/http'], function(exports_1, context_1) { 2 | "use strict"; 3 | var __moduleName = context_1 && context_1.id; 4 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 5 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 6 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 7 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 8 | return c > 3 && r && Object.defineProperty(target, key, r), r; 9 | }; 10 | var __metadata = (this && this.__metadata) || function (k, v) { 11 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 12 | }; 13 | var core_1, http_1; 14 | var HomeComponent; 15 | return { 16 | setters:[ 17 | function (core_1_1) { 18 | core_1 = core_1_1; 19 | }, 20 | function (http_1_1) { 21 | http_1 = http_1_1; 22 | }], 23 | execute: function() { 24 | HomeComponent = (function () { 25 | function HomeComponent(http) { 26 | var _this = this; 27 | this.http = http; 28 | this.user = { 29 | fName: "", 30 | lName: "", 31 | type: "" 32 | }; 33 | this.http.get('/api/user/getUser') 34 | .subscribe(function (res) { 35 | _this.getData = res.json().data; 36 | console.log(res.json().data); 37 | }); 38 | } 39 | HomeComponent.prototype.send = function (user) { 40 | var headers = new http_1.Headers(); 41 | headers.append('Content-Type', 'application/json'); 42 | var options = new http_1.RequestOptions(); 43 | options.headers = headers; 44 | this.http.post('/api/user/User', JSON.stringify(user), options) 45 | .subscribe(function (res) { 46 | console.log("Create User :", res); 47 | }); 48 | ; //http.post 49 | }; 50 | HomeComponent = __decorate([ 51 | //for http request (rest API) 52 | core_1.Component({ 53 | selector: 'home', 54 | templateUrl: "./app/components/home/home.html" 55 | }), 56 | __metadata('design:paramtypes', [http_1.Http]) 57 | ], HomeComponent); 58 | return HomeComponent; 59 | }()); 60 | exports_1("HomeComponent", HomeComponent); 61 | } 62 | } 63 | }); 64 | -------------------------------------------------------------------------------- /client/build/app/components/category/categoryComponent.js: -------------------------------------------------------------------------------- 1 | System.register(["angular2/core", 'angular2/http'], function(exports_1, context_1) { 2 | "use strict"; 3 | var __moduleName = context_1 && context_1.id; 4 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 5 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 6 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 7 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 8 | return c > 3 && r && Object.defineProperty(target, key, r), r; 9 | }; 10 | var __metadata = (this && this.__metadata) || function (k, v) { 11 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 12 | }; 13 | var core_1, http_1; 14 | var CategoryComponent; 15 | return { 16 | setters:[ 17 | function (core_1_1) { 18 | core_1 = core_1_1; 19 | }, 20 | function (http_1_1) { 21 | http_1 = http_1_1; 22 | }], 23 | execute: function() { 24 | CategoryComponent = (function () { 25 | function CategoryComponent(http) { 26 | var _this = this; 27 | this.http = http; 28 | this.user = { 29 | categoryName: "", 30 | categoryDec: "" 31 | }; 32 | this.http.get('/api/getCategory') 33 | .subscribe(function (res) { 34 | _this.getData = res.json().data; 35 | console.log(res.json().data); 36 | }); 37 | } 38 | CategoryComponent.prototype.send = function (user) { 39 | var headers = new http_1.Headers(); 40 | headers.append('Content-Type', 'application/json'); 41 | var options = new http_1.RequestOptions(); 42 | options.headers = headers; 43 | this.http.post('/api/Category', JSON.stringify(user), options) 44 | .subscribe(function (res) { 45 | console.log("Create Category : ", res); 46 | }); 47 | ; //http.post 48 | }; 49 | CategoryComponent = __decorate([ 50 | //for http request (rest API) 51 | core_1.Component({ 52 | selector: 'home', 53 | templateUrl: "./app/components/category/category.html" 54 | }), 55 | __metadata('design:paramtypes', [http_1.Http]) 56 | ], CategoryComponent); 57 | return CategoryComponent; 58 | }()); 59 | exports_1("CategoryComponent", CategoryComponent); 60 | } 61 | } 62 | }); 63 | -------------------------------------------------------------------------------- /client/build/app/components/form/formComponent.js: -------------------------------------------------------------------------------- 1 | System.register(["angular2/core", "angular2/common", "./customValidator"], function(exports_1, context_1) { 2 | "use strict"; 3 | var __moduleName = context_1 && context_1.id; 4 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 5 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 6 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 7 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 8 | return c > 3 && r && Object.defineProperty(target, key, r), r; 9 | }; 10 | var __metadata = (this && this.__metadata) || function (k, v) { 11 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 12 | }; 13 | var core_1, common_1, customValidator_1; 14 | var FormComponent; 15 | return { 16 | setters:[ 17 | function (core_1_1) { 18 | core_1 = core_1_1; 19 | }, 20 | function (common_1_1) { 21 | common_1 = common_1_1; 22 | }, 23 | function (customValidator_1_1) { 24 | customValidator_1 = customValidator_1_1; 25 | }], 26 | execute: function() { 27 | FormComponent = (function () { 28 | function FormComponent(fb) { 29 | this.fb = fb; 30 | this.email = new common_1.Control("", common_1.Validators.required); 31 | this.email2 = new common_1.Control("", customValidator_1.UsernameValidator.emailValidation); 32 | this.name = new common_1.Control("", common_1.Validators.compose([common_1.Validators.required, customValidator_1.UsernameValidator.startsWithNumber])); 33 | this.password = new common_1.Control("", common_1.Validators.compose([common_1.Validators.required, common_1.Validators.minLength(4)])); 34 | this.loginForm = this.fb.group({ 35 | "email": this.email, 36 | "email2": this.email2, 37 | "name": this.name, 38 | "password": this.password 39 | }); 40 | } 41 | FormComponent.prototype.doLogin = function (event) { 42 | if (this.loginForm.dirty && this.loginForm.valid) { 43 | console.log(this.loginForm.value); 44 | event.preventDefault(); 45 | } 46 | }; 47 | FormComponent = __decorate([ 48 | core_1.Component({ 49 | selector: "form-page", 50 | templateUrl: "./app/components/form/form.html" 51 | }), 52 | __metadata('design:paramtypes', [common_1.FormBuilder]) 53 | ], FormComponent); 54 | return FormComponent; 55 | }()); 56 | exports_1("FormComponent", FormComponent); 57 | } 58 | } 59 | }); 60 | -------------------------------------------------------------------------------- /client/build/app/components/socket/socketService.js: -------------------------------------------------------------------------------- 1 | System.register(['angular2/core'], function(exports_1, context_1) { 2 | "use strict"; 3 | var __moduleName = context_1 && context_1.id; 4 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 5 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 6 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 7 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 8 | return c > 3 && r && Object.defineProperty(target, key, r), r; 9 | }; 10 | var __metadata = (this && this.__metadata) || function (k, v) { 11 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 12 | }; 13 | var core_1; 14 | var SocketService; 15 | return { 16 | setters:[ 17 | function (core_1_1) { 18 | core_1 = core_1_1; 19 | }], 20 | execute: function() { 21 | SocketService = (function () { 22 | function SocketService() { 23 | var _this = this; 24 | this.fruits = ['Pineapple']; 25 | this.host = window.location.origin; 26 | console.log("WEBSOCKET connecting to", this.host); 27 | this.socket = io(); 28 | //getting all last record from server if restored or default array 29 | this.get(); 30 | //listing if add fruit on server then server emits the fruit name 31 | this.socket.on("addedFruit", function (data) { 32 | _this.fruits.push(data); 33 | console.log('addedFruit this.fruits', _this.fruits); 34 | }); 35 | } 36 | SocketService.prototype.add = function (fruitName) { 37 | this.socket.emit('addFruit', fruitName); 38 | }; 39 | SocketService.prototype.getAllFruits = function () { 40 | return this.fruits; 41 | }; 42 | SocketService.prototype.get = function () { 43 | //catching from sever when it emits (all fruits).. 44 | this.socket.on('getAllFruits', function (data) { 45 | ///this.fruits = data; 46 | console.log('getAllFruits: ', data); 47 | }); 48 | //sending request to fire all fruits from server and catching from server events (getAllFruits) 49 | this.socket.emit('getFruits', null); 50 | }; 51 | SocketService = __decorate([ 52 | core_1.Injectable(), 53 | __metadata('design:paramtypes', []) 54 | ], SocketService); 55 | return SocketService; 56 | }()); 57 | exports_1("SocketService", SocketService); 58 | } 59 | } 60 | }); 61 | // let host = window.location.origin; 62 | // console.log("WEBSOCKET connecting to", host); 63 | -------------------------------------------------------------------------------- /client/build/app/components/product/productComponent.js: -------------------------------------------------------------------------------- 1 | System.register(["angular2/core", 'angular2/http'], function(exports_1, context_1) { 2 | "use strict"; 3 | var __moduleName = context_1 && context_1.id; 4 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 5 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 6 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 7 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 8 | return c > 3 && r && Object.defineProperty(target, key, r), r; 9 | }; 10 | var __metadata = (this && this.__metadata) || function (k, v) { 11 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 12 | }; 13 | var core_1, http_1; 14 | var ProductComponent; 15 | return { 16 | setters:[ 17 | function (core_1_1) { 18 | core_1 = core_1_1; 19 | }, 20 | function (http_1_1) { 21 | http_1 = http_1_1; 22 | }], 23 | execute: function() { 24 | ProductComponent = (function () { 25 | function ProductComponent(http) { 26 | var _this = this; 27 | this.http = http; 28 | this.product = { 29 | productName: "", 30 | priductDec: "", 31 | categoryName: "", 32 | unit: "" 33 | }; 34 | this.http.get('/api/getProducts') /// get Products... 35 | .subscribe(function (res) { 36 | _this.getProduct = res.json().data; 37 | console.log(res.json().data); 38 | }); 39 | this.http.get('/api/getCategory') /// GEt Category.. 40 | .subscribe(function (res) { 41 | _this.getCategory = res.json().data; 42 | console.log(res.json().data); 43 | }); 44 | } 45 | ProductComponent.prototype.send = function (product) { 46 | console.log(product); 47 | var headers = new http_1.Headers(); 48 | headers.append('Content-Type', 'application/json'); 49 | var options = new http_1.RequestOptions(); 50 | options.headers = headers; 51 | this.http.post('/api/Category', JSON.stringify(this.product), options) 52 | .subscribe(function (res) { 53 | console.log("Craete Products: ", res); 54 | }); 55 | ; //http.post 56 | }; 57 | ProductComponent = __decorate([ 58 | //for http request (rest API) 59 | core_1.Component({ 60 | selector: 'about', 61 | templateUrl: "./app/components/product/product.html" 62 | }), 63 | __metadata('design:paramtypes', [http_1.Http]) 64 | ], ProductComponent); 65 | return ProductComponent; 66 | }()); 67 | exports_1("ProductComponent", ProductComponent); 68 | } 69 | } 70 | }); 71 | -------------------------------------------------------------------------------- /server/typings/serve-static/serve-static.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for serve-static 1.7.1 2 | // Project: https://github.com/expressjs/serve-static 3 | // Definitions by: Uros Smolnik 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | /* =================== USAGE =================== 7 | 8 | import * as serveStatic from "serve-static"; 9 | app.use(serveStatic("public/ftp", {"index": ["default.html", "default.htm"]})) 10 | 11 | =============================================== */ 12 | 13 | /// 14 | /// 15 | 16 | declare module "serve-static" { 17 | import * as express from "express"; 18 | 19 | /** 20 | * Create a new middleware function to serve files from within a given root directory. 21 | * The file to serve will be determined by combining req.url with the provided root directory. 22 | * When a file is not found, instead of sending a 404 response, this module will instead call next() to move on to the next middleware, allowing for stacking and fall-backs. 23 | */ 24 | function serveStatic(root: string, options?: { 25 | /** 26 | * Set how "dotfiles" are treated when encountered. A dotfile is a file or directory that begins with a dot ("."). 27 | * Note this check is done on the path itself without checking if the path actually exists on the disk. 28 | * If root is specified, only the dotfiles above the root are checked (i.e. the root itself can be within a dotfile when when set to "deny"). 29 | * The default value is 'ignore'. 30 | * 'allow' No special treatment for dotfiles 31 | * 'deny' Send a 403 for any request for a dotfile 32 | * 'ignore' Pretend like the dotfile does not exist and call next() 33 | */ 34 | dotfiles?: string; 35 | 36 | /** 37 | * Enable or disable etag generation, defaults to true. 38 | */ 39 | etag?: boolean; 40 | 41 | /** 42 | * Set file extension fallbacks. When set, if a file is not found, the given extensions will be added to the file name and search for. 43 | * The first that exists will be served. Example: ['html', 'htm']. 44 | * The default value is false. 45 | */ 46 | extensions?: string[]; 47 | 48 | /** 49 | * By default this module will send "index.html" files in response to a request on a directory. 50 | * To disable this set false or to supply a new index pass a string or an array in preferred order. 51 | */ 52 | index?: boolean|string|string[]; 53 | 54 | /** 55 | * Enable or disable Last-Modified header, defaults to true. Uses the file system's last modified value. 56 | */ 57 | lastModified?: boolean; 58 | 59 | /** 60 | * Provide a max-age in milliseconds for http caching, defaults to 0. This can also be a string accepted by the ms module. 61 | */ 62 | maxAge?: number|string; 63 | 64 | /** 65 | * Redirect to trailing "/" when the pathname is a dir. Defaults to true. 66 | */ 67 | redirect?: boolean; 68 | 69 | /** 70 | * Function to set custom headers on response. Alterations to the headers need to occur synchronously. 71 | * The function is called as fn(res, path, stat), where the arguments are: 72 | * res the response object 73 | * path the file path that is being sent 74 | * stat the stat object of the file that is being sent 75 | */ 76 | setHeaders?: (res: express.Response, path: string, stat: any) => any; 77 | }): express.Handler; 78 | 79 | import * as m from "mime"; 80 | 81 | module serveStatic { 82 | var mime: typeof m; 83 | } 84 | 85 | export = serveStatic; 86 | } 87 | -------------------------------------------------------------------------------- /client/build/app/components/inventry/inventryComponent.js: -------------------------------------------------------------------------------- 1 | System.register(["angular2/core", 'angular2/http'], function(exports_1, context_1) { 2 | "use strict"; 3 | var __moduleName = context_1 && context_1.id; 4 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 5 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 6 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 7 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 8 | return c > 3 && r && Object.defineProperty(target, key, r), r; 9 | }; 10 | var __metadata = (this && this.__metadata) || function (k, v) { 11 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 12 | }; 13 | var core_1, http_1; 14 | var inventryComponent; 15 | return { 16 | setters:[ 17 | function (core_1_1) { 18 | core_1 = core_1_1; 19 | }, 20 | function (http_1_1) { 21 | http_1 = http_1_1; 22 | }], 23 | execute: function() { 24 | inventryComponent = (function () { 25 | function inventryComponent(http) { 26 | var _this = this; 27 | this.http = http; 28 | this.add = { 29 | categoryName: "", 30 | productName: "", 31 | userName: "", 32 | rate: "", 33 | unit: "" 34 | }; 35 | this.http.get('/api/getCategory') 36 | .subscribe(function (res) { 37 | _this.getCategory = res.json().data; 38 | }); 39 | this.http.get('/api/getProducts') 40 | .subscribe(function (res) { 41 | _this.getProducts = res.json().data; 42 | }); 43 | this.http.get('/api/user/getUser') 44 | .subscribe(function (res) { 45 | _this.getUsers = res.json().data; 46 | }); 47 | this.http.get('/api/rate/getRate') 48 | .subscribe(function (res) { 49 | _this.getRates = res.json().data; 50 | }); 51 | this.http.get('/api/inven/getInventry') 52 | .subscribe(function (res) { 53 | _this.getInventry = res.json().data; 54 | console.log(res.json().data); 55 | }); 56 | } 57 | inventryComponent.prototype.send = function (add) { 58 | console.log(add); 59 | var headers = new http_1.Headers(); 60 | headers.append('Content-Type', 'application/json'); 61 | var options = new http_1.RequestOptions(); 62 | options.headers = headers; 63 | this.http.post('/api/inven/Inventry', JSON.stringify(add), options) 64 | .subscribe(function (res) { 65 | console.log("Craete Inventry: ", res); 66 | }); 67 | ; //http.post 68 | }; 69 | inventryComponent = __decorate([ 70 | //for http request (rest API) 71 | core_1.Component({ 72 | selector: 'home', 73 | templateUrl: "./app/components/inventry/inventry.html" 74 | }), 75 | __metadata('design:paramtypes', [http_1.Http]) 76 | ], inventryComponent); 77 | return inventryComponent; 78 | }()); 79 | exports_1("inventryComponent", inventryComponent); 80 | } 81 | } 82 | }); 83 | -------------------------------------------------------------------------------- /client/build/app/components/app/appComponent.js: -------------------------------------------------------------------------------- 1 | System.register(["angular2/core", "angular2/router", "./../home/homeComponent", "./../product/productComponent", "./../rate/rateComponent", "./../inventry/inventryComponent", "./../category/categoryComponent", "./../testApi/apiComponent", "./../socket/socketComponent", "./../form/formComponent", "./../selling/sellingComponent"], function(exports_1, context_1) { 2 | "use strict"; 3 | var __moduleName = context_1 && context_1.id; 4 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 5 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 6 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 7 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 8 | return c > 3 && r && Object.defineProperty(target, key, r), r; 9 | }; 10 | var __metadata = (this && this.__metadata) || function (k, v) { 11 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 12 | }; 13 | var core_1, router_1, homeComponent_1, productComponent_1, rateComponent_1, inventryComponent_1, categoryComponent_1, apiComponent_1, socketComponent_1, formComponent_1, sellingComponent_1; 14 | var AppComponent; 15 | return { 16 | setters:[ 17 | function (core_1_1) { 18 | core_1 = core_1_1; 19 | }, 20 | function (router_1_1) { 21 | router_1 = router_1_1; 22 | }, 23 | function (homeComponent_1_1) { 24 | homeComponent_1 = homeComponent_1_1; 25 | }, 26 | function (productComponent_1_1) { 27 | productComponent_1 = productComponent_1_1; 28 | }, 29 | function (rateComponent_1_1) { 30 | rateComponent_1 = rateComponent_1_1; 31 | }, 32 | function (inventryComponent_1_1) { 33 | inventryComponent_1 = inventryComponent_1_1; 34 | }, 35 | function (categoryComponent_1_1) { 36 | categoryComponent_1 = categoryComponent_1_1; 37 | }, 38 | function (apiComponent_1_1) { 39 | apiComponent_1 = apiComponent_1_1; 40 | }, 41 | function (socketComponent_1_1) { 42 | socketComponent_1 = socketComponent_1_1; 43 | }, 44 | function (formComponent_1_1) { 45 | formComponent_1 = formComponent_1_1; 46 | }, 47 | function (sellingComponent_1_1) { 48 | sellingComponent_1 = sellingComponent_1_1; 49 | }], 50 | execute: function() { 51 | AppComponent = (function () { 52 | function AppComponent() { 53 | } 54 | AppComponent = __decorate([ 55 | core_1.Component({ 56 | selector: "start-app", 57 | templateUrl: "./app/components/app/app.html", 58 | directives: [router_1.ROUTER_DIRECTIVES] 59 | }), 60 | router_1.RouteConfig([ 61 | // { path : "/", redirectTo : ["Home"] }, 62 | { path: "/home", name: "Home", component: homeComponent_1.HomeComponent, useAsDefault: true }, 63 | { path: "/category", name: "Category", component: categoryComponent_1.CategoryComponent }, 64 | { path: "/product", name: "Product", component: productComponent_1.ProductComponent }, 65 | { path: "/rate", name: "Rate", component: rateComponent_1.RateComponent }, 66 | { path: "/inventry", name: "Inventry", component: inventryComponent_1.inventryComponent }, 67 | { path: "/seller", name: "Seller", component: sellingComponent_1.SellingComponent }, 68 | { path: "/form", name: "Form", component: formComponent_1.FormComponent }, 69 | { path: "/testApi", name: "TestApi", component: apiComponent_1.ApiComponent }, 70 | { path: "/scoket", name: "Socket", component: socketComponent_1.SocketComponent } 71 | ]), 72 | __metadata('design:paramtypes', []) 73 | ], AppComponent); 74 | return AppComponent; 75 | }()); 76 | exports_1("AppComponent", AppComponent); 77 | } 78 | } 79 | }); 80 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | // Improt Modules 2 | var gulp = require('gulp'); 3 | var del = require('del'); 4 | //var watch = require('gulp-watch'); 5 | var sequence = require('gulp-sequence'); 6 | var webserver = require('gulp-webserver'); 7 | var typescript = require('gulp-typescript'); 8 | var gulpNodemon = require('gulp-nodemon'); 9 | 10 | // Define Paths 11 | var path = { 12 | libs: [ 13 | 'node_modules/es6-shim/es6-shim.js', 14 | 'node_modules/angular2/bundles/angular2-polyfills.js', 15 | 'node_modules/systemjs/dist/system.src.js', 16 | 'node_modules/rxjs/bundles/Rx.js', 17 | 'node_modules/angular2/bundles/angular2.dev.js', 18 | 'node_modules/angular2/bundles/http.dev.js', 19 | 'node_modules/angular2/bundles/router.dev.js' 20 | ], 21 | clientts: 'client/src/app/**/*.ts', 22 | html: 'client/src/app/**/*.html', 23 | css: 'client/src/app/**/*.css', 24 | clientassets: ['client/src/app/**/*', '!client/src/app/**/*.ts'], 25 | index: 'client/src/index.html', 26 | clientbuild: 'client/build', 27 | clientbuildapp: 'client/build/app', 28 | clientbuildlib: 'client/build/lib', 29 | serverts: 'server/src/**/*.ts', 30 | serverbuild: 'server/build', 31 | serverjs: 'server/src/**/*.js*', 32 | excludeTyping: '!server/typings/**/*.d.ts', 33 | excludeNodeModules: '!node_modules/**/*.d.ts' 34 | }; 35 | 36 | var serverCompilerOptions = { "target": "ES5", 37 | "module": "commonjs", 38 | "sourceMap": true 39 | }; 40 | 41 | var clientCompilerOptions = { 42 | "target": "ES5", 43 | "module": "system", 44 | "moduleResolution": "node", 45 | "sourceMap": true, 46 | "emitDecoratorMetadata": true, 47 | "experimentalDecorators": true, 48 | "removeComments": false, 49 | "noImplicitAny": false 50 | }; 51 | 52 | 53 | // Clean Server JS 54 | gulp.task('cleanServerJS', function () { 55 | return del(path.serverjs); 56 | }); 57 | 58 | // Clean the Contents of the Distribution Directory 59 | gulp.task('clean', function () { 60 | return del([path.clientbuild, path.serverbuild]); 61 | }); 62 | 63 | // Copy Assets 64 | gulp.task('copy:assets', function () { 65 | return gulp.src(path.clientassets) 66 | .pipe(gulp.dest(path.clientbuildapp)); 67 | }); 68 | 69 | gulp.task('copy:index', function () { 70 | return gulp.src([path.index]) 71 | .pipe(gulp.dest(path.clientbuild)); 72 | }); 73 | 74 | // copy Libs 75 | gulp.task('copy:libs', function () { 76 | return gulp.src(path.libs) 77 | .pipe(gulp.dest(path.clientbuildlib)); 78 | }); 79 | 80 | // copying htmls 81 | gulp.task('copy:html', function () { 82 | return gulp.src(path.html) 83 | .pipe(gulp.dest(path.clientbuildapp)); 84 | }); 85 | 86 | function ServerTranspileTest(tsFilePath) { 87 | return gulp.src(tsFilePath.path) 88 | .pipe(typescript(serverCompilerOptions)) 89 | .pipe(gulp.dest(path.serverbuild)); 90 | } 91 | // TypeScript Server Transpile -- STEP 3 -- 92 | gulp.task('Servertranspile', function () { 93 | return gulp 94 | .src(path.serverts) 95 | .pipe(typescript(serverCompilerOptions)) 96 | .pipe(gulp.dest(path.serverbuild)); 97 | }); 98 | 99 | // TypeScript Client Transpile -- STEP 3 -- 100 | gulp.task('Clienttranspile', function () { 101 | return gulp 102 | .src([path.clientts, '!server/typings/tsd.d.ts', '!node_modules/angular2/typings/node/node.d.ts']) 103 | .pipe(typescript(clientCompilerOptions)) 104 | .pipe(gulp.dest(path.clientbuildapp)); 105 | }); 106 | 107 | // Build Project -- STEP 2 -- 108 | gulp.task('build', sequence('clean', 'copy:assets', 'copy:index', 'copy:libs', 'Clienttranspile', 'Servertranspile', 'cleanServerJS')); 109 | 110 | // Default Task -- STEP 1 -- 111 | gulp.task('default', ['build']); 112 | 113 | // Watch Task 114 | gulp.task('start', sequence('build', 'nodemon', 'watch')); 115 | 116 | // Serve Task 117 | gulp.task('nodemon', function () { 118 | gulpNodemon({ 119 | script: 'server/build/app.js' 120 | }).on('restart', function() { 121 | console.log('GULP: nodemon restarted server.js'); 122 | }); 123 | }); 124 | 125 | gulp.task('watch', function () { 126 | //server ts watching 127 | gulp.watch(path.serverts, ['Servertranspile']); 128 | //client ts watching 129 | gulp.watch(path.clientts, ['Clienttranspile']); 130 | //client html watching 131 | gulp.watch(path.html, ['copy:html']); 132 | //client index.html 133 | gulp.watch(path.index, ['copy:index']); 134 | //client css watching 135 | gulp.watch(path.css, function (file) { 136 | gulp.src(file.path).pipe(gulp.dest(path.clientbuildapp)); 137 | }); 138 | }); 139 | 140 | -------------------------------------------------------------------------------- /client/build/app/components/selling/sellingComponent.js: -------------------------------------------------------------------------------- 1 | System.register(["angular2/core", 'angular2/http'], function(exports_1, context_1) { 2 | "use strict"; 3 | var __moduleName = context_1 && context_1.id; 4 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 5 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 6 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 7 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 8 | return c > 3 && r && Object.defineProperty(target, key, r), r; 9 | }; 10 | var __metadata = (this && this.__metadata) || function (k, v) { 11 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 12 | }; 13 | var core_1, http_1; 14 | var SellingComponent; 15 | return { 16 | setters:[ 17 | function (core_1_1) { 18 | core_1 = core_1_1; 19 | }, 20 | function (http_1_1) { 21 | http_1 = http_1_1; 22 | }], 23 | execute: function() { 24 | SellingComponent = (function () { 25 | function SellingComponent(http) { 26 | var _this = this; 27 | this.http = http; 28 | this.sell = { 29 | productName: "", 30 | unit: "" }; 31 | this.http.get('api/sell/getSellers') /// get Sellers... 32 | .subscribe(function (res) { 33 | _this.getSellings = res.json().data; 34 | console.log(res.json().data); 35 | }); 36 | this.http.get('/api/inven/getInventry') 37 | .subscribe(function (res) { 38 | _this.getInventry = res.json().data; 39 | }); 40 | } 41 | SellingComponent.prototype.onChange = function (deviceValue) { 42 | var _this = this; 43 | this.http.get('/api/inven/getInventry') 44 | .subscribe(function (res) { 45 | res.json().data.forEach(function (data) { 46 | if (data.productName === deviceValue) { 47 | _this.selectRate = data.unit; 48 | } 49 | else { 50 | console.log("ELSE......"); 51 | } 52 | }); 53 | }); 54 | }; 55 | SellingComponent.prototype.send = function (sell) { 56 | // console.log(sell.unit) 57 | var headers = new http_1.Headers(); 58 | headers.append('Content-Type', 'application/json'); 59 | var options = new http_1.RequestOptions(); 60 | options.headers = headers; 61 | var corrent = sell.unit; 62 | var total = this.selectRate; 63 | var now = total - corrent; 64 | console.log("Corrent ", corrent); 65 | console.log("Total ", total); 66 | console.log("Now ", now); 67 | this.http.get('/api/inven/getInventry') 68 | .subscribe(function (res) { 69 | res.json().data.forEach(function (data) { 70 | // console.log("Subscribe ", data.unit) 71 | // if (data.productName === this.m) { 72 | // this.selectRate = data.unit 73 | // console.log("TM", this.selectRate) 74 | // } 75 | // else { 76 | // console.log("ELSE.fdffdffdfdfd.....") 77 | // } 78 | }); 79 | }); 80 | // this.http.post('/api/sell/Selling', JSON.stringify(sell), options) 81 | // .subscribe((res: Response) => { 82 | // console.log("Craete Seller: ", res) 83 | // }); 84 | }; 85 | SellingComponent = __decorate([ 86 | //for http request (rest API) 87 | core_1.Component({ 88 | selector: 'selling', 89 | templateUrl: "./app/components/selling/selling.html" 90 | }), 91 | __metadata('design:paramtypes', [http_1.Http]) 92 | ], SellingComponent); 93 | return SellingComponent; 94 | }()); 95 | exports_1("SellingComponent", SellingComponent); 96 | } 97 | } 98 | }); 99 | -------------------------------------------------------------------------------- /server/typings/body-parser/body-parser.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for body-parser 2 | // Project: http://expressjs.com 3 | // Definitions by: Santi Albo , VILIC VANE , Jonathan Häberle 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | /// 7 | 8 | declare module "body-parser" { 9 | import * as express from "express"; 10 | 11 | /** 12 | * bodyParser: use individual json/urlencoded middlewares 13 | * @deprecated 14 | */ 15 | 16 | function bodyParser(options?: { 17 | /** 18 | * if deflated bodies will be inflated. (default: true) 19 | */ 20 | inflate?: boolean; 21 | /** 22 | * maximum request body size. (default: '100kb') 23 | */ 24 | limit?: any; 25 | /** 26 | * function to verify body content, the parsing can be aborted by throwing an error. 27 | */ 28 | verify?: (req: express.Request, res: express.Response, buf: Buffer, encoding: string) => void; 29 | /** 30 | * only parse objects and arrays. (default: true) 31 | */ 32 | strict?: boolean; 33 | /** 34 | * passed to JSON.parse(). 35 | */ 36 | receiver?: (key: string, value: any) => any; 37 | /** 38 | * parse extended syntax with the qs module. (default: true) 39 | */ 40 | extended?: boolean; 41 | }): express.RequestHandler; 42 | 43 | module bodyParser { 44 | export function json(options?: { 45 | /** 46 | * if deflated bodies will be inflated. (default: true) 47 | */ 48 | inflate?: boolean; 49 | /** 50 | * maximum request body size. (default: '100kb') 51 | */ 52 | limit?: any; 53 | /** 54 | * request content-type to parse, passed directly to the type-is library. (default: 'json') 55 | */ 56 | type?: any; 57 | /** 58 | * function to verify body content, the parsing can be aborted by throwing an error. 59 | */ 60 | verify?: (req: express.Request, res: express.Response, buf: Buffer, encoding: string) => void; 61 | /** 62 | * only parse objects and arrays. (default: true) 63 | */ 64 | strict?: boolean; 65 | /** 66 | * passed to JSON.parse(). 67 | */ 68 | receiver?: (key: string, value: any) => any; 69 | }): express.RequestHandler; 70 | 71 | export function raw(options?: { 72 | /** 73 | * if deflated bodies will be inflated. (default: true) 74 | */ 75 | inflate?: boolean; 76 | /** 77 | * maximum request body size. (default: '100kb') 78 | */ 79 | limit?: any; 80 | /** 81 | * request content-type to parse, passed directly to the type-is library. (default: 'application/octet-stream') 82 | */ 83 | type?: any; 84 | /** 85 | * function to verify body content, the parsing can be aborted by throwing an error. 86 | */ 87 | verify?: (req: express.Request, res: express.Response, buf: Buffer, encoding: string) => void; 88 | }): express.RequestHandler; 89 | 90 | export function text(options?: { 91 | /** 92 | * if deflated bodies will be inflated. (default: true) 93 | */ 94 | inflate?: boolean; 95 | /** 96 | * maximum request body size. (default: '100kb') 97 | */ 98 | limit?: any; 99 | /** 100 | * request content-type to parse, passed directly to the type-is library. (default: 'text/plain') 101 | */ 102 | type?: any; 103 | /** 104 | * function to verify body content, the parsing can be aborted by throwing an error. 105 | */ 106 | verify?: (req: express.Request, res: express.Response, buf: Buffer, encoding: string) => void; 107 | /** 108 | * the default charset to parse as, if not specified in content-type. (default: 'utf-8') 109 | */ 110 | defaultCharset?: string; 111 | }): express.RequestHandler; 112 | 113 | export function urlencoded(options: { 114 | /** 115 | * if deflated bodies will be inflated. (default: true) 116 | */ 117 | inflate?: boolean; 118 | /** 119 | * maximum request body size. (default: '100kb') 120 | */ 121 | limit?: any; 122 | /** 123 | * request content-type to parse, passed directly to the type-is library. (default: 'urlencoded') 124 | */ 125 | type?: any; 126 | /** 127 | * function to verify body content, the parsing can be aborted by throwing an error. 128 | */ 129 | verify?: (req: express.Request, res: express.Response, buf: Buffer, encoding: string) => void; 130 | /** 131 | * parse extended syntax with the qs module. 132 | */ 133 | extended: boolean; 134 | }): express.RequestHandler; 135 | } 136 | 137 | export = bodyParser; 138 | } 139 | -------------------------------------------------------------------------------- /server/typings/q/Q.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for Q 2 | // Project: https://github.com/kriskowal/q 3 | // Definitions by: Barrie Nemetchek , Andrew Gaspar , John Reilly 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | /** 7 | * If value is a Q promise, returns the promise. 8 | * If value is a promise from another library it is coerced into a Q promise (where possible). 9 | */ 10 | declare function Q(promise: Q.IPromise): Q.Promise; 11 | /** 12 | * If value is not a promise, returns a promise that is fulfilled with value. 13 | */ 14 | declare function Q(value: T): Q.Promise; 15 | 16 | declare module Q { 17 | interface IPromise { 18 | then(onFulfill?: (value: T) => U | IPromise, onReject?: (error: any) => U | IPromise): IPromise; 19 | } 20 | 21 | interface Deferred { 22 | promise: Promise; 23 | resolve(value?: T): void; 24 | reject(reason: any): void; 25 | notify(value: any): void; 26 | makeNodeResolver(): (reason: any, value: T) => void; 27 | } 28 | 29 | interface Promise { 30 | /** 31 | * Like a finally clause, allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value. This is useful for collecting resources regardless of whether a job succeeded, like closing a database connection, shutting a server down, or deleting an unneeded key from an object. 32 | 33 | * finally returns a promise, which will become resolved with the same fulfillment value or rejection reason as promise. However, if callback returns a promise, the resolution of the returned promise will be delayed until the promise returned from callback is finished. 34 | */ 35 | fin(finallyCallback: () => any): Promise; 36 | /** 37 | * Like a finally clause, allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value. This is useful for collecting resources regardless of whether a job succeeded, like closing a database connection, shutting a server down, or deleting an unneeded key from an object. 38 | 39 | * finally returns a promise, which will become resolved with the same fulfillment value or rejection reason as promise. However, if callback returns a promise, the resolution of the returned promise will be delayed until the promise returned from callback is finished. 40 | */ 41 | finally(finallyCallback: () => any): Promise; 42 | 43 | /** 44 | * The then method from the Promises/A+ specification, with an additional progress handler. 45 | */ 46 | then(onFulfill?: (value: T) => U | IPromise, onReject?: (error: any) => U | IPromise, onProgress?: Function): Promise; 47 | 48 | /** 49 | * Like then, but "spreads" the array into a variadic fulfillment handler. If any of the promises in the array are rejected, instead calls onRejected with the first rejected promise's rejection reason. 50 | * 51 | * This is especially useful in conjunction with all 52 | */ 53 | spread(onFulfill: (...args: any[]) => IPromise | U, onReject?: (reason: any) => IPromise | U): Promise; 54 | 55 | fail(onRejected: (reason: any) => U | IPromise): Promise; 56 | 57 | /** 58 | * A sugar method, equivalent to promise.then(undefined, onRejected). 59 | */ 60 | catch(onRejected: (reason: any) => U | IPromise): Promise; 61 | 62 | /** 63 | * A sugar method, equivalent to promise.then(undefined, undefined, onProgress). 64 | */ 65 | progress(onProgress: (progress: any) => any): Promise; 66 | 67 | /** 68 | * Much like then, but with different behavior around unhandled rejection. If there is an unhandled rejection, either because promise is rejected and no onRejected callback was provided, or because onFulfilled or onRejected threw an error or returned a rejected promise, the resulting rejection reason is thrown as an exception in a future turn of the event loop. 69 | * 70 | * This method should be used to terminate chains of promises that will not be passed elsewhere. Since exceptions thrown in then callbacks are consumed and transformed into rejections, exceptions at the end of the chain are easy to accidentally, silently ignore. By arranging for the exception to be thrown in a future turn of the event loop, so that it won't be caught, it causes an onerror event on the browser window, or an uncaughtException event on Node.js's process object. 71 | * 72 | * Exceptions thrown by done will have long stack traces, if Q.longStackSupport is set to true. If Q.onerror is set, exceptions will be delivered there instead of thrown in a future turn. 73 | * 74 | * The Golden Rule of done vs. then usage is: either return your promise to someone else, or if the chain ends with you, call done to terminate it. 75 | */ 76 | done(onFulfilled?: (value: T) => any, onRejected?: (reason: any) => any, onProgress?: (progress: any) => any): void; 77 | 78 | /** 79 | * If callback is a function, assumes it's a Node.js-style callback, and calls it as either callback(rejectionReason) when/if promise becomes rejected, or as callback(null, fulfillmentValue) when/if promise becomes fulfilled. If callback is not a function, simply returns promise. 80 | */ 81 | nodeify(callback: (reason: any, value: any) => void): Promise; 82 | 83 | /** 84 | * Returns a promise to get the named property of an object. Essentially equivalent to 85 | * 86 | * promise.then(function (o) { 87 | * return o[propertyName]; 88 | * }); 89 | */ 90 | get(propertyName: String): Promise; 91 | set(propertyName: String, value: any): Promise; 92 | delete(propertyName: String): Promise; 93 | /** 94 | * Returns a promise for the result of calling the named method of an object with the given array of arguments. The object itself is this in the function, just like a synchronous method call. Essentially equivalent to 95 | * 96 | * promise.then(function (o) { 97 | * return o[methodName].apply(o, args); 98 | * }); 99 | */ 100 | post(methodName: String, args: any[]): Promise; 101 | /** 102 | * Returns a promise for the result of calling the named method of an object with the given variadic arguments. The object itself is this in the function, just like a synchronous method call. 103 | */ 104 | invoke(methodName: String, ...args: any[]): Promise; 105 | fapply(args: any[]): Promise; 106 | fcall(...args: any[]): Promise; 107 | 108 | /** 109 | * Returns a promise for an array of the property names of an object. Essentially equivalent to 110 | * 111 | * promise.then(function (o) { 112 | * return Object.keys(o); 113 | * }); 114 | */ 115 | keys(): Promise; 116 | 117 | /** 118 | * A sugar method, equivalent to promise.then(function () { return value; }). 119 | */ 120 | thenResolve(value: U): Promise; 121 | /** 122 | * A sugar method, equivalent to promise.then(function () { throw reason; }). 123 | */ 124 | thenReject(reason: any): Promise; 125 | 126 | /** 127 | * Attaches a handler that will observe the value of the promise when it becomes fulfilled, returning a promise for that same value, perhaps deferred but not replaced by the promise returned by the onFulfilled handler. 128 | */ 129 | tap(onFulfilled: (value: T) => any): Promise; 130 | 131 | timeout(ms: number, message?: string): Promise; 132 | /** 133 | * Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed. 134 | */ 135 | delay(ms: number): Promise; 136 | 137 | /** 138 | * Returns whether a given promise is in the fulfilled state. When the static version is used on non-promises, the result is always true. 139 | */ 140 | isFulfilled(): boolean; 141 | /** 142 | * Returns whether a given promise is in the rejected state. When the static version is used on non-promises, the result is always false. 143 | */ 144 | isRejected(): boolean; 145 | /** 146 | * Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false. 147 | */ 148 | isPending(): boolean; 149 | 150 | valueOf(): any; 151 | 152 | /** 153 | * Returns a "state snapshot" object, which will be in one of three forms: 154 | * 155 | * - { state: "pending" } 156 | * - { state: "fulfilled", value: } 157 | * - { state: "rejected", reason: } 158 | */ 159 | inspect(): PromiseState; 160 | } 161 | 162 | interface PromiseState { 163 | /** 164 | * "fulfilled", "rejected", "pending" 165 | */ 166 | state: string; 167 | value?: T; 168 | reason?: any; 169 | } 170 | 171 | // If no value provided, returned promise will be of void type 172 | export function when(): Promise; 173 | 174 | // if no fulfill, reject, or progress provided, returned promise will be of same type 175 | export function when(value: T | IPromise): Promise; 176 | 177 | // If a non-promise value is provided, it will not reject or progress 178 | export function when(value: T | IPromise, onFulfilled: (val: T) => U | IPromise, onRejected?: (reason: any) => U | IPromise, onProgress?: (progress: any) => any): Promise; 179 | 180 | /** 181 | * Currently "impossible" (and I use the term loosely) to implement due to TypeScript limitations as it is now. 182 | * See: https://github.com/Microsoft/TypeScript/issues/1784 for discussion on it. 183 | */ 184 | // export function try(method: Function, ...args: any[]): Promise; 185 | 186 | export function fbind(method: (...args: any[]) => T | IPromise, ...args: any[]): (...args: any[]) => Promise; 187 | 188 | export function fcall(method: (...args: any[]) => T, ...args: any[]): Promise; 189 | 190 | export function send(obj: any, functionName: string, ...args: any[]): Promise; 191 | export function invoke(obj: any, functionName: string, ...args: any[]): Promise; 192 | export function mcall(obj: any, functionName: string, ...args: any[]): Promise; 193 | 194 | export function denodeify(nodeFunction: Function, ...args: any[]): (...args: any[]) => Promise; 195 | export function nbind(nodeFunction: Function, thisArg: any, ...args: any[]): (...args: any[]) => Promise; 196 | export function nfbind(nodeFunction: Function, ...args: any[]): (...args: any[]) => Promise; 197 | export function nfcall(nodeFunction: Function, ...args: any[]): Promise; 198 | export function nfapply(nodeFunction: Function, args: any[]): Promise; 199 | 200 | export function ninvoke(nodeModule: any, functionName: string, ...args: any[]): Promise; 201 | export function npost(nodeModule: any, functionName: string, args: any[]): Promise; 202 | export function nsend(nodeModule: any, functionName: string, ...args: any[]): Promise; 203 | export function nmcall(nodeModule: any, functionName: string, ...args: any[]): Promise; 204 | 205 | /** 206 | * Returns a promise that is fulfilled with an array containing the fulfillment value of each promise, or is rejected with the same rejection reason as the first promise to be rejected. 207 | */ 208 | export function all(promises: IPromise[]): Promise; 209 | 210 | /** 211 | * Returns a promise for the first of an array of promises to become settled. 212 | */ 213 | export function race(promises: IPromise[]): Promise; 214 | 215 | /** 216 | * Returns a promise that is fulfilled with an array of promise state snapshots, but only after all the original promises have settled, i.e. become either fulfilled or rejected. 217 | */ 218 | export function allSettled(promises: IPromise[]): Promise[]>; 219 | 220 | export function allResolved(promises: IPromise[]): Promise[]>; 221 | 222 | /** 223 | * Like then, but "spreads" the array into a variadic fulfillment handler. If any of the promises in the array are rejected, instead calls onRejected with the first rejected promise's rejection reason. 224 | * This is especially useful in conjunction with all. 225 | */ 226 | export function spread(promises: IPromise[], onFulfilled: (...args: T[]) => U | IPromise, onRejected?: (reason: any) => U | IPromise): Promise; 227 | 228 | /** 229 | * Returns a promise that will have the same result as promise, except that if promise is not fulfilled or rejected before ms milliseconds, the returned promise will be rejected with an Error with the given message. If message is not supplied, the message will be "Timed out after " + ms + " ms". 230 | */ 231 | export function timeout(promise: Promise, ms: number, message?: string): Promise; 232 | 233 | /** 234 | * Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed. 235 | */ 236 | export function delay(promise: Promise, ms: number): Promise; 237 | /** 238 | * Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed. 239 | */ 240 | export function delay(value: T, ms: number): Promise; 241 | /** 242 | * Returns a promise that will be fulfilled with undefined after at least ms milliseconds have passed. 243 | */ 244 | export function delay(ms: number): Promise ; 245 | /** 246 | * Returns whether a given promise is in the fulfilled state. When the static version is used on non-promises, the result is always true. 247 | */ 248 | export function isFulfilled(promise: Promise): boolean; 249 | /** 250 | * Returns whether a given promise is in the rejected state. When the static version is used on non-promises, the result is always false. 251 | */ 252 | export function isRejected(promise: Promise): boolean; 253 | /** 254 | * Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false. 255 | */ 256 | export function isPending(promise: Promise): boolean; 257 | 258 | /** 259 | * Returns a "deferred" object with a: 260 | * promise property 261 | * resolve(value) method 262 | * reject(reason) method 263 | * notify(value) method 264 | * makeNodeResolver() method 265 | */ 266 | export function defer(): Deferred; 267 | 268 | /** 269 | * Returns a promise that is rejected with reason. 270 | */ 271 | export function reject(reason?: any): Promise; 272 | 273 | export function Promise(resolver: (resolve: (val: T | IPromise) => void , reject: (reason: any) => void , notify: (progress: any) => void ) => void ): Promise; 274 | 275 | /** 276 | * Creates a new version of func that accepts any combination of promise and non-promise values, converting them to their fulfillment values before calling the original func. The returned version also always returns a promise: if func does a return or throw, then Q.promised(func) will return fulfilled or rejected promise, respectively. 277 | * 278 | * This can be useful for creating functions that accept either promises or non-promise values, and for ensuring that the function always returns a promise even in the face of unintentional thrown exceptions. 279 | */ 280 | export function promised(callback: (...args: any[]) => T): (...args: any[]) => Promise; 281 | 282 | /** 283 | * Returns whether the given value is a Q promise. 284 | */ 285 | export function isPromise(object: any): boolean; 286 | /** 287 | * Returns whether the given value is a promise (i.e. it's an object with a then function). 288 | */ 289 | export function isPromiseAlike(object: any): boolean; 290 | /** 291 | * Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false. 292 | */ 293 | export function isPending(object: any): boolean; 294 | 295 | /** 296 | * This is an experimental tool for converting a generator function into a deferred function. This has the potential of reducing nested callbacks in engines that support yield. 297 | */ 298 | export function async(generatorFunction: any): (...args: any[]) => Promise; 299 | export function nextTick(callback: Function): void; 300 | 301 | /** 302 | * A settable property that will intercept any uncaught errors that would otherwise be thrown in the next tick of the event loop, usually as a result of done. Can be useful for getting the full stack trace of an error in browsers, which is not usually possible with window.onerror. 303 | */ 304 | export var onerror: (reason: any) => void; 305 | /** 306 | * A settable property that lets you turn on long stack trace support. If turned on, "stack jumps" will be tracked across asynchronous promise operations, so that if an uncaught error is thrown by done or a rejection reason's stack property is inspected in a rejection callback, a long stack trace is produced. 307 | */ 308 | export var longStackSupport: boolean; 309 | 310 | /** 311 | * Calling resolve with a pending promise causes promise to wait on the passed promise, becoming fulfilled with its fulfillment value or rejected with its rejection reason (or staying pending forever, if the passed promise does). 312 | * Calling resolve with a rejected promise causes promise to be rejected with the passed promise's rejection reason. 313 | * Calling resolve with a fulfilled promise causes promise to be fulfilled with the passed promise's fulfillment value. 314 | * Calling resolve with a non-promise value causes promise to be fulfilled with that value. 315 | */ 316 | export function resolve(object: IPromise): Promise; 317 | /** 318 | * Calling resolve with a pending promise causes promise to wait on the passed promise, becoming fulfilled with its fulfillment value or rejected with its rejection reason (or staying pending forever, if the passed promise does). 319 | * Calling resolve with a rejected promise causes promise to be rejected with the passed promise's rejection reason. 320 | * Calling resolve with a fulfilled promise causes promise to be fulfilled with the passed promise's fulfillment value. 321 | * Calling resolve with a non-promise value causes promise to be fulfilled with that value. 322 | */ 323 | export function resolve(object: T): Promise; 324 | 325 | /** 326 | * Resets the global "Q" variable to the value it has before Q was loaded. 327 | * This will either be undefined if there was no version or the version of Q which was already loaded before. 328 | * @returns { The last version of Q. } 329 | */ 330 | export function noConflict(): typeof Q; 331 | } 332 | 333 | declare module "q" { 334 | export = Q; 335 | } 336 | -------------------------------------------------------------------------------- /client/typings/socket.io-client/socket.io-client.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for socket.io-client 1.4.4 2 | // Project: http://socket.io/ 3 | // Definitions by: PROGRE , Damian Connolly , Florent Poujol 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | declare var io: SocketIOClientStatic; 7 | 8 | declare module 'socket.io-client' { 9 | export = io; 10 | } 11 | 12 | interface SocketIOClientStatic { 13 | 14 | /** 15 | * Looks up an existing 'Manager' for multiplexing. If the user summons: 16 | * 'io( 'http://localhost/a' );' 17 | * 'io( 'http://localhost/b' );' 18 | * 19 | * We reuse the existing instance based on the same scheme/port/host, and 20 | * we initialize sockets for each namespace. If autoConnect isn't set to 21 | * false in the options, then we'll automatically connect 22 | * @param uri The uri that we'll connect to, including the namespace, where '/' is the default one (e.g. http://localhost:4000/somenamespace) 23 | * @opts Any connect options that we want to pass along 24 | * @return A Socket object 25 | */ 26 | ( uri: string, opts?: SocketIOClient.ConnectOpts ): SocketIOClient.Socket; 27 | 28 | /** 29 | * Auto-connects to the window location and defalt namespace. 30 | * E.g. window.protocol + '//' + window.host + ':80/' 31 | * @opts Any connect options that we want to pass along 32 | * @return A Socket object 33 | */ 34 | ( opts?: SocketIOClient.ConnectOpts ): SocketIOClient.Socket; 35 | 36 | /** 37 | * @see the default constructor (io(uri, opts)) 38 | */ 39 | connect( uri: string, opts?: SocketIOClient.ConnectOpts ): SocketIOClient.Socket; 40 | 41 | /** 42 | * @see the default constructor (io(opts)) 43 | */ 44 | connect( opts?: SocketIOClient.ConnectOpts ): SocketIOClient.Socket; 45 | 46 | /** 47 | * The socket.io protocol revision number this client works with 48 | * @default 4 49 | */ 50 | protocol: number; 51 | 52 | /** 53 | * Socket constructor - exposed for the standalone build 54 | */ 55 | Socket: SocketIOClient.Socket; 56 | 57 | /** 58 | * Manager constructor - exposed for the standalone build 59 | */ 60 | Manager: SocketIOClient.ManagerStatic; 61 | } 62 | 63 | declare module SocketIOClient { 64 | 65 | /** 66 | * The base emiter class, used by Socket and Manager 67 | */ 68 | interface Emitter { 69 | /** 70 | * Adds a listener for a particular event. Calling multiple times will add 71 | * multiple listeners 72 | * @param event The event that we're listening for 73 | * @param fn The function to call when we get the event. Parameters depend on the 74 | * event in question 75 | * @return This Emitter 76 | */ 77 | on( event: string, fn: Function ):Emitter; 78 | 79 | /** 80 | * @see on( event, fn ) 81 | */ 82 | addEventListener( event: string, fn: Function ):Emitter; 83 | 84 | /** 85 | * Adds a listener for a particular event that will be invoked 86 | * a single time before being automatically removed 87 | * @param event The event that we're listening for 88 | * @param fn The function to call when we get the event. Parameters depend on 89 | * the event in question 90 | * @return This Emitter 91 | */ 92 | once( event: string, fn: Function ):Emitter; 93 | 94 | /** 95 | * Removes a listener for a particular type of event. This will either 96 | * remove a specific listener, or all listeners for this type of event 97 | * @param event The event that we want to remove the listener of 98 | * @param fn The function to remove, or null if we want to remove all functions 99 | * @return This Emitter 100 | */ 101 | off( event: string, fn?: Function ):Emitter; 102 | 103 | /** 104 | * @see off( event, fn ) 105 | */ 106 | removeListener( event: string, fn?: Function ):Emitter; 107 | 108 | /** 109 | * @see off( event, fn ) 110 | */ 111 | removeEventListener( event: string, fn?: Function ):Emitter; 112 | 113 | /** 114 | * Removes all event listeners on this object 115 | * @return This Emitter 116 | */ 117 | removeAllListeners():Emitter; 118 | 119 | /** 120 | * Emits 'event' with the given args 121 | * @param event The event that we want to emit 122 | * @param args Optional arguments to emit with the event 123 | * @return Emitter 124 | */ 125 | emit( event: string, ...args: any[] ):Emitter; 126 | 127 | /** 128 | * Returns all the callbacks for a particular event 129 | * @param event The event that we're looking for the callbacks of 130 | * @return An array of callback Functions, or an empty array if we don't have any 131 | */ 132 | listeners( event: string ):Function[]; 133 | 134 | /** 135 | * Returns if we have listeners for a particular event 136 | * @param event The event that we want to check if we've listeners for 137 | * @return True if we have listeners for this event, false otherwise 138 | */ 139 | hasListeners( event: string ):boolean; 140 | } 141 | 142 | /** 143 | * The Socket static interface 144 | */ 145 | interface SocketStatic { 146 | 147 | /** 148 | * Creates a new Socket, used for communicating with a specific namespace 149 | * @param io The Manager that's controlling this socket 150 | * @param nsp The namespace that this socket is for (@default '/') 151 | * @return A new Socket 152 | */ 153 | ( io: SocketIOClient.Manager, nsp: string ): Socket; 154 | 155 | /** 156 | * Creates a new Socket, used for communicating with a specific namespace 157 | * @param io The Manager that's controlling this socket 158 | * @param nsp The namespace that this socket is for (@default '/') 159 | * @return A new Socket 160 | */ 161 | new ( url: string, opts: any ): SocketIOClient.Manager; 162 | } 163 | 164 | /** 165 | * The Socket that we use to connect to a Namespace on the server 166 | */ 167 | interface Socket extends Emitter { 168 | 169 | /** 170 | * The Manager that's controller this socket 171 | */ 172 | io: SocketIOClient.Manager; 173 | 174 | /** 175 | * The namespace that this socket is for 176 | * @default '/' 177 | */ 178 | nsp: string; 179 | 180 | /** 181 | * The ID of the socket; matches the server ID and is set when we're connected, and cleared 182 | * when we're disconnected 183 | */ 184 | id: string; 185 | 186 | /** 187 | * Are we currently connected? 188 | * @default false 189 | */ 190 | connected: boolean; 191 | 192 | /** 193 | * Are we currently disconnected? 194 | * @default true 195 | */ 196 | disconnected: boolean; 197 | 198 | /** 199 | * Opens our socket so that it connects. If the 'autoConnect' option for io is 200 | * true (default), then this is called automatically when the Socket is created 201 | */ 202 | open(): Socket; 203 | 204 | /** 205 | * @see open(); 206 | */ 207 | connect(): Socket; 208 | 209 | /** 210 | * Sends a 'message' event 211 | * @param args Any optional arguments that we want to send 212 | * @see emit 213 | * @return This Socket 214 | */ 215 | send( ...args: any[] ):Socket; 216 | 217 | /** 218 | * An override of the base emit. If the event is one of: 219 | * connect 220 | * connect_error 221 | * connect_timeout 222 | * connecting 223 | * disconnect 224 | * error 225 | * reconnect 226 | * reconnect_attempt 227 | * reconnect_failed 228 | * reconnect_error 229 | * reconnecting 230 | * ping 231 | * pong 232 | * then the event is emitted normally. Otherwise, if we're connected, the 233 | * event is sent. Otherwise, it's buffered. 234 | * 235 | * If the last argument is a function, then it will be called 236 | * as an 'ack' when the response is received. The parameter(s) of the 237 | * ack will be whatever data is returned from the event 238 | * @param event The event that we're emitting 239 | * @param args Optional arguments to send with the event 240 | * @return This Socket 241 | */ 242 | emit( event: string, ...args: any[] ):Socket; 243 | 244 | /** 245 | * Disconnects the socket manually 246 | * @return This Socket 247 | */ 248 | close():Socket; 249 | 250 | /** 251 | * @see close() 252 | */ 253 | disconnect():Socket; 254 | 255 | /** 256 | * Sets the compress flag. 257 | * @param compress If `true`, compresses the sending data 258 | * @return this Socket 259 | */ 260 | compress(compress: boolean):Socket; 261 | } 262 | 263 | /** 264 | * The Manager static interface 265 | */ 266 | interface ManagerStatic { 267 | /** 268 | * Creates a new Manager 269 | * @param uri The URI that we're connecting to (e.g. http://localhost:4000) 270 | * @param opts Any connection options that we want to use (and pass to engine.io) 271 | * @return A Manager 272 | */ 273 | ( uri: string, opts?: SocketIOClient.ConnectOpts ): SocketIOClient.Manager; 274 | 275 | /** 276 | * Creates a new Manager with the default URI (window host) 277 | * @param opts Any connection options that we want to use (and pass to engine.io) 278 | */ 279 | ( opts: SocketIOClient.ConnectOpts ):SocketIOClient.Manager; 280 | 281 | /** 282 | * @see default constructor 283 | */ 284 | new ( uri: string, opts?: SocketIOClient.ConnectOpts ): SocketIOClient.Manager; 285 | 286 | /** 287 | * @see default constructor 288 | */ 289 | new ( opts: SocketIOClient.ConnectOpts ):SocketIOClient.Manager; 290 | } 291 | 292 | /** 293 | * The Manager class handles all the Namespaces and Sockets that we're using 294 | */ 295 | interface Manager extends Emitter { 296 | 297 | /** 298 | * All the namespaces currently controlled by this Manager, and the Sockets 299 | * that we're using to communicate with them 300 | */ 301 | nsps: { [namespace:string]: Socket }; 302 | 303 | /** 304 | * The connect options that we used when creating this Manager 305 | */ 306 | opts: SocketIOClient.ConnectOpts; 307 | 308 | /** 309 | * The state of the Manager. Either 'closed', 'opening', or 'open' 310 | */ 311 | readyState: string; 312 | 313 | /** 314 | * The URI that this manager is for (host + port), e.g. 'http://localhost:4000' 315 | */ 316 | uri: string; 317 | 318 | /** 319 | * The currently connected sockets 320 | */ 321 | connecting: Socket[]; 322 | 323 | /** 324 | * If we should auto connect (also used when creating Sockets). Set via the 325 | * opts object 326 | */ 327 | autoConnect: boolean; 328 | 329 | /** 330 | * Gets if we should reconnect automatically 331 | * @default true 332 | */ 333 | reconnection(): boolean; 334 | 335 | /** 336 | * Sets if we should reconnect automatically 337 | * @param v True if we should reconnect automatically, false otherwise 338 | * @default true 339 | * @return This Manager 340 | */ 341 | reconnection( v: boolean ): Manager; 342 | 343 | /** 344 | * Gets the number of reconnection attempts we should try before giving up 345 | * @default Infinity 346 | */ 347 | reconnectionAttempts(): number; 348 | 349 | /** 350 | * Sets the number of reconnection attempts we should try before giving up 351 | * @param v The number of attempts we should do before giving up 352 | * @default Infinity 353 | * @return This Manager 354 | */ 355 | reconnectionAttempts( v: number ): Manager; 356 | 357 | /** 358 | * Gets the delay in milliseconds between each reconnection attempt 359 | * @default 1000 360 | */ 361 | reconnectionDelay(): number; 362 | 363 | /** 364 | * Sets the delay in milliseconds between each reconnection attempt 365 | * @param v The delay in milliseconds 366 | * @default 1000 367 | * @return This Manager 368 | */ 369 | reconnectionDelay( v: number ): Manager; 370 | 371 | /** 372 | * Gets the max reconnection delay in milliseconds between each reconnection 373 | * attempt 374 | * @default 5000 375 | */ 376 | reconnectionDelayMax(): number; 377 | 378 | /** 379 | * Sets the max reconnection delay in milliseconds between each reconnection 380 | * attempt 381 | * @param v The max reconnection dleay in milliseconds 382 | * @return This Manager 383 | */ 384 | reconnectionDelayMax( v: number ): Manager; 385 | 386 | /** 387 | * Gets the randomisation factor used in the exponential backoff jitter 388 | * when reconnecting 389 | * @default 0.5 390 | */ 391 | randomizationFactor(): number; 392 | 393 | /** 394 | * Sets the randomisation factor used in the exponential backoff jitter 395 | * when reconnecting 396 | * @param The reconnection randomisation factor 397 | * @default 0.5 398 | * @return This Manager 399 | */ 400 | randomizationFactor( v: number ): Manager; 401 | 402 | /** 403 | * Gets the timeout in milliseconds for our connection attempts 404 | * @default 20000 405 | */ 406 | timeout(): number; 407 | 408 | /** 409 | * Sets the timeout in milliseconds for our connection attempts 410 | * @param The connection timeout milliseconds 411 | * @return This Manager 412 | */ 413 | timeout(v: boolean): Manager; 414 | 415 | /** 416 | * Sets the current transport socket and opens our connection 417 | * @param fn An optional callback to call when our socket has either opened, or 418 | * failed. It can take one optional parameter of type Error 419 | * @return This Manager 420 | */ 421 | open( fn?: (err?: any) => void ): Manager; 422 | 423 | /** 424 | * @see open( fn ); 425 | */ 426 | connect( fn?: (err?: any) => void ): Manager; 427 | 428 | /** 429 | * Creates a new Socket for the given namespace 430 | * @param nsp The namespace that this Socket is for 431 | * @return A new Socket, or if one has already been created for this namespace, 432 | * an existing one 433 | */ 434 | socket( nsp: string ): Socket; 435 | } 436 | 437 | /** 438 | * Options we can pass to the socket when connecting 439 | */ 440 | interface ConnectOpts { 441 | 442 | /** 443 | * Should we force a new Manager for this connection? 444 | * @default false 445 | */ 446 | forceNew?: boolean; 447 | 448 | /** 449 | * Should we multiplex our connection (reuse existing Manager) ? 450 | * @default true 451 | */ 452 | multiplex?: boolean; 453 | 454 | /** 455 | * The path to get our client file from, in the case of the server 456 | * serving it 457 | * @default '/socket.io' 458 | */ 459 | path?: string; 460 | 461 | /** 462 | * Should we allow reconnections? 463 | * @default true 464 | */ 465 | reconnection?: boolean; 466 | 467 | /** 468 | * How many reconnection attempts should we try? 469 | * @default Infinity 470 | */ 471 | reconnectionAttempts?: number; 472 | 473 | /** 474 | * The time delay in milliseconds between reconnection attempts 475 | * @default 1000 476 | */ 477 | reconnectionDelay?: number; 478 | 479 | /** 480 | * The max time delay in milliseconds between reconnection attempts 481 | * @default 5000 482 | */ 483 | reconnectionDelayMax?: number; 484 | 485 | /** 486 | * Used in the exponential backoff jitter when reconnecting 487 | * @default 0.5 488 | */ 489 | randomizationFactor?: number; 490 | 491 | /** 492 | * The timeout in milliseconds for our connection attempt 493 | * @default 20000 494 | */ 495 | timeout?: number; 496 | 497 | /** 498 | * Should we automically connect? 499 | * @default true 500 | */ 501 | autoConnect?: boolean; 502 | 503 | /** 504 | * The host that we're connecting to. Set from the URI passed when connecting 505 | */ 506 | host?: string; 507 | 508 | /** 509 | * The hostname for our connection. Set from the URI passed when connecting 510 | */ 511 | hostname?: string; 512 | 513 | /** 514 | * If this is a secure connection. Set from the URI passed when connecting 515 | */ 516 | secure?: boolean; 517 | 518 | /** 519 | * The port for our connection. Set from the URI passed when connecting 520 | */ 521 | port?: string; 522 | 523 | /** 524 | * Any query parameters in our uri. Set from the URI passed when connecting 525 | */ 526 | query?: Object; 527 | 528 | /** 529 | * `http.Agent` to use, defaults to `false` (NodeJS only) 530 | */ 531 | agent?: string|boolean; 532 | 533 | /** 534 | * Whether the client should try to upgrade the transport from 535 | * long-polling to something better. 536 | * @default true 537 | */ 538 | upgrade?: boolean; 539 | 540 | /** 541 | * Forces JSONP for polling transport. 542 | */ 543 | forceJSONP?: boolean; 544 | 545 | /** 546 | * Determines whether to use JSONP when necessary for polling. If 547 | * disabled (by settings to false) an error will be emitted (saying 548 | * "No transports available") if no other transports are available. 549 | * If another transport is available for opening a connection (e.g. 550 | * WebSocket) that transport will be used instead. 551 | * @default true 552 | */ 553 | jsonp?: boolean; 554 | 555 | /** 556 | * Forces base 64 encoding for polling transport even when XHR2 557 | * responseType is available and WebSocket even if the used standard 558 | * supports binary. 559 | */ 560 | forceBase64?: boolean; 561 | 562 | /** 563 | * Enables XDomainRequest for IE8 to avoid loading bar flashing with 564 | * click sound. default to `false` because XDomainRequest has a flaw 565 | * of not sending cookie. 566 | * @default false 567 | */ 568 | enablesXDR?: boolean; 569 | 570 | /** 571 | * The param name to use as our timestamp key 572 | * @default 't' 573 | */ 574 | timestampParam?: string; 575 | 576 | /** 577 | * Whether to add the timestamp with each transport request. Note: this 578 | * is ignored if the browser is IE or Android, in which case requests 579 | * are always stamped 580 | * @default false 581 | */ 582 | timestampRequests?: boolean; 583 | 584 | /** 585 | * A list of transports to try (in order). Engine.io always attempts to 586 | * connect directly with the first one, provided the feature detection test 587 | * for it passes. 588 | * @default ['polling','websocket'] 589 | */ 590 | transports?: string[]; 591 | 592 | /** 593 | * The port the policy server listens on 594 | * @default 843 595 | */ 596 | policyPost?: number; 597 | 598 | /** 599 | * If true and if the previous websocket connection to the server succeeded, 600 | * the connection attempt will bypass the normal upgrade process and will 601 | * initially try websocket. A connection attempt following a transport error 602 | * will use the normal upgrade process. It is recommended you turn this on 603 | * only when using SSL/TLS connections, or if you know that your network does 604 | * not block websockets. 605 | * @default false 606 | */ 607 | rememberUpgrade?: boolean; 608 | 609 | /** 610 | * Are we only interested in transports that support binary? 611 | */ 612 | onlyBinaryUpgrades?: boolean; 613 | 614 | /** 615 | * (SSL) Certificate, Private key and CA certificates to use for SSL. 616 | * Can be used in Node.js client environment to manually specify 617 | * certificate information. 618 | */ 619 | pfx?: string; 620 | 621 | /** 622 | * (SSL) Private key to use for SSL. Can be used in Node.js client 623 | * environment to manually specify certificate information. 624 | */ 625 | key?: string; 626 | 627 | /** 628 | * (SSL) A string or passphrase for the private key or pfx. Can be 629 | * used in Node.js client environment to manually specify certificate 630 | * information. 631 | */ 632 | passphrase?: string 633 | 634 | /** 635 | * (SSL) Public x509 certificate to use. Can be used in Node.js client 636 | * environment to manually specify certificate information. 637 | */ 638 | cert?: string; 639 | 640 | /** 641 | * (SSL) An authority certificate or array of authority certificates to 642 | * check the remote host against.. Can be used in Node.js client 643 | * environment to manually specify certificate information. 644 | */ 645 | ca?: string|string[]; 646 | 647 | /** 648 | * (SSL) A string describing the ciphers to use or exclude. Consult the 649 | * [cipher format list] 650 | * (http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT) for 651 | * details on the format.. Can be used in Node.js client environment to 652 | * manually specify certificate information. 653 | */ 654 | ciphers?: string; 655 | 656 | /** 657 | * (SSL) If true, the server certificate is verified against the list of 658 | * supplied CAs. An 'error' event is emitted if verification fails. 659 | * Verification happens at the connection level, before the HTTP request 660 | * is sent. Can be used in Node.js client environment to manually specify 661 | * certificate information. 662 | */ 663 | rejectUnauthorized?: boolean; 664 | 665 | } 666 | } 667 | --------------------------------------------------------------------------------