Skip to content

Commit

Permalink
Merge pull request #203 from jkwening/185-saved-pin
Browse files Browse the repository at this point in the history
185 saved pin
  • Loading branch information
jkwening authored Mar 6, 2018
2 parents 7d94d61 + 6c7844b commit 0feb957
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ app.use((req, res, next) => {
if (req.method === 'OPTIONS') {
res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, PATCH, DELETE');

res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Access, Authorization, x-access-token',
);

return res.status(200).json({});
}

Expand Down
14 changes: 11 additions & 3 deletions client/src/components/LeafletOsmMap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import style from "./style";
import MapPane from './MapPane';
import Search from '../../components/Search';
import SearchResults from '../../components/SearchResults';
import { makeRequest } from '../../js/server-requests-utils';

/**
* Leaflet related imports: leaflet, pouchdb module, and routing machine module
Expand Down Expand Up @@ -111,9 +112,16 @@ export default class LeafletOSMMap extends Component {
const deleteBtn = createButton('Remove', container);

L.DomEvent.on(saveBtn, 'click', function() {
// TODO - save marker location to db if possible or queue to
// save when backend server is available
alert(`Save marker at: ${event.latlng}!`);
makeRequest('POST', 'savedPins', '', {
lat: event.latlng.lat,
lng: event.latlng.lng,
}).then((response) => {
alert(`Succes: Saved pin at ${event.latlng} to db`);
console.log('Success - saved: ', response);
}).catch((err) => {
alert('Error saving pin: ', err);
console.log('Error saving pin: ', err);
})
});

L.DomEvent.on(deleteBtn, 'click', function() {
Expand Down
4 changes: 2 additions & 2 deletions client/src/js/server-requests-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ export const makeRequest = (method='GET', baseEndPoint, endPointAddon='', bodyDa
})
}

const url = (BASE_ENDPOINTS[baseEndPoint] || baseEndPoint) + endPointAddon;
const url = ((BASE_ENDPOINTS[baseEndPoint] || baseEndPoint) + endPointAddon).trim();
headers['x-access-token'] = token.getCookie();

let config = {method,
const config = {method,
url,
params,
headers,
Expand Down
2 changes: 1 addition & 1 deletion models/saved-pins.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const savedPinsSchema = new mongoose.Schema({
lng: {
type: Number, min: -180, max: 180, required: true,
},
place_id: { type: String, required: true },
place_id: { type: String, default: '' },
save_date: { type: Date, default: Date.now },
user: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
});
Expand Down

0 comments on commit 0feb957

Please sign in to comment.