Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dx | 1595 | add and delete items #236

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions lib/stack/bulkOperation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ export function BulkOperation (http, data = {}) {
this.stackHeaders = data.stackHeaders
this.urlPath = `/bulk`

/**
* The addItems request allows you to add multiple items to a release in bulk.
* @memberof BulkOperation
* @func addItems
* @returns {Promise<Object>} Response Object.
* @param {Object} params.data - The data containing the items to be added to the release.
* @param {String} [params.bulk_version] - The bulk version.
* @example
* const itemsData = {
* items: [
* {
* uid: '{{entry_uid}}',
* content_type: '{{content_type_uid}}'
* }
* ]
* }
* client.stack({ api_key: 'api_key'}).bulkOperation().addItems({ data: itemsData })
* .then((response) => { console.log(response) })
*/
this.addItems = async ({ data, bulk_version = "" }) => {
this.urlPath = `/bulk/release/items`;
const headers = {
Expand All @@ -27,6 +46,25 @@ export function BulkOperation (http, data = {}) {
}
};

/**
* The updateItems request allows you to update multiple items in a release in bulk.
* @memberof BulkOperation
* @func updateItems
* @returns {Promise<Object>} Response Object.
* @param {Object} params.data - The data containing the items to be updated in the release.
* @param {String} [params.bulk_version] - The bulk version.
* @example
* const itemsData = {
* items: [
* {
* uid: '{{entry_uid}}',
* content_type: '{{content_type_uid}}'
* }
* ]
* }
* client.stack({ api_key: 'api_key'}).bulkOperation().updateItems({ data: itemsData })
* .then((response) => { console.log(response) })
*/
this.updateItems = async ({ data, bulk_version = "" }) => {
this.urlPath = `/bulk/release/update_items`;
const headers = {
Expand All @@ -45,6 +83,17 @@ export function BulkOperation (http, data = {}) {
}
};

/**
* The jobStatus request allows you to check the status of a bulk job.
* @memberof BulkOperation
* @func jobStatus
* @returns {Promise<Object>} Response Object.
* @param {String} params.job_id - The ID of the job.
* @param {String} [params.bulk_version] - The bulk version.
* @example
* client.stack({ api_key: 'api_key'}).bulkOperation().jobStatus({ job_id: 'job_id' })
* .then((response) => { console.log(response) })
*/
this.jobStatus = async ({ job_id, bulk_version = "" }) => {
this.urlPath = `/bulk/jobs/${job_id}`;
const headers = {
Expand Down
49 changes: 44 additions & 5 deletions lib/stack/release/items/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,36 @@ export function ReleaseItem (http, data = {}) {
* client.stack({ api_key: 'api_key'}).release('release_uid').delete({items})
* .then((response) => console.log(response.notice))
*/
this.delete = async (items) => {
this.delete = async (params) => {
let param = {}
if (items === undefined) {
if (params.items === undefined && params.item === undefined) {
param = {all: true}
params.items = []
}
try {
const headers = {
headers: { ...cloneDeep(this.stackHeaders) },
data: {
...cloneDeep(items)
...cloneDeep(params)
},
params: {
...cloneDeep(param)
}
} || {}

if (params.release_version) {
headers.headers['release_version'] = params.release_version;
}

if (params.item) {
this.urlPath = `releases/${data.releaseUid}/item`
headers.data['item'] = params.item
} else
headers.data['items'] = params.items

const response = await http.delete(this.urlPath, headers)
if (response.data) {
return new Release(http, { ...response.data, stackHeaders: data.stackHeaders })
return response.data
} else {
throw error(response)
}
Expand Down Expand Up @@ -129,9 +140,18 @@ export function ReleaseItem (http, data = {}) {
...cloneDeep(this.stackHeaders)
}
} || {}

if (param.release_version) {
headers.headers['release_version'] = param.release_version;
}
if (param.item) {
this.urlPath = `releases/${data.releaseUid}/item`
param['item'] = param.item
} else
param['items'] = param.items

try {
const response = await http.post(param.item ? `releases/${data.releaseUid}/item` : this.urlPath, param, headers)
const response = await http.post(this.urlPath, param, headers)
if (response.data) {
if (response.data) {
return new Release(http, { ...response.data, stackHeaders: data.stackHeaders })
Expand Down Expand Up @@ -181,6 +201,25 @@ export function ReleaseItem (http, data = {}) {
}
}

/**
* The move request allows you to move multiple items within a release.
* @memberof ReleaseItem
* @func move
* @returns {Promise<Object>} Response Object.
* @param {Object} params.param - The data containing the items to be moved within the release.
* @param {String} [params.release_version] - The release version.
* @example
* const moveData = {
* items: [
* {
* uid: '{{entry_uid}}',
* content_type: '{{content_type_uid}}'
* }
* ]
* }
* client.stack({ api_key: 'api_key'}).release('release_uid').item().move({ param: moveData, release_version: '1.0' })
* .then((response) => { console.log(response) })
*/
this.move = async ({ param, release_version = '' }) => {
const headers = {
headers: {
Expand Down
Loading
Loading