automatically quickmatch new authors

This commit is contained in:
MxMarx 2023-10-10 21:49:25 -07:00
parent 753ae3d7dc
commit 060cfe6e86
4 changed files with 97 additions and 58 deletions

View file

@ -1,4 +1,5 @@
const { DataTypes, Model, where, fn, col } = require('sequelize')
const { nameToLastFirst } = require('../utils/parsers/parseNameString')
const oldAuthor = require('../objects/entities/Author')
@ -166,6 +167,12 @@ class Author extends Model {
onDelete: 'CASCADE'
})
Author.belongsTo(library)
Author.addHook('beforeCreate', async (author) => {
if (!author || author.lastFirst) return
author.lastFirst = nameToLastFirst(author.name)
})
}
}
module.exports = Author