Created
June 14, 2018 17:15
-
-
Save cesargdm/35d0841b54211a09a06d3a8761107908 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path') | |
require(path.resolve('models/Schedule')) | |
const Location = require(path.resolve('models/Location')) | |
const connectToDatabase = require(path.resolve('src/helpers/connectToDb')) | |
module.exports.handler = async () => { | |
try { | |
await connectToDatabase() | |
const locations = await Location.find().populate('schedule') | |
return { | |
statusCode: 200, | |
headers: { 'Access-Control-Allow-Origin': '*' }, | |
body: JSON.stringify({ | |
locations | |
}) | |
} | |
} catch (error) { | |
return { | |
statusCode: 500, | |
headers: { 'Access-Control-Allow-Origin': '*' }, | |
body: JSON.stringify({ | |
message: 'Error, please try again later' | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment