forked from woocommerce/woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ce5f7a
commit 095a743
Showing
17 changed files
with
141 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
const order = require('./order'); | ||
const coupon = require('./coupon'); | ||
const { order } = require('./order'); | ||
const { coupon } = require('./coupon'); | ||
const shared = require('./shared'); | ||
|
||
module.exports = { | ||
order, | ||
coupon, | ||
shared, | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,46 @@ | ||
/** | ||
* Shared model for batch updates for a resource. | ||
* | ||
* Note that by default the update is limited to 100 objects to be created, updated, or deleted. | ||
*/ | ||
const batchUpdatePayload = { | ||
create: [], | ||
update: [], | ||
delete: [], | ||
} | ||
|
||
/** | ||
* Batch create a resource. | ||
* Note that by default the update endpoint is limited to 100 objects to be created, updated, or deleted. | ||
* | ||
* @param {Array} resourcesToCreate A list of resource objects to create. | ||
* @returns | ||
* @param {string} action Batch action. Must be one of: create, update, or delete. | ||
* @param {Array} resources A list of resource objects. For the delete action, this will be a list of IDs. | ||
* @param {Object} payload The batch payload object. Defaults to an empty object. | ||
* @returns {Object} The payload to send to the batch endpoint. | ||
*/ | ||
const batchCreate = ( resourcesToCreate = [] ) => { | ||
if ( resourcesToCreate.length === 0 ) { | ||
const batch = ( action, resources = [], payload = {} ) => { | ||
if ( ! [ 'create', 'update', 'delete' ].includes( action ) ) { | ||
return; | ||
} | ||
|
||
// Build array of resources to create | ||
const createArray = []; | ||
resourcesToCreate.forEach( ( resource ) => { | ||
createArray.push( resource ); | ||
}); | ||
|
||
batchUpdatePayload.create = createArray | ||
|
||
return createArray; | ||
} | ||
|
||
/** | ||
* Batch update resources. | ||
* | ||
* @param {Array} resourcesToUpdate A list of resource objects to update. | ||
* @returns | ||
*/ | ||
const batchUpdate = ( resourcesToUpdate = [] ) => { | ||
if ( resourcesToUpdate.length === 0 ) { | ||
return | ||
if ( resources.length === 0 ) { | ||
return; | ||
} | ||
|
||
// Build array of resources to update | ||
const updateArray = []; | ||
resourcesToUpdate.forEach( ( resource ) => { | ||
updateArray.push( resource ); | ||
}); | ||
|
||
return updateArray; | ||
} | ||
if ( action === 'create' ) { | ||
payload.create = [ ...resources ]; | ||
} | ||
|
||
/** | ||
* Batch delete resources. | ||
* | ||
* @param {Array} resourceIds A list of IDs of resource objects to delete. | ||
* @returns | ||
*/ | ||
const batchDelete = ( resourceIds = [] ) => { | ||
if ( resourceIds.length === 0 ) { | ||
return; | ||
if ( action === 'update' ) { | ||
payload.update = [ ...resources ]; | ||
} | ||
|
||
// Build array of resources to delete | ||
const deleteArray = []; | ||
resourceIds.forEach( ( id ) => { | ||
deleteArray.push( id ); | ||
}); | ||
if ( action === 'delete' ) { | ||
payload.delete = [ ...resources ]; | ||
} | ||
|
||
return deleteArray; | ||
} | ||
return payload; | ||
}; | ||
|
||
const getBatchPayloadExample = ( resource ) => { | ||
batchUpdatePayload.create = batchCreate( [ resource ] ); | ||
batchUpdatePayload.update = batchUpdate( [ resource ] ); | ||
batchUpdatePayload.delete = batchDelete( [ 1, 2, 3 ] ); | ||
let batchUpdatePayload = {}; | ||
batchUpdatePayload = batch( 'create', [ resource ], batchUpdatePayload ); | ||
batchUpdatePayload = batch( 'update', [ resource ], batchUpdatePayload ); | ||
batchUpdatePayload = batch( 'delete', [ 1, 2, 3 ], batchUpdatePayload ); | ||
return batchUpdatePayload; | ||
} | ||
}; | ||
|
||
module.exports = { | ||
batchUpdatePayload, | ||
batchCreate, | ||
batchUpdate, | ||
batchDelete, | ||
getBatchPayloadExample | ||
} | ||
batch, | ||
getBatchPayloadExample, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,7 @@ const errorResponse = { | |
message: '', | ||
data: { | ||
status: 400 | ||
} | ||
} | ||
}, | ||
}; | ||
|
||
module.exports = { errorResponse }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
const { customerBilling, customerShipping } = require('./customer'); | ||
const { | ||
batchUpdatePayload, | ||
batchCreate, | ||
batchUpdate, | ||
batchDelete, | ||
batch, | ||
getBatchPayloadExample | ||
} = require('./batch-update'); | ||
const errorRessponse = require('./customer'); | ||
const { errorResponse } = require('./error-response'); | ||
|
||
module.exports = { | ||
customerBilling, | ||
customerShipping, | ||
batchUpdatePayload, | ||
batchCreate, | ||
batchUpdate, | ||
batchDelete, | ||
batch, | ||
getBatchPayloadExample, | ||
errorRessponse | ||
} | ||
errorResponse, | ||
}; |
Oops, something went wrong.