2023-07-05 01:14:44 +02:00
|
|
|
const uuidv4 = require("uuid").v4
|
2023-08-19 00:08:34 +02:00
|
|
|
const { getTitleIgnorePrefix, getTitlePrefixAtEnd } = require('../../utils/index')
|
2022-03-10 02:23:17 +01:00
|
|
|
|
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
|
2023-07-08 16:57:32 +02:00
|
|
|
this.libraryId = null
|
2022-03-09 02:31:44 +01:00
|
|
|
|
|
|
|
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
|
2023-07-08 16:57:32 +02:00
|
|
|
this.libraryId = series.libraryId
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
|
2023-07-29 01:03:31 +02:00
|
|
|
get nameIgnorePrefix() {
|
|
|
|
if (!this.name) return ''
|
|
|
|
return getTitleIgnorePrefix(this.name)
|
|
|
|
}
|
|
|
|
|
2022-03-09 02:31:44 +01:00
|
|
|
toJSON() {
|
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
name: this.name,
|
2023-08-19 00:08:34 +02:00
|
|
|
nameIgnorePrefix: getTitlePrefixAtEnd(this.name),
|
2022-03-13 12:42:43 +01:00
|
|
|
description: this.description,
|
2022-03-09 02:31:44 +01:00
|
|
|
addedAt: this.addedAt,
|
2023-07-08 16:57:32 +02:00
|
|
|
updatedAt: this.updatedAt,
|
|
|
|
libraryId: this.libraryId
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2023-07-08 16:57:32 +02:00
|
|
|
setData(data, libraryId) {
|
2023-07-05 01:14:44 +02:00
|
|
|
this.id = uuidv4()
|
2022-03-10 02:23:17 +01:00
|
|
|
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()
|
2023-07-08 16:57:32 +02:00
|
|
|
this.libraryId = libraryId
|
2022-03-10 02:23:17 +01:00
|
|
|
}
|
2022-03-13 00:45:32 +01:00
|
|
|
|
2022-09-28 00:48:45 +02:00
|
|
|
update(series) {
|
|
|
|
if (!series) return false
|
2022-09-29 00:12:27 +02:00
|
|
|
const keysToUpdate = ['name', 'description']
|
2022-12-26 23:08:53 +01:00
|
|
|
let hasUpdated = false
|
2022-09-28 00:48:45 +02:00
|
|
|
for (const key of keysToUpdate) {
|
|
|
|
if (series[key] !== undefined && series[key] !== this[key]) {
|
|
|
|
this[key] = series[key]
|
|
|
|
hasUpdated = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hasUpdated
|
|
|
|
}
|
|
|
|
|
2022-03-13 00:45:32 +01:00
|
|
|
checkNameEquals(name) {
|
2022-05-23 04:56:51 +02:00
|
|
|
if (!name || !this.name) return false
|
2022-03-13 00:45:32 +01:00
|
|
|
return this.name.toLowerCase() == name.toLowerCase().trim()
|
|
|
|
}
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
module.exports = Series
|