jitz-sharepoint-utilities 2.0.14 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common/IModels.d.ts +40 -0
- package/lib/common/IModels.js +2 -0
- package/lib/common/IObjects.d.ts +72 -0
- package/lib/common/IObjects.js +30 -0
- package/lib/controls/JitzGrid.d.ts +75 -0
- package/lib/controls/JitzGrid.js +606 -0
- package/lib/controls/JitzImage.d.ts +14 -0
- package/lib/controls/JitzImage.js +37 -0
- package/lib/controls/JitzPeoplePicker.d.ts +49 -0
- package/lib/controls/JitzPeoplePicker.js +311 -0
- package/lib/controls/JitzPersonInfo.d.ts +32 -0
- package/lib/controls/JitzPersonInfo.js +98 -0
- package/lib/controls/JitzPersona.d.ts +23 -0
- package/lib/controls/JitzPersona.js +48 -0
- package/lib/data/context/CommonRepository.d.ts +17 -0
- package/lib/data/context/CommonRepository.js +287 -0
- package/lib/data/context/JitzContext.d.ts +13 -0
- package/lib/data/context/JitzContext.js +80 -0
- package/lib/data/context/JitzSPContext.d.ts +8 -0
- package/lib/data/context/JitzSPContext.js +58 -0
- package/lib/data/context/JitzSPHttpClient.d.ts +14 -0
- package/lib/data/context/JitzSPHttpClient.js +173 -0
- package/lib/data/context/List.d.ts +39 -0
- package/lib/data/context/List.js +492 -0
- package/lib/data/context/Repository.d.ts +22 -0
- package/lib/data/context/Repository.js +486 -0
- package/lib/data/interfaces/ICommonRepository.d.ts +6 -0
- package/lib/data/interfaces/ICommonRepository.js +2 -0
- package/lib/data/interfaces/IJitzContext.d.ts +10 -0
- package/lib/data/interfaces/IJitzContext.js +2 -0
- package/lib/data/interfaces/IJitzSPContext.d.ts +6 -0
- package/lib/data/interfaces/IJitzSPContext.js +2 -0
- package/lib/data/interfaces/IJitzSPHttpClient.d.ts +6 -0
- package/lib/data/interfaces/IJitzSPHttpClient.js +2 -0
- package/lib/data/interfaces/IList.d.ts +26 -0
- package/lib/data/interfaces/IList.js +2 -0
- package/lib/data/interfaces/IModels.d.ts +32 -0
- package/lib/data/interfaces/IModels.js +2 -0
- package/lib/data/interfaces/IRepository.d.ts +17 -0
- package/lib/data/interfaces/IRepository.js +2 -0
- package/lib/jitzHttpClient.d.ts +11 -0
- package/lib/jitzHttpClient.js +37 -0
- package/lib/jitzSPHttpClient.d.ts +30 -0
- package/lib/jitzSPHttpClient.js +193 -0
- package/lib/repositories/CommonRepository.d.ts +17 -0
- package/lib/repositories/CommonRepository.js +287 -0
- package/lib/repositories/ICommonRepository.d.ts +6 -0
- package/lib/repositories/ICommonRepository.js +2 -0
- package/lib/repositories/IRepository.d.ts +13 -0
- package/lib/repositories/IRepository.js +2 -0
- package/lib/repositories/Repository.d.ts +18 -0
- package/lib/repositories/Repository.js +392 -0
- package/lib/services/GraphService.d.ts +10 -0
- package/lib/services/GraphService.js +103 -0
- package/lib/services/UserService.d.ts +15 -0
- package/lib/services/UserService.js +202 -0
- package/lib/services/UtilityService.d.ts +29 -0
- package/lib/services/UtilityService.js +254 -0
- package/package.json +1 -1
@@ -0,0 +1,486 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
+
function step(op) {
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
+
switch (op[0]) {
|
21
|
+
case 0: case 1: t = op; break;
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
+
default:
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
+
if (t[2]) _.ops.pop();
|
31
|
+
_.trys.pop(); continue;
|
32
|
+
}
|
33
|
+
op = body.call(thisArg, _);
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
+
}
|
37
|
+
};
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
+
var UtilityService_1 = require("../../services/UtilityService");
|
40
|
+
var Repository = /** @class */ (function () {
|
41
|
+
function Repository(context, listName, listGuid) {
|
42
|
+
if (listGuid === void 0) { listGuid = ""; }
|
43
|
+
this.context = context;
|
44
|
+
this.listName = listName;
|
45
|
+
this.listGuid = listGuid;
|
46
|
+
this.listUrl = "".concat(this.context.siteUrl, "/_api/web/lists").concat(this.listGuid == ""
|
47
|
+
? "/GetByTitle('" + this.listName + "')"
|
48
|
+
: "(guid'" + this.listGuid + "')");
|
49
|
+
}
|
50
|
+
Repository.prototype.getAll = function (selectFields, expand, filters, orderBy, top, skip, skipTokenUniqueField, skipTokenUniqueFieldValue) {
|
51
|
+
var queryUrlGetAllItems = "".concat(this.listUrl, "/items");
|
52
|
+
if (selectFields != null && selectFields != "") {
|
53
|
+
queryUrlGetAllItems = queryUrlGetAllItems + "?$select=" + selectFields;
|
54
|
+
}
|
55
|
+
else {
|
56
|
+
queryUrlGetAllItems = queryUrlGetAllItems + "?$select=*";
|
57
|
+
}
|
58
|
+
if (orderBy != null && orderBy != "") {
|
59
|
+
queryUrlGetAllItems = queryUrlGetAllItems + "&$orderby=" + orderBy;
|
60
|
+
}
|
61
|
+
if (skip != null && skip != undefined && skip > 0) {
|
62
|
+
queryUrlGetAllItems = queryUrlGetAllItems + "&$skip=" + skip;
|
63
|
+
}
|
64
|
+
if (top != null && top != undefined && top > 0) {
|
65
|
+
queryUrlGetAllItems = queryUrlGetAllItems + "&$top=" + top;
|
66
|
+
}
|
67
|
+
if (expand != null && expand != "") {
|
68
|
+
queryUrlGetAllItems = queryUrlGetAllItems + "&$expand=" + expand;
|
69
|
+
}
|
70
|
+
if (filters != null && filters != "") {
|
71
|
+
queryUrlGetAllItems = queryUrlGetAllItems + "&$filter=" + filters;
|
72
|
+
}
|
73
|
+
if (skipTokenUniqueField != null &&
|
74
|
+
skipTokenUniqueField != undefined &&
|
75
|
+
skipTokenUniqueFieldValue != null &&
|
76
|
+
skipTokenUniqueFieldValue != undefined) {
|
77
|
+
if (skipTokenUniqueField == "Id" || skipTokenUniqueField == "id") {
|
78
|
+
skipTokenUniqueField = "ID";
|
79
|
+
}
|
80
|
+
queryUrlGetAllItems =
|
81
|
+
queryUrlGetAllItems +
|
82
|
+
"&$skiptoken=Paged=TRUE%26p_".concat(skipTokenUniqueField, "=").concat(skipTokenUniqueFieldValue);
|
83
|
+
}
|
84
|
+
return this.context.client
|
85
|
+
.get(queryUrlGetAllItems)
|
86
|
+
.then(function (response) {
|
87
|
+
if (response.status >= 200 && response.status < 300) {
|
88
|
+
return response.data.d;
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
return Promise.reject(new Error(JSON.stringify(response)));
|
92
|
+
}
|
93
|
+
})
|
94
|
+
.then(function (data) {
|
95
|
+
// let items: T[] = [];
|
96
|
+
// if (data) {
|
97
|
+
// for (let i = 0; i < data.length; i++) {
|
98
|
+
// let item = data[i];
|
99
|
+
// items.push(item);
|
100
|
+
// }
|
101
|
+
// }
|
102
|
+
return data;
|
103
|
+
})
|
104
|
+
.catch(function (ex) {
|
105
|
+
console.log("load Items > JitzSPHttpClient.get()...catch:", ex);
|
106
|
+
throw ex;
|
107
|
+
});
|
108
|
+
};
|
109
|
+
Repository.prototype.getAllFromUrl = function (url) {
|
110
|
+
return this.context.client
|
111
|
+
.get(url)
|
112
|
+
.then(function (response) {
|
113
|
+
if (response.status >= 200 && response.status < 300) {
|
114
|
+
return response.data.d;
|
115
|
+
}
|
116
|
+
else {
|
117
|
+
return Promise.reject(new Error(JSON.stringify(response)));
|
118
|
+
}
|
119
|
+
})
|
120
|
+
.then(function (data) {
|
121
|
+
// let items: T[] = [];
|
122
|
+
// if (data) {
|
123
|
+
// for (let i = 0; i < data.length; i++) {
|
124
|
+
// let item = data[i];
|
125
|
+
// items.push(item);
|
126
|
+
// }
|
127
|
+
// }
|
128
|
+
return data;
|
129
|
+
})
|
130
|
+
.catch(function (ex) {
|
131
|
+
console.log("load Items > JitzSPHttpClient.get()...catch:", ex);
|
132
|
+
throw ex;
|
133
|
+
});
|
134
|
+
};
|
135
|
+
Repository.prototype.getAllRecursive = function (selectFields_1, expand_1, filters_1, orderBy_1, top_1) {
|
136
|
+
return __awaiter(this, arguments, void 0, function (selectFields, expand, filters, orderBy, top, maxRecursiveCount) {
|
137
|
+
var items, queryUrlGetAllItems;
|
138
|
+
var _this = this;
|
139
|
+
if (maxRecursiveCount === void 0) { maxRecursiveCount = 5; }
|
140
|
+
return __generator(this, function (_a) {
|
141
|
+
switch (_a.label) {
|
142
|
+
case 0:
|
143
|
+
items = [];
|
144
|
+
queryUrlGetAllItems = "".concat(this.listUrl, "/items");
|
145
|
+
if (selectFields != null && selectFields != "") {
|
146
|
+
queryUrlGetAllItems = queryUrlGetAllItems + "?$select=" + selectFields;
|
147
|
+
}
|
148
|
+
else {
|
149
|
+
queryUrlGetAllItems = queryUrlGetAllItems + "?$select=*";
|
150
|
+
}
|
151
|
+
if (expand != null && expand != "") {
|
152
|
+
queryUrlGetAllItems = queryUrlGetAllItems + "&$expand=" + expand;
|
153
|
+
}
|
154
|
+
if (filters != null && filters != "") {
|
155
|
+
queryUrlGetAllItems = queryUrlGetAllItems + "&$filter=" + filters;
|
156
|
+
}
|
157
|
+
if (orderBy != null && orderBy != "") {
|
158
|
+
queryUrlGetAllItems = queryUrlGetAllItems + "&$orderby=" + orderBy;
|
159
|
+
}
|
160
|
+
if (top != null && top != undefined && top > 0) {
|
161
|
+
queryUrlGetAllItems = queryUrlGetAllItems + "&$top=" + top;
|
162
|
+
}
|
163
|
+
return [4 /*yield*/, this.context.client
|
164
|
+
.get(queryUrlGetAllItems)
|
165
|
+
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
166
|
+
return __generator(this, function (_a) {
|
167
|
+
switch (_a.label) {
|
168
|
+
case 0:
|
169
|
+
if (!(response.status >= 200 && response.status < 300)) return [3 /*break*/, 2];
|
170
|
+
return [4 /*yield*/, response.data.d];
|
171
|
+
case 1: return [2 /*return*/, _a.sent()];
|
172
|
+
case 2: return [2 /*return*/, Promise.reject(new Error(JSON.stringify(response)))];
|
173
|
+
}
|
174
|
+
});
|
175
|
+
}); })
|
176
|
+
.then(function (data) { return __awaiter(_this, void 0, void 0, function () {
|
177
|
+
var i, item, returnItem;
|
178
|
+
return __generator(this, function (_a) {
|
179
|
+
switch (_a.label) {
|
180
|
+
case 0:
|
181
|
+
if (data.results) {
|
182
|
+
for (i = 0; i < data.results.length; i++) {
|
183
|
+
item = data.results[i];
|
184
|
+
items.push(item);
|
185
|
+
}
|
186
|
+
}
|
187
|
+
returnItem = {
|
188
|
+
__next: data.__next,
|
189
|
+
results: items,
|
190
|
+
};
|
191
|
+
if (!(returnItem.__next != undefined && returnItem.__next.length > 0)) return [3 /*break*/, 2];
|
192
|
+
return [4 /*yield*/, this.recursiveFetch(returnItem.__next, 2, maxRecursiveCount, returnItem.results)];
|
193
|
+
case 1:
|
194
|
+
items = _a.sent();
|
195
|
+
_a.label = 2;
|
196
|
+
case 2: return [2 /*return*/];
|
197
|
+
}
|
198
|
+
});
|
199
|
+
}); })
|
200
|
+
.catch(function (ex) {
|
201
|
+
console.log("load Items > JitzSPHttpClient.get()...catch:", ex);
|
202
|
+
throw ex;
|
203
|
+
})];
|
204
|
+
case 1:
|
205
|
+
_a.sent();
|
206
|
+
return [2 /*return*/, items];
|
207
|
+
}
|
208
|
+
});
|
209
|
+
});
|
210
|
+
};
|
211
|
+
Repository.prototype.recursiveFetch = function (url_1) {
|
212
|
+
return __awaiter(this, arguments, void 0, function (url, recursiveCount, maxRecursiveCount, items) {
|
213
|
+
var _this = this;
|
214
|
+
if (recursiveCount === void 0) { recursiveCount = 1; }
|
215
|
+
if (maxRecursiveCount === void 0) { maxRecursiveCount = 5; }
|
216
|
+
if (items === void 0) { items = []; }
|
217
|
+
return __generator(this, function (_a) {
|
218
|
+
switch (_a.label) {
|
219
|
+
case 0:
|
220
|
+
items = items || [];
|
221
|
+
return [4 /*yield*/, this.context.client
|
222
|
+
.get(url)
|
223
|
+
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
224
|
+
return __generator(this, function (_a) {
|
225
|
+
switch (_a.label) {
|
226
|
+
case 0:
|
227
|
+
if (!(response.status >= 200 && response.status < 300)) return [3 /*break*/, 2];
|
228
|
+
return [4 /*yield*/, response.data.d];
|
229
|
+
case 1: return [2 /*return*/, _a.sent()];
|
230
|
+
case 2: return [2 /*return*/, Promise.reject(new Error(JSON.stringify(response)))];
|
231
|
+
}
|
232
|
+
});
|
233
|
+
}); })
|
234
|
+
.then(function (data) { return __awaiter(_this, void 0, void 0, function () {
|
235
|
+
var i, item, returnItem;
|
236
|
+
return __generator(this, function (_a) {
|
237
|
+
switch (_a.label) {
|
238
|
+
case 0:
|
239
|
+
if (data.results) {
|
240
|
+
for (i = 0; i < data.results.length; i++) {
|
241
|
+
item = data.results[i];
|
242
|
+
items.push(item);
|
243
|
+
}
|
244
|
+
}
|
245
|
+
returnItem = {
|
246
|
+
__next: data.__next,
|
247
|
+
results: items,
|
248
|
+
};
|
249
|
+
if (!(returnItem.__next != undefined &&
|
250
|
+
returnItem.__next.length > 0 &&
|
251
|
+
recursiveCount < maxRecursiveCount)) return [3 /*break*/, 2];
|
252
|
+
return [4 /*yield*/, this.recursiveFetch(returnItem.__next, recursiveCount + 1, maxRecursiveCount, returnItem.results)];
|
253
|
+
case 1:
|
254
|
+
items = _a.sent();
|
255
|
+
_a.label = 2;
|
256
|
+
case 2: return [2 /*return*/];
|
257
|
+
}
|
258
|
+
});
|
259
|
+
}); })
|
260
|
+
.catch(function (ex) {
|
261
|
+
console.log("load Items > JitzSPHttpClient.get()...catch:", ex);
|
262
|
+
// throw ex; //Let it continue
|
263
|
+
})];
|
264
|
+
case 1:
|
265
|
+
_a.sent();
|
266
|
+
return [2 /*return*/, items];
|
267
|
+
}
|
268
|
+
});
|
269
|
+
});
|
270
|
+
};
|
271
|
+
Repository.prototype.itemsCount = function (filters) {
|
272
|
+
var queryUrlGetAllItems = "".concat(this.listUrl, "/ItemCount");
|
273
|
+
if (filters != null && filters != "") {
|
274
|
+
queryUrlGetAllItems = queryUrlGetAllItems + "?$filter=" + filters;
|
275
|
+
}
|
276
|
+
return this.context.client
|
277
|
+
.get(queryUrlGetAllItems)
|
278
|
+
.then(function (response) {
|
279
|
+
if (response.status >= 200 && response.status < 300) {
|
280
|
+
return response.data.d.ItemCount;
|
281
|
+
}
|
282
|
+
else {
|
283
|
+
return Promise.reject(new Error(JSON.stringify(response)));
|
284
|
+
}
|
285
|
+
})
|
286
|
+
.then(function (data) {
|
287
|
+
return data;
|
288
|
+
})
|
289
|
+
.catch(function (ex) {
|
290
|
+
console.log("loadEvents > JitzSPHttpClient.get()...catch:", ex);
|
291
|
+
throw ex;
|
292
|
+
});
|
293
|
+
};
|
294
|
+
Repository.prototype.getItemById = function (id, selectFields, expand) {
|
295
|
+
return __awaiter(this, void 0, void 0, function () {
|
296
|
+
var queryUrl;
|
297
|
+
return __generator(this, function (_a) {
|
298
|
+
switch (_a.label) {
|
299
|
+
case 0:
|
300
|
+
queryUrl = "".concat(this.listUrl, "/items(") +
|
301
|
+
id +
|
302
|
+
")" +
|
303
|
+
"?$select=*".concat(selectFields != undefined ? ",".concat(selectFields) : "") +
|
304
|
+
"".concat(expand != undefined ? "&$expand=".concat(expand) : "");
|
305
|
+
return [4 /*yield*/, this.context.client
|
306
|
+
.get(queryUrl)
|
307
|
+
.then(function (response) {
|
308
|
+
if (response.status >= 200 && response.status < 300) {
|
309
|
+
return response.data.d;
|
310
|
+
}
|
311
|
+
else {
|
312
|
+
return Promise.reject(new Error(JSON.stringify(response)));
|
313
|
+
}
|
314
|
+
})
|
315
|
+
.then(function (data) {
|
316
|
+
return data;
|
317
|
+
})
|
318
|
+
.catch(function (ex) {
|
319
|
+
console.log("loadEvents > JitzSPHttpClient.get()...catch:", ex);
|
320
|
+
throw ex;
|
321
|
+
})];
|
322
|
+
case 1: return [2 /*return*/, _a.sent()];
|
323
|
+
}
|
324
|
+
});
|
325
|
+
});
|
326
|
+
};
|
327
|
+
Repository.prototype.createItem = function (item) {
|
328
|
+
var _this = this;
|
329
|
+
return this.getEntityType().then(function (entityType) {
|
330
|
+
item.__metadata = {
|
331
|
+
type: entityType,
|
332
|
+
};
|
333
|
+
var requestUrl = "".concat(_this.listUrl, "/items");
|
334
|
+
return _this.context.client
|
335
|
+
.post(requestUrl, item, {
|
336
|
+
Accept: "application/json;odata=nometadata",
|
337
|
+
"Content-type": "application/json;odata=verbose",
|
338
|
+
"odata-version": "",
|
339
|
+
})
|
340
|
+
.then(function (response) {
|
341
|
+
if (response.status >= 200 && response.status < 300) {
|
342
|
+
var json = response.data.d;
|
343
|
+
return json;
|
344
|
+
}
|
345
|
+
else {
|
346
|
+
return Promise.reject(new Error(JSON.stringify(response)));
|
347
|
+
}
|
348
|
+
});
|
349
|
+
});
|
350
|
+
};
|
351
|
+
Repository.prototype.updateItem = function (item) {
|
352
|
+
var _this = this;
|
353
|
+
return this.getEntityType().then(function (entityType) {
|
354
|
+
item.__metadata = {
|
355
|
+
//etag: "1",
|
356
|
+
type: entityType,
|
357
|
+
};
|
358
|
+
var requestUrl = "".concat(_this.listUrl, "/items(").concat(item.Id, ")");
|
359
|
+
return _this.context.client
|
360
|
+
.post(requestUrl, item, {
|
361
|
+
Accept: "application/json;odata=nometadata",
|
362
|
+
"Content-type": "application/json;odata=verbose",
|
363
|
+
"odata-version": "",
|
364
|
+
"IF-MATCH": "*",
|
365
|
+
"X-HTTP-Method": "MERGE",
|
366
|
+
})
|
367
|
+
.then(function (response) {
|
368
|
+
if (response.status >= 200 && response.status < 300) {
|
369
|
+
return item;
|
370
|
+
}
|
371
|
+
else {
|
372
|
+
// console.log(JSON.stringify(response));
|
373
|
+
return Promise.reject(new Error(JSON.stringify(response)));
|
374
|
+
}
|
375
|
+
});
|
376
|
+
});
|
377
|
+
};
|
378
|
+
Repository.prototype.deleteItem = function (id) {
|
379
|
+
var requestUrl = "".concat(this.listUrl, "/items(").concat(id, ")");
|
380
|
+
return this.context.client
|
381
|
+
.post(requestUrl, {}, {
|
382
|
+
Accept: "application/json;odata=nometadata",
|
383
|
+
"Content-type": "application/json;odata=verbose",
|
384
|
+
"odata-version": "",
|
385
|
+
"IF-MATCH": "*",
|
386
|
+
"X-HTTP-Method": "DELETE",
|
387
|
+
})
|
388
|
+
.then(function (response) {
|
389
|
+
if (response.status >= 200 && response.status < 300) {
|
390
|
+
return true;
|
391
|
+
}
|
392
|
+
else {
|
393
|
+
return Promise.reject(new Error(JSON.stringify(response)));
|
394
|
+
}
|
395
|
+
});
|
396
|
+
};
|
397
|
+
Repository.prototype.deleteItems = function (ids) {
|
398
|
+
var _this = this;
|
399
|
+
// Here we will delete two different list items from two different lists in a single REST call
|
400
|
+
// Every batch will have a Batch ID/GUID
|
401
|
+
var batchGuid = UtilityService_1.default.generateGUID();
|
402
|
+
// Every delete/changeset should have a ChangeSet ID/GUID
|
403
|
+
var changeSetGUID = UtilityService_1.default.generateGUID()();
|
404
|
+
// creating the body
|
405
|
+
var batchContents = new Array();
|
406
|
+
ids.map(function (id) {
|
407
|
+
// Request creation for first list item Delete
|
408
|
+
var endpoint = "".concat(_this.listUrl, "/items(").concat(id, ")");
|
409
|
+
// create the changeset
|
410
|
+
batchContents.push("--changeset_" + changeSetGUID);
|
411
|
+
batchContents.push("Content-Type: application/http");
|
412
|
+
batchContents.push("Content-Transfer-Encoding: binary");
|
413
|
+
batchContents.push("");
|
414
|
+
batchContents.push("DELETE " + endpoint + " HTTP/1.1");
|
415
|
+
batchContents.push("Content-Type: application/json;odata=verbose");
|
416
|
+
batchContents.push("Accept: application/json;odata=verbose");
|
417
|
+
batchContents.push("IF-MATCH: *");
|
418
|
+
batchContents.push("");
|
419
|
+
});
|
420
|
+
batchContents.push("--changeset_" + changeSetGUID + "--");
|
421
|
+
// batch body
|
422
|
+
var batchBody = batchContents.join("\r\n");
|
423
|
+
batchContents = new Array();
|
424
|
+
// create a batch for creating items
|
425
|
+
batchContents.push("--batch_" + batchGuid);
|
426
|
+
batchContents.push('Content-Type: multipart/mixed; boundary="changeset_' +
|
427
|
+
changeSetGUID +
|
428
|
+
'"');
|
429
|
+
batchContents.push("Content-Length: " + batchBody.length);
|
430
|
+
batchContents.push("Content-Transfer-Encoding: binary");
|
431
|
+
batchContents.push("");
|
432
|
+
batchContents.push(batchBody);
|
433
|
+
batchContents.push("");
|
434
|
+
batchContents.push("--batch_" + batchGuid + "--");
|
435
|
+
batchBody = batchContents.join("\r\n");
|
436
|
+
// create the request endpoint
|
437
|
+
var batchEndPoint = "".concat(this.context.siteUrl, "/_api/$batch");
|
438
|
+
// // create request
|
439
|
+
// jQuery.ajax({
|
440
|
+
// url: endpoint,
|
441
|
+
// type: 'POST',
|
442
|
+
// headers: batchRequestHeader,
|
443
|
+
// data: batchBody,
|
444
|
+
// success: function (response) {
|
445
|
+
// console.log(response);
|
446
|
+
// },
|
447
|
+
// fail: function (error) {
|
448
|
+
// console.log(response);
|
449
|
+
// }
|
450
|
+
// });
|
451
|
+
return this.context.client
|
452
|
+
.post(batchEndPoint, batchBody, {
|
453
|
+
"Content-Type": 'multipart/mixed; boundary="batch_' + batchGuid + '"',
|
454
|
+
})
|
455
|
+
.then(function (response) {
|
456
|
+
if (response.status >= 200 && response.status < 300) {
|
457
|
+
return true;
|
458
|
+
}
|
459
|
+
else {
|
460
|
+
return Promise.reject(new Error(JSON.stringify(response)));
|
461
|
+
}
|
462
|
+
});
|
463
|
+
};
|
464
|
+
Repository.prototype.getEntityType = function () {
|
465
|
+
var _this = this;
|
466
|
+
return new Promise(function (resolve, reject) {
|
467
|
+
if (_this._listEntityType) {
|
468
|
+
resolve(_this._listEntityType);
|
469
|
+
return;
|
470
|
+
}
|
471
|
+
_this.context.client
|
472
|
+
.get("".concat(_this.listUrl, "?$select=ListItemEntityTypeFullName"))
|
473
|
+
.then(function (response) {
|
474
|
+
return response;
|
475
|
+
}, function (error) {
|
476
|
+
reject(error);
|
477
|
+
})
|
478
|
+
.then(function (response) {
|
479
|
+
_this._listEntityType = response.data.d.ListItemEntityTypeFullName;
|
480
|
+
resolve(_this._listEntityType || "");
|
481
|
+
});
|
482
|
+
});
|
483
|
+
};
|
484
|
+
return Repository;
|
485
|
+
}());
|
486
|
+
exports.default = Repository;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { WebPartContext } from "@microsoft/sp-webpart-base";
|
2
|
+
import IJitzSPContext from "./IJitzSPContext";
|
3
|
+
import { MSGraphClientV3 } from "@microsoft/sp-http";
|
4
|
+
export default interface IJitzContext {
|
5
|
+
spContext: IJitzSPContext;
|
6
|
+
webpartContext: WebPartContext;
|
7
|
+
graphClient: MSGraphClientV3;
|
8
|
+
siteId: string;
|
9
|
+
init: () => void;
|
10
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { IModel } from "./IModels";
|
2
|
+
import IJitzContext from "../interfaces/IJitzContext";
|
3
|
+
import { IRepository } from "./IRepository";
|
4
|
+
export interface IList<T extends IModel> {
|
5
|
+
context: IJitzContext;
|
6
|
+
listName: string;
|
7
|
+
repository: IRepository<T>;
|
8
|
+
getItems(filter?: string, orderby?: string, top?: number, skip?: number): Promise<T[]>;
|
9
|
+
loadMore(): Promise<T[]>;
|
10
|
+
getItemById(id: number): Promise<T>;
|
11
|
+
getItemsRecursive(filters?: string, orderby?: string, top?: number, maxRecursiveCount?: number): Promise<T[]>;
|
12
|
+
getItemsCount(filters?: string): Promise<number>;
|
13
|
+
create(item: T): Promise<T>;
|
14
|
+
update(item: T): Promise<T>;
|
15
|
+
delete(id: number): Promise<boolean>;
|
16
|
+
getItemsIndexed(filterQuery?: string, orderby?: string, top?: number): Promise<T[]>;
|
17
|
+
loadMoreIndexed(): Promise<T[]>;
|
18
|
+
getItemsIndexedRecursive(filterQuery?: string): Promise<T[]>;
|
19
|
+
_nextPageLink?: string;
|
20
|
+
top: number;
|
21
|
+
indexLimit: number;
|
22
|
+
upperId: number;
|
23
|
+
lowerId: number;
|
24
|
+
filters?: string;
|
25
|
+
orderBy?: string;
|
26
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
export interface IModel {
|
2
|
+
Id?: number;
|
3
|
+
Title?: string;
|
4
|
+
AuthorId?: number;
|
5
|
+
Author?: IPersonOrGroup;
|
6
|
+
__metadata?: {};
|
7
|
+
}
|
8
|
+
export interface IListItemsMetadata<T> {
|
9
|
+
__next?: string;
|
10
|
+
results: T[];
|
11
|
+
}
|
12
|
+
export interface IEmail {
|
13
|
+
properties: {
|
14
|
+
From?: string;
|
15
|
+
To: {
|
16
|
+
results: string[];
|
17
|
+
};
|
18
|
+
Body: string;
|
19
|
+
Subject: string;
|
20
|
+
__metadata?: {};
|
21
|
+
};
|
22
|
+
}
|
23
|
+
export interface IPersonOrGroup {
|
24
|
+
Id: number;
|
25
|
+
Title: string;
|
26
|
+
EMail: string;
|
27
|
+
Email: string;
|
28
|
+
Name: string;
|
29
|
+
LoginName: string;
|
30
|
+
IsGroup: boolean;
|
31
|
+
Groups?: IPersonOrGroup[];
|
32
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import IJitzSPContext from "./IJitzSPContext";
|
2
|
+
import { IModel } from "./IModels";
|
3
|
+
export interface IRepository<T extends IModel> {
|
4
|
+
context: IJitzSPContext;
|
5
|
+
listName: string;
|
6
|
+
listGuid: string;
|
7
|
+
listUrl: string;
|
8
|
+
getAll(selectFields?: string, expand?: string, filters?: string, orderBy?: string, top?: number, skip?: number, skipTokenUniqueField?: string, skipTokenUniqueFieldValue?: string): Promise<T[]>;
|
9
|
+
getAllFromUrl(url: string): Promise<T[]>;
|
10
|
+
itemsCount(filters?: string): Promise<number>;
|
11
|
+
getItemById(id: number, selectFields?: string, expand?: string): Promise<T>;
|
12
|
+
createItem(item: T): Promise<T>;
|
13
|
+
updateItem(item: T): Promise<T>;
|
14
|
+
deleteItem(id: number): Promise<boolean>;
|
15
|
+
deleteItems(ids: number[]): Promise<boolean>;
|
16
|
+
getAllRecursive(selectFields?: string, expand?: string, filters?: string, orderBy?: string, top?: number, maxRecursiveCount?: number): any;
|
17
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export interface IJitzHttpClient {
|
2
|
+
get: (url: string, header?: any) => any;
|
3
|
+
post: (url: string, data: any, header?: any) => any;
|
4
|
+
}
|
5
|
+
export default class JitzHttpClient implements IJitzHttpClient {
|
6
|
+
private header;
|
7
|
+
private _client;
|
8
|
+
constructor();
|
9
|
+
get: (url: string, header?: any) => any;
|
10
|
+
post: (url: string, data: any, header?: any) => any;
|
11
|
+
}
|