-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpairing-code.model.js
More file actions
51 lines (48 loc) · 1.23 KB
/
pairing-code.model.js
File metadata and controls
51 lines (48 loc) · 1.23 KB
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
48
49
50
51
import { DataTypes } from 'sequelize';
import { sequelize } from '../config/database.js';
import User from './user.model.js';
import ApiToken from './api-token.model.js';
const PairingCode = sequelize.define('PairingCode', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
user_code: {
type: DataTypes.STRING(9),
allowNull: false,
},
status: {
type: DataTypes.ENUM('pending', 'approved', 'consumed'),
allowNull: false,
defaultValue: 'pending',
},
user_id: {
type: DataTypes.UUID,
allowNull: true,
references: { model: User, key: 'id' },
},
api_token_id: {
type: DataTypes.UUID,
allowNull: true,
references: { model: ApiToken, key: 'id' },
},
token_plaintext: {
type: DataTypes.TEXT,
allowNull: true,
},
expires_at: {
type: DataTypes.DATE,
allowNull: false,
},
}, {
tableName: 'pairing_codes',
timestamps: true,
updatedAt: false,
underscored: true,
});
User.hasMany(PairingCode, { foreignKey: 'user_id' });
PairingCode.belongsTo(User, { foreignKey: 'user_id' });
ApiToken.hasOne(PairingCode, { foreignKey: 'api_token_id' });
PairingCode.belongsTo(ApiToken, { foreignKey: 'api_token_id' });
export default PairingCode;