@@ -29,16 +29,27 @@ router
29
29
30
30
let contractHash = req . body . contractHash . toLowerCase ( ) ;
31
31
let packageHash = req . body . packageHash . toLowerCase ( ) ;
32
- var newpair = new hashesofpairsModel ( {
32
+ let pairData = await hashesofpairsModel . findOne ( {
33
33
contractHash : contractHash ,
34
34
packageHash : packageHash ,
35
35
} ) ;
36
- await hashesofpairsModel . create ( newpair ) ;
36
+ if ( pairData == null ) {
37
+ var newpair = new hashesofpairsModel ( {
38
+ contractHash : contractHash ,
39
+ packageHash : packageHash ,
40
+ } ) ;
41
+ await hashesofpairsModel . create ( newpair ) ;
37
42
38
- return res . status ( 200 ) . json ( {
39
- success : true ,
40
- message : "Pair's Contract and Package Hash are Succefully stored." ,
41
- } ) ;
43
+ return res . status ( 200 ) . json ( {
44
+ success : true ,
45
+ message : "Pair's Contract and Package Hash are Succefully stored." ,
46
+ } ) ;
47
+ } else {
48
+ return res . status ( 406 ) . json ( {
49
+ success : false ,
50
+ message : "These Pair's Contract and Package Hash are already added." ,
51
+ } ) ;
52
+ }
42
53
} catch ( error ) {
43
54
console . log ( "error (try-catch) : " + error ) ;
44
55
return res . status ( 500 ) . json ( {
@@ -67,16 +78,27 @@ router
67
78
68
79
let contractHash = req . body . contractHash . toLowerCase ( ) ;
69
80
let packageHash = req . body . packageHash . toLowerCase ( ) ;
70
- var newpair = new allcontractsDataModel ( {
81
+ let contractsData = await allcontractsDataModel . findOne ( {
71
82
contractHash : contractHash ,
72
83
packageHash : packageHash ,
73
84
} ) ;
74
- await allcontractsDataModel . create ( newpair ) ;
85
+ if ( contractsData == null ) {
86
+ var newpair = new allcontractsDataModel ( {
87
+ contractHash : contractHash ,
88
+ packageHash : packageHash ,
89
+ } ) ;
90
+ await allcontractsDataModel . create ( newpair ) ;
75
91
76
- return res . status ( 200 ) . json ( {
77
- success : true ,
78
- message : "Contract and Package Hash are Succefully stored." ,
79
- } ) ;
92
+ return res . status ( 200 ) . json ( {
93
+ success : true ,
94
+ message : "Contract and Package Hash are Succefully stored." ,
95
+ } ) ;
96
+ } else {
97
+ return res . status ( 406 ) . json ( {
98
+ success : false ,
99
+ message : "These Contract and Package Hash are already stored." ,
100
+ } ) ;
101
+ }
80
102
} catch ( error ) {
81
103
console . log ( "error (try-catch) : " + error ) ;
82
104
return res . status ( 500 ) . json ( {
@@ -96,15 +118,23 @@ router
96
118
message : "tokensList not found in the request Body." ,
97
119
} ) ;
98
120
}
99
- let newData = new tokensListModel ( {
100
- data : req . body . tokensList ,
101
- } ) ;
102
- await tokensListModel . create ( newData ) ;
121
+ let result = await tokensListModel . find ( { } ) ;
122
+ if ( result . length == 0 ) {
123
+ let newData = new tokensListModel ( {
124
+ data : req . body . tokensList ,
125
+ } ) ;
126
+ await tokensListModel . create ( newData ) ;
103
127
104
- return res . status ( 200 ) . json ( {
105
- success : true ,
106
- message : "Token List Data SuccessFully Saved." ,
107
- } ) ;
128
+ return res . status ( 200 ) . json ( {
129
+ success : true ,
130
+ message : "Token List Data SuccessFully added." ,
131
+ } ) ;
132
+ } else {
133
+ return res . status ( 406 ) . json ( {
134
+ success : false ,
135
+ message : "Tokens List Data already added." ,
136
+ } ) ;
137
+ }
108
138
} catch ( error ) {
109
139
console . log ( "error (try-catch) : " + error ) ;
110
140
return res . status ( 500 ) . json ( {
0 commit comments