feat: Create access tokens model
This commit is contained in:
32
packages/backend/src/models/access-token.js
Normal file
32
packages/backend/src/models/access-token.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import Base from './base.js';
|
||||
import User from './user.js';
|
||||
|
||||
class AccessToken extends Base {
|
||||
static tableName = 'access_tokens';
|
||||
|
||||
static jsonSchema = {
|
||||
type: 'object',
|
||||
required: ['token', 'expiresIn'],
|
||||
|
||||
properties: {
|
||||
id: { type: 'string', format: 'uuid' },
|
||||
userId: { type: 'string', format: 'uuid' },
|
||||
token: { type: 'string', minLength: 32 },
|
||||
expiresIn: { type: 'integer' },
|
||||
revokedAt: { type: ['string', 'null'], format: 'date-time' },
|
||||
},
|
||||
};
|
||||
|
||||
static relationMappings = () => ({
|
||||
user: {
|
||||
relation: Base.BelongsToOneRelation,
|
||||
modelClass: User,
|
||||
join: {
|
||||
from: 'access_tokens.user_id',
|
||||
to: 'users.id',
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export default AccessToken;
|
Reference in New Issue
Block a user