-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
67 lines (59 loc) · 1.9 KB
/
server.js
File metadata and controls
67 lines (59 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require('dotenv').config();
/* **** Express modules **** */
const express = require('express');
const app = express();
const morgan = require('morgan');
const axios = require('axios');
const bodyParser = require('body-parser');
/* **** DB Connection modules **** */
const db = require('./database');
/* **** Apply universal middleware **** */
// app.use('/public', express.static(`${__dirname}/../public`));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// app.use(cookieParser());
app.use(morgan({ format: 'dev' }));
// app.use('/graphql', graphqlHTTP({ schema: gqlSchema, graphiql: true }));
app.get('/ms/user/map', (req, res) => {
const chef = req.query;
console.log('this is chef from server ln 24', req.query);
axios
.get(
`https://maps.googleapis.com/maps/api/geocode/json?address=${
chef.streetAddress
},${chef.city},${chef.stateName}&key=${process.env.MAP_KEY}`
)
.then(data => {
const { lat, lng } = data.data.results[0].geometry.location;
console.log(lat, lng, chef);
db.MapChef.findOrCreate({
where: { chefId: chef.chefId },
defaults: {
chefId: chef.ChefId,
streetAddress: chef.streetAddress,
city: chef.city,
stateName: chef.stateName,
zip: chef.zip,
lat,
lng,
name: chef.name,
username: chef.username,
description: chef.description
}
})
.then(data => {
console.log('THIS IS THE DATA FROM MAPSERVER LN51', data);
res.send(data);
})
.catch(err => console.log(err));
// .success(function(user, created) {
// console.log(user.values);
// res.send(200);
// })
// .error(err => console.log(err));
// res.send({
// lat, lng, name: chef.name, description: chef.description,
// });
});
});
module.exports = app;