Skip to content

Commit

Permalink
fix(params): flip param values in updateItemResource so they are pass…
Browse files Browse the repository at this point in the history
…ed correctly

AFFECTS PACKAGES:
@esri/arcgis-rest-items

ISSUES CLOSED: #118
  • Loading branch information
Noah Mulfinger committed Feb 22, 2018
1 parent 8c428f2 commit 5093e39
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
51 changes: 26 additions & 25 deletions packages/arcgis-rest-items/src/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ export function addItemJsonData(
): Promise<any> {
const owner = requestOptions.owner || requestOptions.authentication.username;

const url = `${getPortalUrl(
requestOptions
)}/content/users/${owner}/items/${requestOptions.id}/update`;
const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${
requestOptions.id
}/update`;

// Portal API requires that the 'data' be stringified and POSTed in
// a `text` form field. It can also be sent with the `.create` call by sending
Expand Down Expand Up @@ -240,8 +240,9 @@ export function getItemData(
* @returns A Promise that resolves with the status of the operation.
*/
export function updateItem(requestOptions: IItemRequestOptions): Promise<any> {
const url = `${getPortalUrl(requestOptions)}/content/users/${requestOptions
.item.owner}/items/${requestOptions.item.id}/update`;
const url = `${getPortalUrl(requestOptions)}/content/users/${
requestOptions.item.owner
}/items/${requestOptions.item.id}/update`;

// serialize the item into something Portal will accept
requestOptions.params = serializeItem(requestOptions.item);
Expand All @@ -259,9 +260,9 @@ export function removeItem(
requestOptions: IItemIdRequestOptions
): Promise<any> {
const owner = requestOptions.owner || requestOptions.authentication.username;
const url = `${getPortalUrl(
requestOptions
)}/content/users/${owner}/items/${requestOptions.id}/delete`;
const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${
requestOptions.id
}/delete`;
return request(url, requestOptions);
}

Expand All @@ -275,9 +276,9 @@ export function protectItem(
requestOptions: IItemIdRequestOptions
): Promise<any> {
const owner = requestOptions.owner || requestOptions.authentication.username;
const url = `${getPortalUrl(
requestOptions
)}/content/users/${owner}/items/${requestOptions.id}/protect`;
const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${
requestOptions.id
}/protect`;
return request(url, requestOptions);
}

Expand All @@ -291,9 +292,9 @@ export function unprotectItem(
requestOptions: IItemIdRequestOptions
): Promise<any> {
const owner = requestOptions.owner || requestOptions.authentication.username;
const url = `${getPortalUrl(
requestOptions
)}/content/users/${owner}/items/${requestOptions.id}/unprotect`;
const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${
requestOptions.id
}/unprotect`;
return request(url, requestOptions);
}

Expand All @@ -306,9 +307,9 @@ export function unprotectItem(
export function getItemResources(
requestOptions: IItemIdRequestOptions
): Promise<any> {
const url = `${getPortalUrl(
requestOptions
)}/content/items/${requestOptions.id}/resources`;
const url = `${getPortalUrl(requestOptions)}/content/items/${
requestOptions.id
}/resources`;

requestOptions.params = { num: 1000 };

Expand All @@ -325,13 +326,13 @@ export function updateItemResource(
requestOptions: IItemResourceRequestOptions
): Promise<any> {
const owner = requestOptions.owner || requestOptions.authentication.username;
const url = `${getPortalUrl(
requestOptions
)}/content/users/${owner}/items/${requestOptions.id}/updateResources`;
const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${
requestOptions.id
}/updateResources`;

requestOptions.params = {
fileName: requestOptions.content,
text: requestOptions.name
fileName: requestOptions.name,
text: requestOptions.content
};

return request(url, requestOptions);
Expand All @@ -347,9 +348,9 @@ export function removeItemResource(
requestOptions: IItemResourceRequestOptions
): Promise<any> {
const owner = requestOptions.owner || requestOptions.authentication.username;
const url = `${getPortalUrl(
requestOptions
)}/content/users/${owner}/items/${requestOptions.id}/removeResources`;
const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${
requestOptions.id
}/removeResources`;

requestOptions.params = { resource: requestOptions.resource };
return request(url, requestOptions);
Expand Down
8 changes: 4 additions & 4 deletions packages/arcgis-rest-items/test/items.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ describe("search", () => {
updateItemResource({
id: "3ef",
owner: "dbouwman",
content: "image/banner.png",
name: "jumbotron",
name: "image/banner.png",
content: "jumbotron",
...MOCK_USER_REQOPTS
})
.then(response => {
Expand All @@ -620,8 +620,8 @@ describe("search", () => {
fetchMock.once("*", UpdateItemResourceResponse);
updateItemResource({
id: "3ef",
content: "image/banner.png",
name: "jumbotron",
name: "image/banner.png",
content: "jumbotron",
...MOCK_USER_REQOPTS
})
.then(response => {
Expand Down

0 comments on commit 5093e39

Please sign in to comment.