From 4623a4254b26d49b01d572653bdc38364e8c1e4f Mon Sep 17 00:00:00 2001 From: Evan Skrukwa Date: Tue, 13 May 2025 13:36:36 -0400 Subject: [PATCH 1/2] implement DeleteList and RecycleList --- src/utils/sharepoint.rest/list.ts | 49 ++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/utils/sharepoint.rest/list.ts b/src/utils/sharepoint.rest/list.ts index cdb6368..152f359 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"; @@ -1341,6 +1341,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})'`; From 57fc69492e9eead33da030c1341d641a31a3c9a8 Mon Sep 17 00:00:00 2001 From: evan <71612373+skrukwa@users.noreply.github.com> Date: Tue, 13 May 2025 14:55:07 -0400 Subject: [PATCH 2/2] typo --- src/utils/sharepoint.rest/list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/sharepoint.rest/list.ts b/src/utils/sharepoint.rest/list.ts index 152f359..2197da7 100644 --- a/src/utils/sharepoint.rest/list.ts +++ b/src/utils/sharepoint.rest/list.ts @@ -1,4 +1,4 @@ -import {__getSPRestErrorData, 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";