All files / src index.ts

92.85% Statements 26/28
100% Branches 2/2
93.33% Functions 14/15
92.85% Lines 26/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 921x 1x 1x     1x         3x       1x 1x 1x   1x                 2x 2x 1x     1x 1x 1x 1x 1x               2x             2x             1x           1x           1x         1x       1x       1x         1x      
import xml2js from 'xml2js';
import { Util } from './service/util';
import { SourceId, CtrXml, RescoreCtrXml, RescoreAltCtrXml, SoapEnvelope, Score, Scores, OverallCrInfo } from './service/xml-obj-builder';
 
 
export class XmlJson {
 
    private xml2js: any;
 
    constructor() {
        this.xml2js = xml2js;
    }
 
    public async toJson(xml: string) {
        return new Promise((resolve, reject) => {
            const parser = new this.xml2js.Parser();
            parser.parseStringPromise(xml)
                .then((result: any) => {
                    return resolve(JSON.stringify(result));
                })
                .catch((err: any) => {
                    return reject(err);
                });
            });
    }
 
    public async toXml(json: any) {
        return new Promise((resolve, reject) => {
            if (!Util.isJson(json)) {
                return reject(`Invalid JSON`);
            }
 
            const option = { renderOpts: { pretty: true, indent: ' ', newline: '\n' }, cdata: true };
            const builder = new this.xml2js.Builder(option);
            try {
                let xml = builder.buildObject(json);
                return resolve(xml);
            } catch(err: any) {
                return reject(err);
            }
        });
    }
 
    public buildSourceIdJson(processType: string, programCode: string, testCode: string) {
        return SourceId.getObject(processType, programCode, testCode);
 
    }
 
    public buildCtrXmlJson(registSystemId: string, adminCode: string, etsCandidateId: string, 
        apuid: string, testPackageId: string, subformCode: string) {
        
        return CtrXml.getObject(registSystemId, adminCode, etsCandidateId, 
            apuid, testPackageId, subformCode);
 
    }
 
    public buildRescoreCtrXmlJson(registSystemId: string, oppRegistSystemId: string, oppId: string, ctrId: string, adminCode: string, transId: string, testPackageId: string, subformCode: string, accnum: string, statusDate: string) {
        
        return RescoreCtrXml.getObject(registSystemId, oppRegistSystemId, oppId, ctrId, adminCode, transId, testPackageId, subformCode, accnum, statusDate);
 
    }
 
    public buildRescoreAltCtrXmlJson(registSystemId: string, ctrId: string, adminCode: string, transId: string, testPackageId: string, subformCode: string, accnum: string) {
        
        return RescoreAltCtrXml.getObject(registSystemId, ctrId, adminCode, transId, testPackageId, subformCode, accnum);
 
    }
 
    public buildSoapEnvelopeJson(usernameTag: string, pwTag: string, sourceId: any, ctrXml: any) {
        
        return SoapEnvelope.getObject(usernameTag, pwTag, sourceId, ctrXml);
 
    }
 
    public buildRaterScoreJson(scoreValue: string, scoreModeCode: string, vartype: string, scoreCompletionDate: string) {
        return Score.getObject(scoreValue, scoreModeCode, vartype, scoreCompletionDate);
    }
 
    public buildDimensionRatingInfoJson(scorerId: string, scoringCenter: string, scoreDate: string, scoreModeCode: string, scoreResultTypeCode: string, scorerComment: string[], scoreValue: string, scoreDomainCode: string) {
        return Scores.getObject(scorerId, scoringCenter, scoreDate, scoreModeCode, scoreResultTypeCode, scorerComment, scoreValue, scoreDomainCode);
    }
 
    public buildOverallCrInfoJson(resultTypeCode: string, raterScore: string) {
        return OverallCrInfo.getObject(resultTypeCode, raterScore);
    }
 
}
 
export class SoapInterface {
 
 
}