You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
604 B
26 lines
604 B
1 year ago
|
import MapModel from '../db/models/map.js'
|
||
|
|
||
|
const getAllMaps = async (req, res) => {
|
||
|
const maps = await MapModel.query()
|
||
|
|
||
|
res.json({ maps })
|
||
|
}
|
||
|
|
||
|
const getMapByName = async (req, res) => {
|
||
|
const name = req.params.mapName
|
||
|
try {
|
||
|
let map = await MapModel.query().where({ name }).withGraphFetched('map_points').first()
|
||
|
|
||
|
if (!map) {
|
||
|
const created = await MapModel.query().insert({ name })
|
||
|
map = await MapModel.query().findById(created.id).withGraphFetched('map_points')
|
||
|
}
|
||
|
|
||
|
res.json(map)
|
||
|
} catch (error) {
|
||
|
console.error(error)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export { getMapByName, getAllMaps }
|