-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gok 348-Inventory - Refactor the "Load Stock" button to initiate the …
…"Stock Initials" API (#41) * Deepthi M|Gok-348|Updated the Loadstock save (Post api call) to create an instance type Initial instead of Receipt. * Deepthi M|Gok-348|Updated the resolve issue with date picker
- Loading branch information
1 parent
2f09a46
commit 2d7d1bd
Showing
3 changed files
with
81 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
postRequest, | ||
getRequest, | ||
stockOperationURL, | ||
stockOperationTypeURL, | ||
} from '../utils/api-utils'; | ||
import { getFormattedDate } from '../utils/date-utils'; | ||
|
||
const saveStockInitial = async (items, outwardNumber, destinationUuid) => { | ||
const instanceTypeResponse = await getRequest(stockOperationTypeURL('Initial')); | ||
const instanceTypeUuids = instanceTypeResponse.results[0].uuid; | ||
const itemsArray = []; | ||
await Promise.all( | ||
items.map(async (item) => { | ||
const itemName = encodeURIComponent(item.item); | ||
const response = await getRequest(`/openmrs/ws/rest/v2/inventory/item?v=full&q=${itemName}`); | ||
const itemUuid = response.results[0]?.uuid; | ||
// Add the item to the requestBody.items array with all corresponding properties | ||
itemsArray.push({ | ||
item: itemUuid, | ||
quantity: item.totalQuantity, | ||
expiration: item.expiration, | ||
batchNumber: item.batchNumber, | ||
calculatedExpiration: true, | ||
}); | ||
}), | ||
); | ||
|
||
const requestBody = { | ||
status: 'NEW', | ||
attributes: [], | ||
items: itemsArray, | ||
operationNumber: '', | ||
instanceType: instanceTypeUuids, | ||
operationDate: getFormattedDate(), | ||
source: '', | ||
destination: destinationUuid, | ||
institution: '', | ||
department: '', | ||
outwardId: outwardNumber, | ||
}; | ||
|
||
return postRequest(stockOperationURL, requestBody); | ||
}; | ||
export default saveStockInitial; |