-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-token.model.js
More file actions
47 lines (44 loc) · 984 Bytes
/
api-token.model.js
File metadata and controls
47 lines (44 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { DataTypes } from 'sequelize';
import { sequelize } from '../config/database.js';
import User from './user.model.js';
const ApiToken = sequelize.define('ApiToken', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
user_id: {
type: DataTypes.UUID,
allowNull: false,
references: { model: User, key: 'id' },
},
name: {
type: DataTypes.STRING(64),
allowNull: false,
},
token_hash: {
type: DataTypes.CHAR(64),
allowNull: false,
unique: true,
},
token_prefix: {
type: DataTypes.STRING(8),
allowNull: false,
},
last_used_at: {
type: DataTypes.DATE,
allowNull: true,
},
revoked_at: {
type: DataTypes.DATE,
allowNull: true,
},
}, {
tableName: 'api_tokens',
timestamps: true,
updatedAt: false,
underscored: true,
});
User.hasMany(ApiToken, { foreignKey: 'user_id' });
ApiToken.belongsTo(User, { foreignKey: 'user_id' });
export default ApiToken;