mirror of
https://github.com/tornadocash/trusted-setup-server.git
synced 2024-11-01 16:15:19 +01:00
41 lines
978 B
JavaScript
41 lines
978 B
JavaScript
'use strict'
|
|
|
|
const validate = (contribution, options) => {
|
|
const { name, company, socialType } = contribution.dataValues
|
|
if (socialType !== 'anonymous' && (name.length < 4 || name.length > 35)) {
|
|
throw new Error('Wrong name')
|
|
}
|
|
if (company && company.length > 35) {
|
|
throw new Error('Wrong company')
|
|
}
|
|
}
|
|
|
|
module.exports = (sequelize, DataTypes) => {
|
|
const Contribution = sequelize.define(
|
|
'Contribution',
|
|
{
|
|
token: DataTypes.STRING,
|
|
name: DataTypes.STRING,
|
|
company: DataTypes.STRING,
|
|
handle: DataTypes.STRING,
|
|
socialType: DataTypes.STRING,
|
|
hash: DataTypes.STRING
|
|
},
|
|
{
|
|
hooks: {
|
|
beforeCreate: validate,
|
|
beforeUpdate: validate
|
|
}
|
|
}
|
|
)
|
|
Contribution.nextContributionIndex = async function() {
|
|
const rowsCount = await this.count()
|
|
return rowsCount + 1
|
|
}
|
|
|
|
Contribution.associate = function(models) {
|
|
// associations can be defined here
|
|
}
|
|
return Contribution
|
|
}
|