daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Mar 19th, 2018 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Express
  2. let express = require("express");
  3. let app = express();
  4. app.enable('trust proxy');
  5. const path = require("path");
  6. const crypto = require('crypto');
  7. const Datastore = require('@google-cloud/datastore');
  8. // Static Folder
  9. app.use(express.static(__dirname + '/public/dist'));
  10.  
  11. // Body Parser
  12. let bodyParser = require("body-parser");
  13. app.use(bodyParser.urlencoded({extended:true}));
  14. app.use(bodyParser.json());
  15.  
  16. // Morgan
  17. let morgan = require("morgan");
  18. app.use(morgan('dev'));
  19.  
  20.  
  21.  
  22.  
  23. const datastore = Datastore();
  24. const query = datastore.createQuery('visit')
  25.     .order('timestamp', { descending: true })
  26. .limit(10);
  27.  
  28.  
  29. // Routes
  30. // Get Users
  31. app.get("/customer", (req, res, next) => {
  32.     console.log("Server > GET '/customer' ");
  33.     return datastore.runQuery(query)
  34.     .then((results) => {
  35.       const entities = results[0];
  36.       return results;//.map((entity) => `CNAME: ${entity.cname}, Phone: ${entity.phone}`);
  37.       console.log(entity);
  38.  
  39.  
  40.     })
  41. })
  42.  
  43.  
  44. app.all("*", (req,res,next) => {
  45.     res.sendfile(path.resolve("./public/dist/index.html"));
  46. })
  47.  
  48. // Server Listening @ 1337
  49. app.listen(8080, ()=> console.log("Server running at 8080"));
  50.    
  51. import { Injectable } from '@angular/core';
  52. import { Customer } from '../customer';
  53. //import 'rxjs/rx';
  54. import { Observable } from 'rxjs/Observable';
  55. import { Http } from '@angular/http';
  56.  
  57. @Injectable()
  58. export class CustomerService {
  59.  
  60.    constructor(private _http: Http) { }
  61.  
  62.   create(user: Customer) {
  63.    return this._http.post('/customer', user).map(data => data.json()).toPromise();
  64.  
  65.   }
  66.   destroy(user: Customer) {
  67.    // return this._http.delete('/users/' + user._id).map(data => data.json()).toPromise();
  68.   }
  69.   update(user: Customer) {
  70.    // return this._http.put('/users/' + user._id, user).map(data => data.json()).toPromise();
  71.   }
  72.   getUsers() {
  73.     return this._http.get('/customer').map(data => data.json()).toPromise();
  74.   }
  75.  
  76.   getUser(user: Customer) {
  77.    // return this._http.post('/users' + user._id, user).toPromise();
  78.   }
  79.  
  80. }
  81.    
  82. import { Component,OnInit } from '@angular/core';
  83. import { Customer } from '../customer';
  84. import { CustomerService } from './customer.service'
  85. import { Http } from '@angular/http';
  86. @Component({
  87.   selector: 'ngx-form-layouts',
  88.   styleUrls: ['./customer.component.scss'],
  89.   templateUrl: './customer.component.html',
  90. })
  91. export class CustomerComponent implements OnInit {
  92.  
  93.   customer: Array<Customer>=[];
  94.   constructor(private _customerService: CustomerService,private _http: Http ) { }
  95.   ngOnInit() {
  96.    this.getUsers();
  97.   }
  98. getUsers() {
  99.   this._customerService.getUsers().then(customer => this.customer = customer)
  100.   .catch(err => console.log(err));
  101.  // return this._http.get('/customer').map(data => data.json()).toPromise();
  102. }
  103. }
  104.    
  105. <div class="row">
  106.     <div class="col-lg-12">
  107.         <nb-card>
  108.             <nb-card-body>
  109.                     {{customer | json}}
  110.             </nb-card-body>
  111.         </nb-card>
  112.     </div>
  113. </div>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top