Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge 71b21bb into bf05c4e
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobueno committed Aug 21, 2017
2 parents bf05c4e + 71b21bb commit 12c2247
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 15 additions & 7 deletions client/wfm/src/service/WfmService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ export class WfmService {
if (!workorder.assignee) {
return Promise.reject(new Error(`Workorder with Id ${workorderId} has no assignee`));
}
return this.createNewResult(workorderId, workorder.assignee)
.then(result => {
workorder.status = this.checkStatus(workorder, workflow);
return Promise.all([
this.workorderService.update(workorder),
this.createNewResult(workorderId, workorder.assignee)
]).then(([updatedWorkorder, result]) => {
// Now we check the current status of the workflow to see where the next step should be.
result.status = this.checkStatus(workorder, workflow, result);
result.status = updatedWorkorder.status;

// We now have the current status of the workflow for this workorder, the begin step is now complete.
return {
workorder,
updatedWorkorder,
workflow,
result,
nextStepIndex,
Expand Down Expand Up @@ -187,9 +190,14 @@ export class WfmService {
// The result needs to be updated with the latest step results
result.stepResults = result.stepResults || {};
result.stepResults[step.code] = stepResult;
result.status = this.checkStatus(workorder, workflow, result);
const status = this.checkStatus(workorder, workflow, result);
result.status = status;
workorder.status = status;

return this.resultService.update(result).then(() => ({
return Promise.all([
this.workorderService.update(workorder),
this.resultService.update(result)
]).then(() => ({
workorder,
workflow,
result,
Expand Down Expand Up @@ -247,7 +255,7 @@ export class WfmService {
* @param workflow - The workflow to check status
* @param result - The result to check status
*/
protected checkStatus(workorder: WorkOrder, workflow: WorkFlow, result: WorkOrderResult): STATUS {
protected checkStatus(workorder: WorkOrder, workflow: WorkFlow, result?: WorkOrderResult): STATUS {
let status;
const stepReview = this.executeStepReview(workflow.steps, result);
if (stepReview.nextStepIndex >= workflow.steps.length - 1 && stepReview.complete) {
Expand Down
2 changes: 2 additions & 0 deletions client/wfm/test/service/WfmService-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe('WfmService', function() {
stepCode: 'vehicle-inspection'
}).then(data => {
expect(data.nextStepIndex).to.equal(1);
expect(data.workorder.status).to.equal(STATUS.COMPLETE_DISPLAY);
// would be nice to have `?.` here...
// see https://github.com/tc39/proposal-optional-chaining
const stepResult: StepResult | undefined = data.result &&
Expand All @@ -102,6 +103,7 @@ describe('WfmService', function() {
stepCode: 'vehicle-inspection'
}).then(data => {
expect(data.result && data.result.status).to.equal(STATUS.PENDING_DISPLAY);
expect(data.workorder.status).to.equal(STATUS.PENDING_DISPLAY);
const stepResult: StepResult | undefined = data.result &&
data.result.stepResults &&
data.result.stepResults['vehicle-inspection'];
Expand Down

0 comments on commit 12c2247

Please sign in to comment.