feat: Create access tokens model
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
export async function up(knex) {
|
||||||
|
return knex.schema.createTable('access_tokens', (table) => {
|
||||||
|
table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()'));
|
||||||
|
table.string('token').notNullable();
|
||||||
|
table.integer('expires_in').notNullable();
|
||||||
|
table.timestamp('revoked_at').nullable();
|
||||||
|
table.uuid('user_id').references('id').inTable('users');
|
||||||
|
|
||||||
|
table.timestamps(true, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex) {
|
||||||
|
return knex.schema.dropTable('access_tokens');
|
||||||
|
}
|
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;
|
@@ -8,6 +8,7 @@ import userAbility from '../helpers/user-ability.js';
|
|||||||
import createAuthTokenByUserId from '../helpers/create-auth-token-by-user-id.js';
|
import createAuthTokenByUserId from '../helpers/create-auth-token-by-user-id.js';
|
||||||
import Base from './base.js';
|
import Base from './base.js';
|
||||||
import App from './app.js';
|
import App from './app.js';
|
||||||
|
import AccessToken from './access-token.js';
|
||||||
import Connection from './connection.js';
|
import Connection from './connection.js';
|
||||||
import Execution from './execution.js';
|
import Execution from './execution.js';
|
||||||
import Flow from './flow.js';
|
import Flow from './flow.js';
|
||||||
@@ -42,6 +43,14 @@ class User extends Base {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static relationMappings = () => ({
|
static relationMappings = () => ({
|
||||||
|
accessTokens: {
|
||||||
|
relation: Base.HasManyRelation,
|
||||||
|
modelClass: AccessToken,
|
||||||
|
join: {
|
||||||
|
from: 'users.id',
|
||||||
|
to: 'access_tokens.user_id',
|
||||||
|
},
|
||||||
|
},
|
||||||
connections: {
|
connections: {
|
||||||
relation: Base.HasManyRelation,
|
relation: Base.HasManyRelation,
|
||||||
modelClass: Connection,
|
modelClass: Connection,
|
||||||
|
Reference in New Issue
Block a user