diff --git a/models/sql/torrent.js b/models/sql/torrent.js index 3df71ae..1db99d1 100644 --- a/models/sql/torrent.js +++ b/models/sql/torrent.js @@ -61,11 +61,6 @@ module.exports = (sequelize, DataTypes, Model) => { static async create(data, ...args){ try{ - - // let instance = this.build(data); - // console.log('instance', instance) - await this.build(data).validate(); - // console.log('validate', val); data.isPrivate = data.isPrivate === 'true' ? true : false; let options = { @@ -89,7 +84,7 @@ module.exports = (sequelize, DataTypes, Model) => { throw error; } - return await super.create({ + let createData = { magnetLink: data.magnetLink, hashString, isPrivate: data.isPrivate, @@ -98,7 +93,12 @@ module.exports = (sequelize, DataTypes, Model) => { category: this.categoryFromTPB(data.category), status: 0, percentDone: 0, - }, args); + }; + + // Validate only after hashString is populated. + await this.build(createData).validate(); + + return await super.create(createData, args); }catch (error){ console.log('Torrent create error', error); throw error;