jitz-sharepoint-utilities 2.0.4 → 2.0.5
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.
@@ -1,3 +1,4 @@
|
|
1
|
+
import UtilityService from "../../services/UtilityService";
|
1
2
|
import IJitzSPContext from "../interfaces/IJitzSPContext";
|
2
3
|
import { IListItemsMetadata, IModel } from "../interfaces/IModels";
|
3
4
|
import { IRepository } from "../interfaces/IRepository";
|
@@ -360,6 +361,86 @@ export default class Repository<T extends IModel> implements IRepository<T> {
|
|
360
361
|
});
|
361
362
|
}
|
362
363
|
|
364
|
+
public deleteItems(ids: number[]): Promise<boolean> {
|
365
|
+
// Here we will delete two different list items from two different lists in a single REST call
|
366
|
+
// Every batch will have a Batch ID/GUID
|
367
|
+
var batchGuid = UtilityService.generateGUID();
|
368
|
+
|
369
|
+
// Every delete/changeset should have a ChangeSet ID/GUID
|
370
|
+
var changeSetGUID = UtilityService.generateGUID()();
|
371
|
+
|
372
|
+
// creating the body
|
373
|
+
var batchContents = new Array();
|
374
|
+
|
375
|
+
ids.map((id) => {
|
376
|
+
// Request creation for first list item Delete
|
377
|
+
var endpoint = `${this.context.siteUrl}/_api/web/lists/getbytitle('${this.listName}')/items(${id})`;
|
378
|
+
|
379
|
+
// create the changeset
|
380
|
+
batchContents.push("--changeset_" + changeSetGUID);
|
381
|
+
batchContents.push("Content-Type: application/http");
|
382
|
+
batchContents.push("Content-Transfer-Encoding: binary");
|
383
|
+
batchContents.push("");
|
384
|
+
batchContents.push("DELETE " + endpoint + " HTTP/1.1");
|
385
|
+
batchContents.push("Content-Type: application/json;odata=verbose");
|
386
|
+
batchContents.push("Accept: application/json;odata=verbose");
|
387
|
+
batchContents.push("IF-MATCH: *");
|
388
|
+
batchContents.push("");
|
389
|
+
});
|
390
|
+
|
391
|
+
batchContents.push("--changeset_" + changeSetGUID + "--");
|
392
|
+
|
393
|
+
// batch body
|
394
|
+
var batchBody = batchContents.join("\r\n");
|
395
|
+
|
396
|
+
batchContents = new Array();
|
397
|
+
|
398
|
+
// create a batch for creating items
|
399
|
+
batchContents.push("--batch_" + batchGuid);
|
400
|
+
batchContents.push(
|
401
|
+
'Content-Type: multipart/mixed; boundary="changeset_' +
|
402
|
+
changeSetGUID +
|
403
|
+
'"'
|
404
|
+
);
|
405
|
+
batchContents.push("Content-Length: " + batchBody.length);
|
406
|
+
batchContents.push("Content-Transfer-Encoding: binary");
|
407
|
+
batchContents.push("");
|
408
|
+
batchContents.push(batchBody);
|
409
|
+
batchContents.push("");
|
410
|
+
|
411
|
+
batchContents.push("--batch_" + batchGuid + "--");
|
412
|
+
batchBody = batchContents.join("\r\n");
|
413
|
+
|
414
|
+
// create the request endpoint
|
415
|
+
var batchEndPoint = `${this.context.siteUrl}/_api/$batch`;
|
416
|
+
|
417
|
+
// // create request
|
418
|
+
// jQuery.ajax({
|
419
|
+
// url: endpoint,
|
420
|
+
// type: 'POST',
|
421
|
+
// headers: batchRequestHeader,
|
422
|
+
// data: batchBody,
|
423
|
+
// success: function (response) {
|
424
|
+
// console.log(response);
|
425
|
+
// },
|
426
|
+
// fail: function (error) {
|
427
|
+
// console.log(response);
|
428
|
+
// }
|
429
|
+
// });
|
430
|
+
|
431
|
+
return this.context.client
|
432
|
+
.post(batchEndPoint, batchBody, {
|
433
|
+
"Content-Type": 'multipart/mixed; boundary="batch_' + batchGuid + '"',
|
434
|
+
})
|
435
|
+
.then((response: any) => {
|
436
|
+
if (response.status >= 200 && response.status < 300) {
|
437
|
+
return true;
|
438
|
+
} else {
|
439
|
+
return Promise.reject(new Error(JSON.stringify(response)));
|
440
|
+
}
|
441
|
+
});
|
442
|
+
}
|
443
|
+
|
363
444
|
private getEntityType(): Promise<string> {
|
364
445
|
return new Promise<string>(
|
365
446
|
(
|
@@ -20,6 +20,7 @@ export interface IRepository<T extends IModel> {
|
|
20
20
|
createItem(item: T): Promise<T>;
|
21
21
|
updateItem(item: T): Promise<T>;
|
22
22
|
deleteItem(id: number): Promise<boolean>;
|
23
|
+
deleteItems(ids: number[]): Promise<boolean>;
|
23
24
|
getAllRecursive(
|
24
25
|
selectFields?: string,
|
25
26
|
expand?: string,
|
@@ -15,5 +15,6 @@ export default class Repository<T extends IModel> implements IRepository<T> {
|
|
15
15
|
createItem(item: T): Promise<T>;
|
16
16
|
updateItem(item: T): Promise<T>;
|
17
17
|
deleteItem(id: number): Promise<boolean>;
|
18
|
+
deleteItems(ids: number[]): Promise<boolean>;
|
18
19
|
private getEntityType;
|
19
20
|
}
|
@@ -36,6 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
36
36
|
}
|
37
37
|
};
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
+
var UtilityService_1 = require("../../services/UtilityService");
|
39
40
|
var Repository = /** @class */ (function () {
|
40
41
|
function Repository(context, listName) {
|
41
42
|
this.context = context;
|
@@ -396,6 +397,73 @@ var Repository = /** @class */ (function () {
|
|
396
397
|
}
|
397
398
|
});
|
398
399
|
};
|
400
|
+
Repository.prototype.deleteItems = function (ids) {
|
401
|
+
var _this = this;
|
402
|
+
// Here we will delete two different list items from two different lists in a single REST call
|
403
|
+
// Every batch will have a Batch ID/GUID
|
404
|
+
var batchGuid = UtilityService_1.default.generateGUID();
|
405
|
+
// Every delete/changeset should have a ChangeSet ID/GUID
|
406
|
+
var changeSetGUID = UtilityService_1.default.generateGUID()();
|
407
|
+
// creating the body
|
408
|
+
var batchContents = new Array();
|
409
|
+
ids.map(function (id) {
|
410
|
+
// Request creation for first list item Delete
|
411
|
+
var endpoint = "".concat(_this.context.siteUrl, "/_api/web/lists/getbytitle('").concat(_this.listName, "')/items(").concat(id, ")");
|
412
|
+
// create the changeset
|
413
|
+
batchContents.push("--changeset_" + changeSetGUID);
|
414
|
+
batchContents.push("Content-Type: application/http");
|
415
|
+
batchContents.push("Content-Transfer-Encoding: binary");
|
416
|
+
batchContents.push("");
|
417
|
+
batchContents.push("DELETE " + endpoint + " HTTP/1.1");
|
418
|
+
batchContents.push("Content-Type: application/json;odata=verbose");
|
419
|
+
batchContents.push("Accept: application/json;odata=verbose");
|
420
|
+
batchContents.push("IF-MATCH: *");
|
421
|
+
batchContents.push("");
|
422
|
+
});
|
423
|
+
batchContents.push("--changeset_" + changeSetGUID + "--");
|
424
|
+
// batch body
|
425
|
+
var batchBody = batchContents.join("\r\n");
|
426
|
+
batchContents = new Array();
|
427
|
+
// create a batch for creating items
|
428
|
+
batchContents.push("--batch_" + batchGuid);
|
429
|
+
batchContents.push('Content-Type: multipart/mixed; boundary="changeset_' +
|
430
|
+
changeSetGUID +
|
431
|
+
'"');
|
432
|
+
batchContents.push("Content-Length: " + batchBody.length);
|
433
|
+
batchContents.push("Content-Transfer-Encoding: binary");
|
434
|
+
batchContents.push("");
|
435
|
+
batchContents.push(batchBody);
|
436
|
+
batchContents.push("");
|
437
|
+
batchContents.push("--batch_" + batchGuid + "--");
|
438
|
+
batchBody = batchContents.join("\r\n");
|
439
|
+
// create the request endpoint
|
440
|
+
var batchEndPoint = "".concat(this.context.siteUrl, "/_api/$batch");
|
441
|
+
// // create request
|
442
|
+
// jQuery.ajax({
|
443
|
+
// url: endpoint,
|
444
|
+
// type: 'POST',
|
445
|
+
// headers: batchRequestHeader,
|
446
|
+
// data: batchBody,
|
447
|
+
// success: function (response) {
|
448
|
+
// console.log(response);
|
449
|
+
// },
|
450
|
+
// fail: function (error) {
|
451
|
+
// console.log(response);
|
452
|
+
// }
|
453
|
+
// });
|
454
|
+
return this.context.client
|
455
|
+
.post(batchEndPoint, batchBody, {
|
456
|
+
"Content-Type": 'multipart/mixed; boundary="batch_' + batchGuid + '"',
|
457
|
+
})
|
458
|
+
.then(function (response) {
|
459
|
+
if (response.status >= 200 && response.status < 300) {
|
460
|
+
return true;
|
461
|
+
}
|
462
|
+
else {
|
463
|
+
return Promise.reject(new Error(JSON.stringify(response)));
|
464
|
+
}
|
465
|
+
});
|
466
|
+
};
|
399
467
|
Repository.prototype.getEntityType = function () {
|
400
468
|
var _this = this;
|
401
469
|
return new Promise(function (resolve, reject) {
|
@@ -10,5 +10,6 @@ export interface IRepository<T extends IModel> {
|
|
10
10
|
createItem(item: T): Promise<T>;
|
11
11
|
updateItem(item: T): Promise<T>;
|
12
12
|
deleteItem(id: number): Promise<boolean>;
|
13
|
+
deleteItems(ids: number[]): Promise<boolean>;
|
13
14
|
getAllRecursive(selectFields?: string, expand?: string, filters?: string, orderBy?: string, top?: number, maxRecursiveCount?: number): any;
|
14
15
|
}
|