2022-03-10 02:23:17 +01:00
|
|
|
const { getId } = require('../../utils/index')
|
|
|
|
|
2022-03-09 02:31:44 +01:00
|
|
|
class Series {
|
|
|
|
constructor(series) {
|
|
|
|
this.id = null
|
|
|
|
this.name = null
|
2022-03-13 12:42:43 +01:00
|
|
|
this.description = null
|
2022-03-09 02:31:44 +01:00
|
|
|
this.addedAt = null
|
|
|
|
this.updatedAt = null
|
|
|
|
|
|
|
|
if (series) {
|
|
|
|
this.construct(series)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
construct(series) {
|
|
|
|
this.id = series.id
|
|
|
|
this.name = series.name
|
2022-03-13 12:42:43 +01:00
|
|
|
this.description = series.description || null
|
2022-03-09 02:31:44 +01:00
|
|
|
this.addedAt = series.addedAt
|
|
|
|
this.updatedAt = series.updatedAt
|
|
|
|
}
|
|
|
|
|
|
|
|
toJSON() {
|
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
name: this.name,
|
2022-03-13 12:42:43 +01:00
|
|
|
description: this.description,
|
2022-03-09 02:31:44 +01:00
|
|
|
addedAt: this.addedAt,
|
|
|
|
updatedAt: this.updatedAt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-10 02:23:17 +01:00
|
|
|
toJSONMinimal(sequence) {
|
2022-03-09 02:31:44 +01:00
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
name: this.name,
|
2022-03-10 02:23:17 +01:00
|
|
|
sequence
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-10 02:23:17 +01:00
|
|
|
|
|
|
|
setData(data) {
|
|
|
|
this.id = getId('ser')
|
|
|
|
this.name = data.name
|
2022-03-13 12:42:43 +01:00
|
|
|
this.description = data.description || null
|
2022-03-10 02:23:17 +01:00
|
|
|
this.addedAt = Date.now()
|
|
|
|
this.updatedAt = Date.now()
|
|
|
|
}
|
2022-03-13 00:45:32 +01:00
|
|
|
|
|
|
|
checkNameEquals(name) {
|
|
|
|
if (!name) return false
|
|
|
|
return this.name.toLowerCase() == name.toLowerCase().trim()
|
|
|
|
}
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
module.exports = Series
|