-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCRUD.ts
61 lines (54 loc) · 1.86 KB
/
CRUD.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { DataModel } from "./DataModel.js";
export class CRUD{
fetchData():any{
let fetchfn=async ()=> await fetch('https://localhost:7113/api/My').then(response=>response.json()).catch(err=> console.log());
return fetchfn();
}
fetchDataWithId(id:any):any{
let fetchfn=async ()=> await fetch(`https://localhost:7113/api/My/${id}`).then(response=>response.json()).catch(err=>console.log());
return fetchfn();
}
postData(item:DataModel):void{
let pushObj={
Name:item.Name,
email:item.email,
phone:item.phone,
landline:item.landline,
website:item.website,
address:item.address
}
let postfn= async() => await fetch('https://localhost:7113/api/My',{
method:'POST',
headers:{
'Content-type':'application/json; charset=UTF-8'
},
body:JSON.stringify(pushObj)
})
postfn();
}
updateData(id:number,contact:DataModel):void{
//console.log(`value received: ${contact.Name},${contact.email}, ${contact.phone}`);
let putfn= async ()=> await fetch(`https://localhost:7113/api/My/${id}`,{
method:'PUT',
headers:{
'Content-type':'application/json; charset=UTF-8'
},
body:JSON.stringify({
// id:id,
name:contact.Name,
email:contact.email,
phone:contact.phone,
landline:contact.landline,
website:contact.website,
address:contact.address
})
}).then(res=>res.json()).catch(err=>console.log());
putfn();
}
deleteData(id:number):void{
let delRecord=async ()=>await fetch(`https://localhost:7113/api/My/${id}`,{
method:'DELETE'
})
delRecord();
}
}