import { ListItem } from "gd-sprest-def/lib/SP" ; import { IcreateDocSet } from "../../../@types/helper/methods" ; import { Web } from "../../lib" ; import { request } from "./request" ; param name param listName param webUrl export const createDocSet = ( name , listName , webUrl ? ) : PromiseLike < ListItem > => { return new Promise ( ( resolve , reject ) => { Web ( webUrl ) . Lists ( listName ) . query ( { Expand : [ "ContentTypes" , "ParentWeb" , "RootFolder" ] } ) . execute ( list => { let ctId = "0x0120D520" ; for ( let i = 0 ; i < list . ContentTypes . results . length ; i ++ ) { if ( list . ContentTypes . results [ i ] . StringId . indexOf ( ctId ) == 0 ) { ctId = list . ContentTypes . results [ i ] . StringId ; break ; } } request ( { method : "POST" , url : list . ParentWebUrl + "/_vti_bin/listdata.svc/" + list . Title . replace ( / /g , "" ) , headers : { Accept : "application/json;odata=verbose" , "Content-Type" : "application/json;odata=verbose" , Slug : list . RootFolder . ServerRelativeUrl + "/" + name + "|" + ctId , "X-Requested-With" : "XMLHttpRequest" } , data : { Title : name , Path : list . RootFolder . ServerRelativeUrl } } ) . then ( response => { if ( response . d && response . d . Id > 0 ) { Web ( webUrl ) . Lists ( listName ) . Items ( response . d . Id ) . execute ( resolve ) ; } else { reject ( response [ "response" ] ) ; } } ) ; } , reject ) ; } ) ; } ;