All files / lib create-order-request.js

69.27% Statements 115/166
27.27% Branches 3/11
11.53% Functions 3/26
69.27% Lines 115/166

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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 1661x 1x 1x 1x 1x 1x 1x 20x 20x 20x 20x 20x 20x 20x 1x 1x 1x 1x     1x 1x     1x 1x     1x 1x     1x 1x 1x 1x 1x 1x     1x 1x     1x 1x     1x 1x     1x 1x 1x 1x 1x 1x     1x 1x     1x 1x     1x 1x     1x 1x 1x 1x 1x 1x     1x 1x     1x 1x     1x 1x     1x 1x 1x 1x 1x 1x 40x 40x 1x 1x     1x 1x     1x 1x     1x 1x 1x 1x 1x 1x     1x 1x     1x 1x     1x 1x     1x 1x 1x 1x 20x     20x 20x     20x 20x 20x 20x 20x 20x 20x   20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 1x 1x 1x
'use strict';
const { CertificateParameters } = require('./certificate-parameters');
const { CertificateKinds } = require('./enums');
 
class CreateOrderRequest {
 
	constructor({ caId, templateId, kind, copyToCertificate, parameters, validityEnd } = {}) {
		this._caId = caId || null;
		this._templateId = templateId || null;
		this._kind = kind || null;
		this._copyToCertificate = copyToCertificate || null;
		this._parameters = parameters || null;
		this._validityEnd = validityEnd || null;
	}
 
	//region "caId" Accessors
 
	getCAId() {
		return this._caId;
	}
 
	get caId() {
		return this._caId;
	}
 
	setCAId(value) {
		this._caId = value;
	}
 
	set caId(value) {
		this._caId = value;
	}
 
	//endregion
 
	//region "templateId" Accessors
 
	getTemplateId() {
		return this._templateId;
	}
 
	get templateId() {
		return this._templateId;
	}
 
	setTemplateId(value) {
		this._templateId = value;
	}
 
	set templateId(value) {
		this._templateId = value;
	}
 
	//endregion
 
	//region "kind" Accessors
 
	getKind() {
		return this._kind;
	}
 
	get kind() {
		return this._kind;
	}
 
	setKind(value) {
		this._kind = value;
	}
 
	set kind(value) {
		this._kind = value;
	}
 
	//endregion
 
	//region "copyToTemplate" Accessors
 
	getCopyToTemplate() {
		return this._copyToTemplate;
	}
 
	get copyToTemplate() {
		return this._copyToTemplate;
	}
 
	setCopyToTemplate(value) {
		this._copyToTemplate = value;
	}
 
	set copyToTemplate(value) {
		this._copyToTemplate = value;
	}
 
	//endregion
 
	//region "parameters" Accessors
 
	getParameters() {
		return this._parameters;
	}
 
	get parameters() {
		return this._parameters;
	}
 
	setParameters(value) {
		this._parameters = value;
	}
 
	set parameters(value) {
		this._parameters = value;
	}
 
	//endregion
 
	//region "validityEnd" Accessors
 
	getValidityEnd() {
		return this._validityEnd;
	}
 
	get validityEnd() {
		return this._validityEnd;
	}
 
	setValidityEnd(value) {
		this._validityEnd = value;
	}
 
	set validityEnd(value) {
		this._validityEnd = value;
	}
 
	//endregion
 
	toModel() {
		if (!this._parameters) {
			throw new Error('The "parameters" field was not set');
		}
 
		if (this._parameters && !(this._parameters instanceof CertificateParameters)) {
			throw new Error(`Unsupported type for "parameters" on model for CreateOrderRequest: ${typeof(this._parameters)}`);
		}
 
		if (this._kind) {
			switch (this._kind) {
			case CertificateKinds.PUBLIC_KEY:
			case CertificateKinds.ATTRIBUTE:
				break;
			default:
				throw new Error(`Unsupported "kind" field on model for CreateOrderRequest: ${this._kind}`);
			}
		}
 
		return {
			caId: this._caId,
			templateId: this._templateId,
			kind: this._kind,
			copyToTemplate: this._copyToTemplate,
			parameters: this._parameters ? this._parameters.toModel() : null,
			validityEnd: this._validityEnd
		};
	}
}
 
exports.CreateOrderRequest = CreateOrderRequest;