Skip to content

Commit 052278b

Browse files
committed
refactor(core-typings,model-typings,models): implement ICredentialToken to extend IRocketChatRecord and update create method to return void
1 parent e8cbd7e commit 052278b

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

packages/core-typings/src/ICredentialToken.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export interface ICredentialToken {
2-
_id: string;
1+
import type { IRocketChatRecord } from './IRocketChatRecord';
32

3+
export interface ICredentialToken extends IRocketChatRecord {
44
userInfo: {
55
username?: string;
66
attributes?: any;

packages/model-typings/src/models/ICredentialTokensModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import type { ICredentialToken } from '@rocket.chat/core-typings';
33
import type { IBaseModel } from './IBaseModel';
44

55
export interface ICredentialTokensModel extends IBaseModel<ICredentialToken> {
6-
create(_id: string, userInfo: ICredentialToken['userInfo']): Promise<ICredentialToken>;
6+
create(_id: string, userInfo: ICredentialToken['userInfo']): Promise<void>;
77
findOneNotExpiredById(_id: string): Promise<ICredentialToken | null>;
88
}

packages/models/src/models/CredentialTokens.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ICredentialToken, RocketChatRecordDeleted } from '@rocket.chat/core-typings';
2-
import type { ICredentialTokensModel } from '@rocket.chat/model-typings';
2+
import type { ICredentialTokensModel, InsertionModel } from '@rocket.chat/model-typings';
33
import type { Collection, Db, IndexDescription } from 'mongodb';
44

55
import { BaseRaw } from './BaseRaw';
@@ -13,16 +13,15 @@ export class CredentialTokensRaw extends BaseRaw<ICredentialToken> implements IC
1313
return [{ key: { expireAt: 1 }, sparse: true, expireAfterSeconds: 0 }];
1414
}
1515

16-
async create(_id: string, userInfo: ICredentialToken['userInfo']): Promise<ICredentialToken> {
16+
async create(_id: string, userInfo: ICredentialToken['userInfo']): Promise<void> {
1717
const validForMilliseconds = 60000; // Valid for 60 seconds
18-
const token = {
18+
const token: InsertionModel<ICredentialToken> = {
1919
_id,
2020
userInfo,
2121
expireAt: new Date(Date.now() + validForMilliseconds),
2222
};
2323

2424
await this.insertOne(token);
25-
return token;
2625
}
2726

2827
findOneNotExpiredById(_id: string): Promise<ICredentialToken | null> {

0 commit comments

Comments
 (0)