|
1 | 1 | import { |
2 | | - ContainerList, |
3 | | - ProcessingStatus, |
4 | | - ProcessResponse, |
5 | | - Result, |
6 | | - ResultItem, |
7 | | - RfidLocation, Status, StatusResult, |
8 | | - TextResult, |
9 | | - TransactionInfo |
| 2 | + ContainerList, ImagesResult, |
| 3 | + ProcessingStatus, |
| 4 | + ProcessResponse, RawImageResult, |
| 5 | + Result, |
| 6 | + ResultItem, |
| 7 | + RfidLocation, Status, StatusResult, |
| 8 | + TextResult, |
| 9 | + TransactionInfo |
10 | 10 | } from "../models/index.js"; |
11 | 11 | import {Text} from "./text.js"; |
| 12 | +import {Images} from "./images.js"; |
12 | 13 |
|
13 | 14 |
|
14 | 15 | export class Response { |
15 | 16 |
|
16 | | - // other modules: |
17 | | - // - images |
18 | | - // - status |
19 | | - // - authenticity |
20 | | - // - document |
21 | | - status?: Status |
22 | | - text?: Text |
| 17 | + // other future modules: |
| 18 | + // - authenticity |
| 19 | + // - document |
| 20 | + status?: Status |
| 21 | + text?: Text |
| 22 | + images?: Images |
23 | 23 |
|
24 | | - lowLvlResponse: LowLvlResponse |
| 24 | + lowLvlResponse: LowLvlResponse |
25 | 25 |
|
26 | | - constructor(original: ProcessResponse) { |
| 26 | + constructor(original: ProcessResponse) { |
27 | 27 |
|
28 | | - const lowLvlResponse = new LowLvlResponse(original) |
29 | | - this.lowLvlResponse = lowLvlResponse |
| 28 | + const lowLvlResponse = new LowLvlResponse(original) |
| 29 | + this.lowLvlResponse = lowLvlResponse |
30 | 30 |
|
31 | | - const textResult = lowLvlResponse.textResult() |
32 | | - if (textResult) { |
33 | | - this.text = new Text(textResult.Text) |
34 | | - } |
35 | | - this.status = lowLvlResponse.statusResult()?.Status |
| 31 | + this.status = lowLvlResponse.statusResult()?.Status |
| 32 | + const textResult = lowLvlResponse.textResult() |
| 33 | + if (textResult) { |
| 34 | + this.text = new Text(textResult.Text) |
36 | 35 | } |
| 36 | + const imagesResult = lowLvlResponse.imagesResult() |
| 37 | + if (imagesResult) { |
| 38 | + this.images = new Images(imagesResult.Images, lowLvlResponse.normalizedInputImages()) |
| 39 | + } |
| 40 | + } |
37 | 41 | } |
38 | 42 |
|
39 | 43 | export class LowLvlResponse implements ProcessResponse { |
40 | 44 |
|
41 | | - ContainerList: ContainerList |
42 | | - ProcessingFinished: ProcessingStatus |
43 | | - TransactionInfo: TransactionInfo |
44 | | - ChipPage: RfidLocation |
| 45 | + ContainerList: ContainerList |
| 46 | + ProcessingFinished: ProcessingStatus |
| 47 | + TransactionInfo: TransactionInfo |
| 48 | + ChipPage: RfidLocation |
45 | 49 |
|
46 | | - constructor(original: ProcessResponse) { |
47 | | - this.ContainerList = original.ContainerList |
48 | | - this.ProcessingFinished = original.ProcessingFinished |
49 | | - this.TransactionInfo = original.TransactionInfo |
50 | | - this.ChipPage = original.ChipPage |
51 | | - } |
| 50 | + constructor(original: ProcessResponse) { |
| 51 | + this.ContainerList = original.ContainerList |
| 52 | + this.ProcessingFinished = original.ProcessingFinished |
| 53 | + this.TransactionInfo = original.TransactionInfo |
| 54 | + this.ChipPage = original.ChipPage |
| 55 | + } |
52 | 56 |
|
53 | | - public textResult(): TextResult | undefined { |
54 | | - return <TextResult>this.resultByType(Result.TEXT) |
55 | | - } |
| 57 | + public normalizedInputImages(): Array<RawImageResult> | undefined { |
| 58 | + // @ts-ignore |
| 59 | + return this.resultsByType(Result.RAW_IMAGE) |
| 60 | + } |
56 | 61 |
|
57 | | - public statusResult(): StatusResult | undefined { |
58 | | - return <StatusResult>this.resultByType(Result.STATUS) |
59 | | - } |
| 62 | + public statusResult(): StatusResult | undefined { |
| 63 | + return <StatusResult>this.resultByType(Result.STATUS) |
| 64 | + } |
60 | 65 |
|
61 | | - public resultByType(type: Result): ResultItem | undefined { |
62 | | - return this.ContainerList.List.find(container => container.result_type === type) |
63 | | - } |
| 66 | + public textResult(): TextResult | undefined { |
| 67 | + return <TextResult>this.resultByType(Result.TEXT) |
| 68 | + } |
| 69 | + |
| 70 | + public imagesResult(): ImagesResult | undefined { |
| 71 | + return <ImagesResult>this.resultByType(Result.IMAGES) |
| 72 | + } |
| 73 | + |
| 74 | + public resultByType(type: Result): ResultItem | undefined { |
| 75 | + return this.ContainerList.List.find(container => container.result_type === type) |
| 76 | + } |
| 77 | + |
| 78 | + public resultsByType(type: Result): Array<ResultItem> | undefined { |
| 79 | + return this.ContainerList.List.filter(container => container.result_type === type) |
| 80 | + } |
64 | 81 | } |
0 commit comments