1
+ const testData = [ {
2
+ Categories : "Participants" ,
3
+ "Company/Organization" : null ,
4
+ Date : null ,
5
+
6
+ "First Name" : "JUNAIDU" ,
7
+ "Institutional Affiliation" : null ,
8
+ "Last Name" : "SALISU" ,
9
+ "Phone Number" : null
10
+ } , {
11
+ Categories : "Participants" ,
12
+ "Company/Organization" : null ,
13
+ Date : null ,
14
+
15
+ "First Name" : "JUNAIDU" ,
16
+ "Institutional Affiliation" : null ,
17
+ "Last Name" : "SALISU" ,
18
+ "Phone Number" : null
19
+ } , {
20
+ Categories : "Participants" ,
21
+ "Company/Organization" : null ,
22
+ Date : null ,
23
+
24
+ "First Name" : "JUNAIDU" ,
25
+ "Institutional Affiliation" : null ,
26
+ "Last Name" : "SALISU" ,
27
+ "Phone Number" : null
28
+ } ] ;
1
29
2
- const looper = ( ) => {
3
- let count = 0 ;
4
- const setting = setInterval ( function ( ) {
5
- if ( count >= 2 ) {
6
- console . log ( "ended" )
7
- clearInterval ( setting )
8
- }
9
- else {
10
- console . log ( "Time Interval" )
11
- count ++ ;
12
- }
13
- } , 1000 * 2 ) ;
14
- } ;
30
+ // fetch('http://localhost:3000/api/v1/emails', {
31
+ // method: 'POST',
32
+ // mode: 'no-cors',
33
+ // headers: {
34
+ // 'Content-Type': 'application/json',
35
+ // },
36
+ // body: JSON.stringify({
37
+ // "email" : testData[0].Email,
38
+ // "name" : `${testData[0]["Last Name"]} ${testData[0]["First Name"]}`,
39
+ // "category" : testData[0].Categories
40
+ // }),
41
+ // })
42
+ // .then((response) => response.json())
43
+ // .then((data) => {
44
+ // console.log('success: ', data);
45
+ // })
46
+
47
+ // async function postData(url = '', data = {}) {
48
+ // // Default options are marked with *
49
+ // const response = await fetch(url, {
50
+ // method: 'POST',
51
+ // mode: 'no-cors',
52
+ // cache: 'no-cache',
53
+ // credentials: 'same-origin',
54
+ // headers: {
55
+ // 'Content-Type': 'application/json',
56
+
57
+ // },
58
+
59
+ // body: JSON.stringify(data) // body data type must match "Content-Type" header
60
+ // });
61
+ // return response.text();// parses JSON response into native JavaScript objects
62
+ // }
63
+
64
+ // postData('http://localhost:3000/api/v1/emails', {
65
+ // "email" : testData[0].Email,
66
+ // "name" : `${testData[0]["Last Name"]} ${testData[0]["First Name"]}`,
67
+ // "category" : testData[0].Categories
68
+ // })
69
+ // .then((data) => {
70
+ // console.log(JSON.parse(data));
71
+ // });
15
72
16
- looper ( ) ;
73
+ const looper = async ( data ) => {
74
+
75
+ for ( let x = 733 ; x < data . length ; x ++ ) {
17
76
18
- fetch ( 'https://sheet.best/api/sheets/5f05d562-cf94-492b-aac8-195d3c57ec67' )
19
- . then ( ( res ) => ( res . json ( ) ) )
20
- . then ( ( data ) => {
21
- console . log ( data )
77
+
78
+ await fetch ( 'http://localhost:3000/api/v1/emails' , {
79
+ method : 'POST' ,
80
+ headers : {
81
+ 'Content-Type' : 'application/json' ,
82
+ } ,
83
+ body : JSON . stringify ( {
84
+ "email" : data [ x ] . Email ,
85
+ "name" : `${ data [ x ] [ "Last Name" ] } ${ data [ x ] [ "First Name" ] } ` ,
86
+ "category" : data [ x ] . Categories
87
+ } ) ,
88
+ } )
89
+ . then ( ( response ) => response . json ( ) )
90
+ . then ( ( data ) => {
91
+ console . log ( x )
92
+ console . log ( 'success: ' , data ) ;
93
+ } )
94
+ . catch ( ( error ) => {
95
+ console . error ( 'Error: ' , error ) ;
96
+ } ) ;
97
+ }
98
+ } ;
22
99
23
- } )
100
+ //looper(testData);
101
+ // console.log("Its working at this put")
102
+ // fetch('https://sheet.best/api/sheets/7d520258-c5f2-4cc6-8644-436ff5e3e6c5')
103
+ // .then((res) => (res.json()))
104
+ // .then((data) => {
105
+ // console.log(data)
106
+ // looper(data);
107
+ // })
0 commit comments