2022-03-10 02:23:17 +01:00
|
|
|
const { getId } = require('../../utils/index')
|
|
|
|
|
2022-03-09 02:31:44 +01:00
|
|
|
class Author {
|
|
|
|
constructor(author) {
|
|
|
|
this.id = null
|
|
|
|
this.asin = null
|
|
|
|
this.name = null
|
|
|
|
this.imagePath = null
|
2022-03-10 02:23:17 +01:00
|
|
|
this.relImagePath = null
|
2022-03-09 02:31:44 +01:00
|
|
|
this.addedAt = null
|
|
|
|
this.updatedAt = null
|
|
|
|
|
|
|
|
if (author) {
|
|
|
|
this.construct(author)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
construct(author) {
|
|
|
|
this.id = author.id
|
|
|
|
this.asin = author.asin
|
|
|
|
this.name = author.name
|
|
|
|
this.imagePath = author.imagePath
|
2022-03-10 02:23:17 +01:00
|
|
|
this.relImagePath = author.relImagePath
|
2022-03-09 02:31:44 +01:00
|
|
|
this.addedAt = author.addedAt
|
|
|
|
this.updatedAt = author.updatedAt
|
|
|
|
}
|
|
|
|
|
|
|
|
toJSON() {
|
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
asin: this.asin,
|
|
|
|
name: this.name,
|
|
|
|
imagePath: this.imagePath,
|
2022-03-10 02:23:17 +01:00
|
|
|
relImagePath: this.relImagePath,
|
2022-03-09 02:31:44 +01:00
|
|
|
addedAt: this.addedAt,
|
2022-03-10 02:23:17 +01:00
|
|
|
lastUpdate: this.updatedAt
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toJSONMinimal() {
|
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
name: this.name
|
|
|
|
}
|
|
|
|
}
|
2022-03-10 02:23:17 +01:00
|
|
|
|
|
|
|
setData(data) {
|
|
|
|
this.id = getId('aut')
|
|
|
|
this.name = data.name
|
|
|
|
this.asin = data.asin || null
|
|
|
|
this.imagePath = data.imagePath || null
|
|
|
|
this.relImagePath = data.relImagePath || null
|
|
|
|
this.addedAt = Date.now()
|
|
|
|
this.updatedAt = Date.now()
|
|
|
|
}
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
module.exports = Author
|