-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #386 from ideal-postcodes/onspd_aug_2019
ONSPD Aug 2019 Update
- Loading branch information
Showing
28 changed files
with
2,108 additions
and
1,053 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"use strict"; | ||
|
||
const ScottishPostcode = require("../models/scottish_postcode"); | ||
const Postcode = require("postcode"); | ||
const { | ||
InvalidPostcodeError, | ||
PostcodeNotFoundError, | ||
} = require("../lib/errors.js"); | ||
|
||
exports.show = (request, response, next) => { | ||
const { postcode } = request.params; | ||
if (!Postcode.isValid(postcode.trim())) | ||
return next(new InvalidPostcodeError()); | ||
|
||
ScottishPostcode.find(postcode, (error, result) => { | ||
if (error) return next(error); | ||
if (!result) return next(new PostcodeNotFoundError()); | ||
response.jsonApiResponse = { | ||
status: 200, | ||
result: ScottishPostcode.toJson(result), | ||
}; | ||
return next(); | ||
}); | ||
}; |
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
Oops, something went wrong.