skailan-contacts
Version:
Servicio de gestión de contactos para Skailan
50 lines • 1.43 kB
JavaScript
export class Tag {
id;
organizationId;
name;
createdAt;
updatedAt;
constructor(id, organizationId, name, createdAt, updatedAt) {
this.id = id;
this.organizationId = organizationId;
this.name = name;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.validate();
}
validate() {
if (!this.id) {
throw new Error('Tag ID is required');
}
if (!this.organizationId) {
throw new Error('Organization ID is required');
}
if (!this.name || this.name.trim().length === 0) {
throw new Error('Tag name is required');
}
if (this.name.length > 50) {
throw new Error('Tag name must be less than 50 characters');
}
}
updateName(newName) {
if (!newName || newName.trim().length === 0) {
throw new Error('Tag name is required');
}
if (newName.length > 50) {
throw new Error('Tag name must be less than 50 characters');
}
this.name = newName.trim();
this.updatedAt = new Date();
this.validate();
}
toJSON() {
return {
id: this.id,
organizationId: this.organizationId,
name: this.name,
createdAt: this.createdAt,
updatedAt: this.updatedAt
};
}
}
//# sourceMappingURL=Tag.js.map