-
-
Save joshdcar/8d50ff70c9303b504d69f968d2d3a5de 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
import { Router, Request, Response, NextFunction} from 'express'; | |
import { LocationData } from '../data/LocationData'; | |
import { PhotoLocationDocument } from '../data/PhotoLocationDocument'; | |
export class PhotoLocationRouter { | |
router:Router; | |
constructor(){ | |
this.router = Router(); | |
this.init(); | |
} | |
public GetPhotoLocation(req:Request, res: Response){ | |
let query:string = req.params.id; | |
var data:LocationData = new LocationData(); | |
data.GetLocationAsync(query).then( requestResult => { | |
res.status(200).send(requestResult); | |
}).catch( e => { | |
res.status(404).send({ | |
message: e.message, | |
status: res.status | |
}); | |
}); | |
} | |
public AddPhotoLocation(req:Request, res: Response){ | |
var doc: PhotoLocationDocument = <PhotoLocationDocument>req.body; | |
var data:LocationData = new LocationData(); | |
data.AddLocationAsync(doc).then( requestResult => { | |
res.status(200).send(requestResult); | |
}).catch( e => { | |
res.status(404).send({ | |
message: e.message, | |
status: res.status | |
}); | |
}); | |
} | |
public UpdatePhotoLocation(req:Request, res: Response){ | |
var doc: PhotoLocationDocument = <PhotoLocationDocument>req.body; | |
var data:LocationData = new LocationData(); | |
data.UpdateLocationAsync(doc).then( requestResult => { | |
res.status(200).send(requestResult); | |
}).catch( e => { | |
res.status(404).send({ | |
message: e.message, | |
status: 404 | |
}); | |
}); | |
} | |
public DeletePhotoLocation(req:Request, res: Response){ | |
let query:string = req.params.id; | |
var data:LocationData = new LocationData(); | |
data.DeletePhotoLocationAsync(query).then( requestResult => { | |
res.status(204).send(); | |
}).catch( e => { | |
res.status(404).send({ | |
message: e.message, | |
status: 404 | |
}); | |
}); | |
}; | |
init(){ | |
this.router.get("/:id", this.GetPhotoLocation), | |
this.router.post("/", this.AddPhotoLocation), | |
this.router.put("/",this.UpdatePhotoLocation), | |
this.router.delete("/:id",this.DeletePhotoLocation) | |
} | |
} | |
const photoLocationRouter = new PhotoLocationRouter(); | |
photoLocationRouter.init(); | |
export default photoLocationRouter.router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment