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.
outline/server/models/ApiKey.js

34 lines
654 B
JavaScript
Raw Normal View History

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';
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
export default ApiKey;