skailan-contacts
Version:
Servicio de gestión de contactos para Skailan
86 lines • 2.76 kB
JavaScript
export class ContactCommunicationPlatform {
id;
contactId;
organizationId;
platform;
platformUserId;
platformUsername;
isActive;
isPrimary;
config;
createdAt;
updatedAt;
constructor(id, contactId, organizationId, platform, platformUserId, platformUsername, isActive, isPrimary, config, createdAt, updatedAt) {
this.id = id;
this.contactId = contactId;
this.organizationId = organizationId;
this.platform = platform;
this.platformUserId = platformUserId;
this.platformUsername = platformUsername;
this.isActive = isActive;
this.isPrimary = isPrimary;
this.config = config;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.validate();
}
validate() {
if (!this.id) {
throw new Error('Platform ID is required');
}
if (!this.contactId) {
throw new Error('Contact ID is required');
}
if (!this.organizationId) {
throw new Error('Organization ID is required');
}
if (!this.platform) {
throw new Error('Platform is required');
}
const validPlatforms = ['whatsapp', 'telegram', 'email', 'sms', 'facebook', 'instagram'];
if (!validPlatforms.includes(this.platform)) {
throw new Error(`Invalid platform: ${this.platform}. Valid platforms are: ${validPlatforms.join(', ')}`);
}
}
updatePlatformInfo(platformUserId, platformUsername, isActive, isPrimary, config) {
this.platformUserId = platformUserId;
this.platformUsername = platformUsername;
this.isActive = isActive;
this.isPrimary = isPrimary;
this.config = config;
this.updatedAt = new Date();
this.validate();
}
activate() {
this.isActive = true;
this.updatedAt = new Date();
}
deactivate() {
this.isActive = false;
this.updatedAt = new Date();
}
setAsPrimary() {
this.isPrimary = true;
this.updatedAt = new Date();
}
setAsSecondary() {
this.isPrimary = false;
this.updatedAt = new Date();
}
toJSON() {
return {
id: this.id,
contactId: this.contactId,
organizationId: this.organizationId,
platform: this.platform,
platformUserId: this.platformUserId,
platformUsername: this.platformUsername,
isActive: this.isActive,
isPrimary: this.isPrimary,
config: this.config,
createdAt: this.createdAt,
updatedAt: this.updatedAt
};
}
}
//# sourceMappingURL=ContactCommunicationPlatform.js.map