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
631 B
JavaScript
Raw Permalink Normal View History

// @flow
import randomstring from "randomstring";
import { DataTypes, sequelize } from "../sequelize";
2016-08-24 07:37:54 +00:00
const ApiKey = sequelize.define(
"apiKey",
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 },
2016-08-24 07:37:54 +00:00
},
2017-04-27 04:47:03 +00:00
{
paranoid: true,
hooks: {
beforeValidate: (key) => {
2017-04-27 04:47:03 +00:00
key.secret = randomstring.generate(38);
},
},
}
);
2016-08-24 07:37:54 +00:00
ApiKey.associate = (models) => {
ApiKey.belongsTo(models.User, {
as: "user",
foreignKey: "userId",
});
};
export default ApiKey;