@@ -3,42 +3,78 @@ import {
3
3
availableContinents ,
4
4
availableSovereignties ,
5
5
} from "../constants/constant" ;
6
+ import generateGuideResponse from "../helper/generateGuideResponse" ;
6
7
7
8
const index = ( req : Request , res : Response ) => {
8
9
const fullUrl = req . fullUrl ;
9
10
10
11
const apiIndexGuide = {
11
- allCountriesUrl : `${ fullUrl } /all` ,
12
- countriesByContinent : `${ fullUrl } /continent/{continentName}` ,
13
- countriesBySovereignty : `${ fullUrl } /sovereignty/{sovereigntyName}` ,
14
- countryByISONumericCode : `${ fullUrl } /isocode/numeric/{ISONumericCode}` ,
15
- countryByISOCode : `${ fullUrl } /isocode/{ISOCode}` ,
16
- countriesByCurrencyCode : `${ fullUrl } /currency/{currencyCode}` ,
17
- countryByTopLevelDomain : `${ fullUrl } /topLevelDomain/{topLevelDomain}` ,
18
- countriesByDialingCode : `${ fullUrl } /dialingCode/{dialingCode}` ,
12
+ allCountriesUrl : `${ fullUrl } /countries/ all` ,
13
+ countriesByContinent : `${ fullUrl } /countries/ continent/{continentName}` ,
14
+ countriesBySovereignty : `${ fullUrl } /countries/ sovereignty/{sovereigntyName}` ,
15
+ countryByISONumericCode : `${ fullUrl } /countries/ isocode/numeric/{ISONumericCode}` ,
16
+ countryByISOCode : `${ fullUrl } /countries/ isocode/{ISOCode}` ,
17
+ countriesByCurrencyCode : `${ fullUrl } /countries/ currency/{currencyCode}` ,
18
+ countryByTopLevelDomain : `${ fullUrl } /countries/ topLevelDomain/{topLevelDomain}` ,
19
+ countriesByDialingCode : `${ fullUrl } /countries/ dialingCode/{dialingCode}` ,
19
20
} ;
20
21
21
22
res . json ( apiIndexGuide ) ;
22
23
} ;
23
24
24
- const continent = ( _req : Request , res : Response ) => {
25
- const apiContinentGuide = {
26
- message : "Continent should be one of the following" ,
27
- availableContinents,
28
- } ;
29
- res . status ( 404 ) . json ( apiContinentGuide ) ;
25
+ const continent = ( req : Request , res : Response ) => {
26
+ generateGuideResponse ( req , res , "continent" , "continentName" , "Continent" ) ;
30
27
} ;
31
28
32
- const sovereignty = ( _req : Request , res : Response ) => {
33
- const apiSovereigntyGuide = {
34
- message : "Sovereignty should be one of the following" ,
35
- availableSovereignties,
36
- } ;
37
- res . status ( 404 ) . json ( apiSovereigntyGuide ) ;
29
+ const sovereignty = ( req : Request , res : Response ) => {
30
+ generateGuideResponse (
31
+ req ,
32
+ res ,
33
+ "sovereignty" ,
34
+ "sovereigntyName" ,
35
+ "Sovereignty"
36
+ ) ;
37
+ } ;
38
+
39
+ const ISONumericCode = ( req : Request , res : Response ) => {
40
+ generateGuideResponse (
41
+ req ,
42
+ res ,
43
+ "isocode/numeric" ,
44
+ "ISONumericCode" ,
45
+ "ISO Numeric Code"
46
+ ) ;
47
+ } ;
48
+
49
+ const ISOCode = ( req : Request , res : Response ) => {
50
+ generateGuideResponse ( req , res , "isocode" , "ISOCode" , "ISOCode" ) ;
51
+ } ;
52
+
53
+ const currencyCode = ( req : Request , res : Response ) => {
54
+ generateGuideResponse ( req , res , "currency" , "ISOCode" , "Currency Code" ) ;
55
+ } ;
56
+
57
+ const topLevelDomain = ( req : Request , res : Response ) => {
58
+ generateGuideResponse (
59
+ req ,
60
+ res ,
61
+ "topLevelDomain" ,
62
+ "topLevelDomain" ,
63
+ "Top Level Domain"
64
+ ) ;
65
+ } ;
66
+
67
+ const dialingCode = ( req : Request , res : Response ) => {
68
+ generateGuideResponse ( req , res , "dialingCode" , "dialingCode" , "Dialing Code" ) ;
38
69
} ;
39
70
40
71
export default {
41
72
index,
42
73
continent,
43
74
sovereignty,
75
+ ISONumericCode,
76
+ ISOCode,
77
+ currencyCode,
78
+ topLevelDomain,
79
+ dialingCode,
44
80
} ;
0 commit comments