


Code : #
javax.validation.constraints.NotNull

Code : #
// Delete all existing working orders
function deleteAllOrders() {
	return new Promise((res, rej) => {
		let response = [];
		let tickets = [];
		let index = 0;
		let close = {};
		get('/workingorders')
			.then(r => {
				let temp = r.body.workingOrders;
				if (temp.length === 0)(res('There is no order to close'));
				for (let i = 0; i < temp.length; i++) {
					tickets.push(temp[i].workingOrderData.dealId);
				}
				function _close(index) {
					if (tickets[index]) {
						del('/workingorders/otc/' + tickets[index], close)
							.then(r => {
								get('/confirms/' + r.body.dealReference)
									.then(r => {
										if (r.status !== 200) {
											rej(r);
										} else {
											index++;
											_close(index);
											response.push(r.body);
										}
									})
									.catch(e => {
										rej(e);
									});
							})
							.catch(e => {
								rej(e);
							});
					} else {
						res(response);
					}
				}
				_close(index);
			});
	});
}