Created
July 17, 2020 05:25
-
-
Save bankchart/9502c738f69e6996a2f98fbe9007fd1f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const responseFromApi = { "transactionId": "7063c660-3ffa-4272-8d26-c64aae2d660e", "timestamp": 1594959997353, "statusCode": "S0000", "statusMessage": "Successfully processed.", "domainName": "root", "data": { "mapResponse": [{ "confKey": "master.operator", "confValue": "{\"operatorList\":[{\"code\":\"OP01\",\"name\":\"DTAC\",\"description\":\"dtn\"},{\"code\":\"OP02\",\"name\":\"DTN\",\"description\":\"dtn\"}]}", "confType": "J", "remark": "JSON Array Object" }, { "confKey": "master.sim.size", "confValue": "{\"simSizeList\":[{\"code\":\"01\",\"name\":\"H\",\"description\":\"Haft size\",\"boxSize\":500},{\"code\":\"02\",\"name\":\"P\",\"description\":\"Plug-in\",\"boxSize\":500}]}", "confType": "J", "remark": "JSON Array Object" }, { "confKey": "master.form.factor", "confValue": "{\"formFactorList\":[{\"code\":\"F01\",\"name\":\"2FF\",\"description\":\"2FF\"},{\"code\":\"F02\",\"name\":\"2+3+4FF\",\"description\":\"2+3+4FF\"},{\"code\":\"F03\",\"name\":\"MFF2\",\"description\":\"MFF2\"}]}", "confType": "J", "remark": "JSON Array Object" }, { "confKey": "aws.s3.protocol", "confValue": "http", "confType": "T", "remark": "AWS S3 Protocol" }, { "confKey": "keycloak.server.protocol", "confValue": "http", "confType": "T", "remark": "Key Cloak server protocol" }, { "confKey": "aws.s3.path.upload.images", "confValue": "rd-images", "confType": "T", "remark": "AWS S3 path rd-images" }, { "confKey": "aws.s3.path.opm.allocatecardresult", "confValue": "rd-opm/allocate-card-result", "confType": "T", "remark": "AWS S3 path rd-opm/allocate-card-result" }, { "confKey": "aws.s3.path.opm.allocatecard", "confValue": "rd-opm/allocate-card", "confType": "T", "remark": "AWS S3 path rd-opm/allocate-card" }, { "confKey": "aws.s3.path.vendor.output", "confValue": "sim-vendor/output", "confType": "T", "remark": "AWS S3 path sim-vendor/output" }, { "confKey": "register.allocate.dealernumb", "confValue": "10000", "confType": "T", "remark": "Allocate Dealer Number" }] } }; | |
| const data = responseFromApi.data.mapResponse; | |
| interface Configuration { | |
| confKey?: string; | |
| confValue?: string; | |
| remark?: string; | |
| confType?: string; | |
| formControlName ?: string; | |
| } | |
| interface ConfigurationInfo { | |
| data: Configuration | Configuration[]; | |
| } | |
| const tmp: ConfigurationInfo = { | |
| data: <Configuration[]>[] | |
| } | |
| data.forEach((n) => { | |
| const transformData = { | |
| confKey: n.confKey, | |
| confValue: n.confValue, | |
| remark: n.remark, | |
| confType: n.confType, | |
| formControlName: n.confKey.replace(/\./g, '_') | |
| } | |
| tmp.data = [ | |
| ...<Configuration[]>tmp.data, | |
| transformData | |
| ]; | |
| }); | |
| console.log(tmp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment