@umbraco/json-models-builders
Version:
Builders and models for Umbraco Sites
82 lines • 2.29 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MemberBuilder = void 0;
const memberValueBuilder_1 = require("./memberValueBuilder");
const memberVariantBuilder_1 = require("./memberVariantBuilder");
class MemberBuilder {
memberValueBuilder;
memberVariantBuilder;
id;
email;
username;
password;
memberTypeId;
groups;
isApproved;
constructor() {
this.memberValueBuilder = [];
this.memberVariantBuilder = [];
this.groups = [];
}
addValue() {
const builder = new memberValueBuilder_1.MemberValueBuilder(this);
this.memberValueBuilder.push(builder);
return builder;
}
addVariant() {
const builder = new memberVariantBuilder_1.MemberVariantBuilder(this);
this.memberVariantBuilder.push(builder);
return builder;
}
withId(id) {
this.id = id;
return this;
}
withEmail(email) {
this.email = email;
return this;
}
withUsername(username) {
this.username = username;
return this;
}
withPassword(password) {
this.password = password;
return this;
}
withMemberTypeId(memberTypeId) {
this.memberTypeId = memberTypeId;
return this;
}
addGroup(group) {
this.groups.push(group);
return this;
}
withIsApproved(isApproved) {
this.isApproved = isApproved;
return this;
}
build() {
if (this.id == null) {
const crypto = require('crypto');
this.id = crypto.randomUUID();
}
return {
values: this.memberValueBuilder.map((builder) => {
return builder.build();
}) || [],
variants: this.memberVariantBuilder.map((builder) => {
return builder.build();
}) || [],
id: this.id,
email: this.email || "",
username: this.username || "",
password: this.password || "",
memberType: { id: this.memberTypeId },
groups: this.groups || [],
isApproved: this.isApproved || false
};
}
}
exports.MemberBuilder = MemberBuilder;
//# sourceMappingURL=memberBuilder.js.map