Skip to content

Commit

Permalink
feat(security.gblib): Phone field and conversation refeerence.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo Rodriguez (pragmatismo.io) committed Jun 27, 2019
1 parent 223801d commit 46261d7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/security.gblib/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ export class GuaribasUser extends Model<GuaribasUser> {

@BelongsTo(() => GuaribasInstance)
public instance: GuaribasInstance;

@Column
phone: string

@Column(DataType.TEXT)
@Column
conversationReference: string
}

/**
Expand Down
23 changes: 23 additions & 0 deletions packages/security.gblib/services/SecService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import urlJoin = require('url-join');

import { GBService, IGBInstance } from 'botlib';
import { GuaribasGroup, GuaribasUser, GuaribasUserGroup } from '../models';
import { ConversationReference } from 'botbuilder';

/**
* Security service layer.
Expand Down Expand Up @@ -65,4 +66,26 @@ export class SecService extends GBService {
.error(reject);
});
}

/**
* Retrives a conversation reference from contact phone.
*/
public async getConversationReference(phone: string): Promise<ConversationReference> {
const options = { where: { phone: phone } };
const user = await GuaribasUser.findOne(options);

return JSON.parse(user.conversationReference);
}

/**
* Updates a conversation reference from contact phone.
*/
public async updateConversationReference(phone: string, conversationReference: string) {
const options = { where: { phone: phone } };
const user = await GuaribasUser.findOne(options);

user.conversationReference = conversationReference;
await user.save();
}

}

0 comments on commit 46261d7

Please sign in to comment.