This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
2017-04-27 04:47:03 +00:00
|
|
|
import { DataTypes, sequelize } from '../sequelize';
|
2016-08-24 07:37:54 +00:00
|
|
|
import randomstring from 'randomstring';
|
|
|
|
|
2017-06-26 00:21:33 +00:00
|
|
|
const ApiKey = sequelize.define(
|
|
|
|
'apiKeys',
|
2017-04-27 04:47:03 +00:00
|
|
|
{
|
|
|
|
id: {
|
|
|
|
type: DataTypes.UUID,
|
|
|
|
defaultValue: DataTypes.UUIDV4,
|
|
|
|
primaryKey: true,
|
2016-08-24 07:37:54 +00:00
|
|
|
},
|
2017-04-27 04:47:03 +00:00
|
|
|
name: DataTypes.STRING,
|
|
|
|
secret: { type: DataTypes.STRING, unique: true },
|
|
|
|
userId: {
|
|
|
|
type: DataTypes.UUID,
|
|
|
|
allowNull: false,
|
|
|
|
references: {
|
|
|
|
model: 'users',
|
|
|
|
},
|
2016-08-24 07:37:54 +00:00
|
|
|
},
|
|
|
|
},
|
2017-04-27 04:47:03 +00:00
|
|
|
{
|
|
|
|
tableName: 'apiKeys',
|
|
|
|
paranoid: true,
|
|
|
|
hooks: {
|
|
|
|
beforeValidate: key => {
|
|
|
|
key.secret = randomstring.generate(38);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2016-08-24 07:37:54 +00:00
|
|
|
|
2017-06-26 00:21:33 +00:00
|
|
|
export default ApiKey;
|