Skip to content

Commit

Permalink
Merge 4db6b98 into b18fc8c
Browse files Browse the repository at this point in the history
  • Loading branch information
thollingshead authored May 7, 2021
2 parents b18fc8c + 4db6b98 commit 7a21f01
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/arcgis-rest-portal/src/items/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ export interface IItemResourceOptions extends IUserItemOptions {
resource?: any;
}

export interface IRemoveItemResourceOptions extends IUserItemOptions {
/**
* Resource item to be removed. Resource prefix needs to be specified if the file resource has one.
*/
resource?: string;

/**
* If true, all file resources are removed.
*/
deleteAll?: boolean;
}

export interface ICreateUpdateItemOptions extends IUserRequestOptions {
/**
* The owner of the item. If this property is not present, `item.owner` will be passed, or lastly `authentication.username`.
Expand Down
10 changes: 8 additions & 2 deletions packages/arcgis-rest-portal/src/items/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { request, appendCustomParams } from "@esri/arcgis-rest-request";
import { getPortalUrl } from "../util/get-portal-url";
import {
IUserItemOptions,
IItemResourceOptions,
IRemoveItemResourceOptions,
IFolderIdOptions,
determineOwner,
IManageItemRelationshipOptions
Expand Down Expand Up @@ -79,7 +79,7 @@ export function removeItemRelationship(
* @returns A Promise that deletes an item resource.
*/
export function removeItemResource(
requestOptions: IItemResourceOptions
requestOptions: IRemoveItemResourceOptions
): Promise<{ success: boolean }> {
return determineOwner(requestOptions).then(owner => {
const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${
Expand All @@ -91,6 +91,12 @@ export function removeItemResource(
...requestOptions.params,
resource: requestOptions.resource
};

// only override the deleteAll param specified previously if it is passed explicitly
if (typeof requestOptions.deleteAll !== "undefined") {
requestOptions.params.deleteAll = requestOptions.deleteAll;
}

return request(url, requestOptions);
});
}
Expand Down
23 changes: 23 additions & 0 deletions packages/arcgis-rest-portal/test/items/remove.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,29 @@ describe("search", () => {
});
});

it("should remove a resource with deleteAll", done => {
fetchMock.once("*", RemoveItemResourceResponse);
removeItemResource({
id: "3ef",
owner: "dbouwman",
resource: "image/banner.png",
deleteAll: true,
...MOCK_USER_REQOPTS
})
.then(response => {
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/items/3ef/removeResources"
);
expect(options.method).toBe("POST");
expect(options.body).toContain(encodeParam("deleteAll", "true"));
done();
})
.catch(e => {
fail(e);
});
});

it("should remove a resource with extra params", done => {
fetchMock.once("*", RemoveItemResourceResponse);
removeItemResource({
Expand Down

0 comments on commit 7a21f01

Please sign in to comment.