All files / lib order.js

64.44% Statements 145/225
71.42% Branches 10/14
25% Functions 9/36
64.44% Lines 145/225

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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 2261x 1x 1x 1x 1x 1x 1x 33x 33x 33x 33x 33x 33x 33x 33x 1x 1x 1x 1x     1x 1x 60x 60x 1x 1x     1x 1x     1x 1x 1x 1x 1x 1x     1x 1x 26x 26x 1x 1x     1x 1x     1x 1x 1x 1x 1x 1x     1x 1x 2x 2x 1x 1x     1x 1x     1x 1x 1x 1x 1x 1x     1x 1x 26x 26x 1x 1x     1x 1x     1x 1x 1x 1x 1x 1x     1x 1x 2x 2x 1x 1x     1x 1x     1x 1x 1x 1x 1x 1x     1x 1x 26x 26x 1x 1x     1x 1x     1x 1x 1x 1x 1x 1x     1x 1x 26x 26x 1x 1x     1x 1x     1x 1x 1x 1x                                             1x 1x 1x 1x 1x 33x 33x 33x 33x 33x 33x 33x 1x 1x 1x 1x     1x 1x     1x 1x     1x 1x     1x 1x 1x 1x                 1x 1x 1x 1x  
'use strict';
const { OrderStatus } = require('./enums');
const { CertificateParameters } = require('./certificate-parameters');
 
class BaseOrder {
 
	constructor({ id, caId, templateId, alias, emailAddress, certificateId, status } = {}) {
		this._id = id || null;
		this._caId = caId || null;
		this._templateId = templateId || null;
		this._alias = alias || null;
		this._emailAddress = emailAddress || null;
		this._certificateId = certificateId || null;
		this._status = status || null;
	}
 
	//region "id" Accessors
 
	getId() {
		return this._id;
	}
 
	get id() {
		return this._id;
	}
 
	setId(value) {
		this._id = value;
	}
 
	set id(value) {
		this._id = value;
	}
 
	//endregion
 
	//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 "alias" Accessors
 
	getAlias() {
		return this._alias;
	}
 
	get alias() {
		return this._alias;
	}
 
	setAlias(value) {
		this._alias = value;
	}
 
	set alias(value) {
		this._alias = value;
	}
 
	//endregion
 
	//region "emailAddress" Accessors
 
	getEmailAddress() {
		return this._emailAddress;
	}
 
	get emailAddress() {
		return this._emailAddress;
	}
 
	setEmailAddress(value) {
		this._emailAddress = value;
	}
 
	set emailAddress(value) {
		this._emailAddress = value;
	}
 
	//endregion
 
	//region "certificateId" Accessors
 
	getCertificateId() {
		return this._certificateId;
	}
 
	get certificateId() {
		return this._certificateId;
	}
 
	setCertificateId(value) {
		this._certificateId = value;
	}
 
	set certificateId(value) {
		this._certificateId = value;
	}
 
	//endregion
 
	//region "status" Accessors
 
	getStatus() {
		return this._status;
	}
 
	get status() {
		return this._status;
	}
 
	setStatus(value) {
		this._status = value;
	}
 
	set status(value) {
		this._status = value;
	}
 
	//endregion
 
	toModel() {

		if (this._status) {
			switch (this._status) {
			case OrderStatus.PENDING:
			case OrderStatus.LOCKED:
			case OrderStatus.ISSUED:
				break;
			default:
				throw new Error(`Unsupported "status" field on model for BaseOrder: ${this._status}`);
			}
		}

		return {
			id: this._id,
			caId: this._caId,
			templateId: this._templateId,
			alias: this._alias,
			emailAddress: this._emailAddress,
			certificateId: this._certificateId,
			status: this._status
		};
	}
}
 
class Order extends BaseOrder {
 
	constructor({ parameters, ...model } = {}) {
		super(model);
		this._parameters = null;
 
		if (parameters) {
			this._parameters = CertificateParameters.decode(parameters);
		}
	}
 
	//region "parameters" Accessors
 
	getParameters() {
		return this._parameters;
	}
 
	get parameters() {
		return this._parameters;
	}
 
	setParameters(value) {
		this._parameters = value;
	}
 
	set parameters(value) {
		this._parameters = value;
	}
 
	//endregion
 
	toModel() {
		if (this._parameters && !(this._parameters instanceof CertificateParameters)) {
			throw new Error(`Unsupported type for "parameters" on model for Order: ${typeof (this._parameters)}`);
		}

		let model = super.toModel();
		model['parameters'] = this._parameters ? this._parameters.toModel() : null;
		return model;
	}
}
 
exports.BaseOrder = BaseOrder;
exports.Order = Order;