diff --git a/src/utils/sharepoint.rest/list.ts b/src/utils/sharepoint.rest/list.ts index 9fb88c7..1ace41f 100644 --- a/src/utils/sharepoint.rest/list.ts +++ b/src/utils/sharepoint.rest/list.ts @@ -1,4 +1,4 @@ -import { jsonClone } from "../../exports-index"; +import { __getSPRestErrorData, jsonClone } from "../../exports-index"; import { PushNoDuplicate, firstOrNull, makeUniqueArray, toHash } from "../../helpers/collections.base"; import { jsonStringify } from "../../helpers/json"; import { NormalizeListName, SPBasePermissions, SchemaJsonToXml, SchemaXmlToJson, extendFieldInfos } from "../../helpers/sharepoint"; @@ -1358,6 +1358,53 @@ export async function CreateList(siteUrl: string, info: { return newList; } +export async function RecycleList(siteUrl: string, listIdOrTitle: string): Promise<{ recycled: boolean; errorMessage?: string}> { + siteUrl = GetSiteUrl(siteUrl); + const url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/recycle()`; + const result: { recycled: boolean; errorMessage?: string; } = { recycled: true }; + + try { + await GetJson<{ d: {Recycle: string; } }>( + url, null, + { + method: "POST", + allowCache: false, + jsonMetadata: jsonTypes.nometadata, + spWebUrl: siteUrl + } + ); + } catch (e) { + result.recycled = false; + result.errorMessage = __getSPRestErrorData(e).message; + } + + return result; +} + +export async function DeleteList(siteUrl: string, listIdOrTitle: string): Promise<{ deleted: boolean; errorMessage?: string }> { + siteUrl = GetSiteUrl(siteUrl); + const url = `${GetListRestUrl(siteUrl, listIdOrTitle)}/deleteObject`; + const result: { deleted: boolean; errorMessage?: string } = { deleted: true }; + + try { + await GetJson( + url, null, + { + method: "POST", + xHttpMethod: "DELETE", + allowCache: false, + jsonMetadata: jsonTypes.nometadata, + spWebUrl: siteUrl + } + ); + } catch (e) { + result.deleted = false; + result.errorMessage = __getSPRestErrorData(e).message; + } + + return result; +} + export async function SearchList(siteUrl: string, listIdOrTitle: string, query: string) { let listId = GetListId(siteUrl, listIdOrTitle); let url = `${GetRestBaseUrl(siteUrl)}/search/query?querytext='(${query}*)'&querytemplate='{searchTerms} (NormListID:${listId})'`;