-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCRUD.js
68 lines (68 loc) · 2.9 KB
/
CRUD.js
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
62
63
64
65
66
67
68
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
export class CRUD {
fetchData() {
let fetchfn = () => __awaiter(this, void 0, void 0, function* () { return yield fetch('https://localhost:7113/api/My').then(response => response.json()).catch(err => console.log()); });
return fetchfn();
}
fetchDataWithId(id) {
let fetchfn = () => __awaiter(this, void 0, void 0, function* () { return yield fetch(`https://localhost:7113/api/My/${id}`).then(response => response.json()).catch(err => console.log()); });
return fetchfn();
}
postData(item) {
let pushObj = {
Name: item.Name,
email: item.email,
phone: item.phone,
landline: item.landline,
website: item.website,
address: item.address
};
let postfn = () => __awaiter(this, void 0, void 0, function* () {
return yield fetch('https://localhost:7113/api/My', {
method: 'POST',
headers: {
'Content-type': 'application/json; charset=UTF-8'
},
body: JSON.stringify(pushObj)
});
});
postfn();
}
updateData(id, contact) {
//console.log(`value received: ${contact.Name},${contact.email}, ${contact.phone}`);
let putfn = () => __awaiter(this, void 0, void 0, function* () {
return yield 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) {
let delRecord = () => __awaiter(this, void 0, void 0, function* () {
return yield fetch(`https://localhost:7113/api/My/${id}`, {
method: 'DELETE'
});
});
delRecord();
}
}