CentralBackend/models/Affiliate.js

63 lines
1.5 KiB
JavaScript

class Affiliate {
constructor({
id = null,
name = '',
description = '',
url = '',
object_storage_id = null,
original_filename = null,
category = '',
is_active = true,
commission_rate = null,
created_at = null,
updated_at = null
}) {
this.id = id;
this.name = name;
this.description = description;
this.url = url;
this.object_storage_id = object_storage_id;
this.original_filename = original_filename;
this.category = category;
this.is_active = is_active;
this.commission_rate = commission_rate;
this.created_at = created_at;
this.updated_at = updated_at;
}
static fromDbRow(row) {
if (!row) return null;
return new Affiliate({
id: row.id,
name: row.name,
description: row.description,
url: row.url,
object_storage_id: row.object_storage_id,
original_filename: row.original_filename,
category: row.category,
is_active: row.is_active === 1 || row.is_active === true,
commission_rate: row.commission_rate,
created_at: row.created_at,
updated_at: row.updated_at
});
}
toJSON() {
return {
id: this.id,
name: this.name,
description: this.description,
url: this.url,
object_storage_id: this.object_storage_id,
original_filename: this.original_filename,
category: this.category,
is_active: this.is_active,
commission_rate: this.commission_rate,
created_at: this.created_at,
updated_at: this.updated_at
};
}
}
module.exports = Affiliate;