Skip to content

Commit

Permalink
Merge pull request #132 from infinitybase/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
guimroque authored Jun 27, 2024
2 parents 5453564 + 6aa8fec commit b4748fc
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/api/src/models/Notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,13 @@ class Notification extends Base {
}

export { Notification };


// -- Criação de índice para a coluna 'user_id'
// CREATE INDEX idx_notifications_user_id ON notifications(user_id);

// -- Criação de índice para a coluna 'title'
// CREATE INDEX idx_notifications_title ON notifications(title);

// -- Criação de índice para a coluna 'read'
// CREATE INDEX idx_notifications_read ON notifications(read);
10 changes: 10 additions & 0 deletions packages/api/src/models/Predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,13 @@ class Predicate extends Base {
}

export { Predicate };

// -- Criação de índice para a coluna 'owner_id' na tabela 'predicates'
// CREATE INDEX idx_predicates_owner_id ON predicates(owner_id);

// -- Criação de índice para a coluna 'workspace_id' na tabela 'predicates'
// CREATE INDEX idx_predicates_workspace_id ON predicates(workspace_id);

// -- Criação de índice para a coluna 'version_id' na tabela 'predicates'
// CREATE INDEX idx_predicates_version_id ON predicates(version_id);

12 changes: 12 additions & 0 deletions packages/api/src/models/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,15 @@ class Transaction extends Base {
}

export { Transaction };

// -- Criação de índice para a coluna 'transaction_id' na tabela 'assets'
// CREATE INDEX idx_assets_transaction_id ON assets(transaction_id);

// -- Criação de índice para a coluna 'transaction_id' na tabela 'witnesses'
// CREATE INDEX idx_witnesses_transaction_id ON witnesses(transaction_id);

// -- Criação de índice para a coluna 'predicate_id' na tabela 'transactions'
// CREATE INDEX idx_transactions_predicate_id ON transactions(predicate_id);

// -- Criação de índice para a coluna 'created_by' na tabela 'transactions'
// CREATE INDEX idx_transactions_created_by ON transactions(created_by);
12 changes: 12 additions & 0 deletions packages/api/src/models/UserToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,15 @@ class UserToken extends Base {
}

export default UserToken;

// -- Criação de índice para a coluna 'workspace_id' na tabela 'user_tokens'
// CREATE INDEX idx_user_tokens_workspace_id ON user_tokens(workspace_id);

// -- Criação de índice para a coluna 'user_id' na tabela 'user_tokens'
// CREATE INDEX idx_user_tokens_user_id ON user_tokens(user_id);

// -- Criação de índice para a coluna 'encoder' na tabela 'user_tokens'
// CREATE INDEX idx_user_tokens_encoder ON user_tokens(encoder);

// -- Criação de índice para a coluna 'expired_at' na tabela 'user_tokens'
// CREATE INDEX idx_user_tokens_expired_at ON user_tokens(expired_at);
12 changes: 12 additions & 0 deletions packages/api/src/models/Workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,15 @@ class Workspace extends Base {
}

export { Workspace };

// -- Criação de índice para a coluna 'owner_id' na tabela 'workspace'
// CREATE INDEX idx_workspace_owner_id ON workspace(owner_id);

// -- Criação de índice para a coluna 'workspace_id' na tabela 'predicates'
// CREATE INDEX idx_predicates_workspace_id ON predicates(workspace_id);

// -- Criação de índice para a coluna 'workspace_id' na tabela 'workspace_users'
// CREATE INDEX idx_workspace_users_workspace_id ON workspace_users(workspace_id);

// -- Criação de índice para a coluna 'user_id' na tabela 'workspace_users'
// CREATE INDEX idx_workspace_users_user_id ON workspace_users(user_id);
17 changes: 17 additions & 0 deletions packages/api/src/modules/auth/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
IFindTokenParams,
ISignInResponse,
} from './types';
import { LessThanOrEqual } from 'typeorm';

export class AuthService implements IAuthService {
async signIn(payload: ICreateUserTokenPayload): Promise<ISignInResponse> {
Expand Down Expand Up @@ -100,4 +101,20 @@ export class AuthService implements IAuthService {
});
});
}

async clearExpiredTokens(): Promise<void> {
try {
await UserToken.delete({
expired_at: LessThanOrEqual(new Date()),
});
} catch (e) {
throw new Internal({
type: ErrorTypes.Internal,
title: 'Error on clear expired tokens',
detail: e,
});
}
}


}
2 changes: 2 additions & 0 deletions packages/api/src/server/storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { User } from "@src/models";
import UserToken from "@src/models/UserToken";
import { Workspace } from "@src/models/Workspace";
import { AuthService } from "@src/modules/auth/services";
import { TokenUtils } from "@src/utils";
import { isPast } from "date-fns";

Expand Down Expand Up @@ -72,6 +73,7 @@ export class SessionStorage {
this.data.delete(sessionId);
}
}
new AuthService().clearExpiredTokens();
this.nextClear = new Date().getTime() + CLEAR_TIME;
}

Expand Down

0 comments on commit b4748fc

Please sign in to comment.