From 3670cf4a21362e61032f6c862f8b71b92b747b9e Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (pragmatismo.io)" Date: Thu, 27 Jun 2019 09:22:32 -0300 Subject: [PATCH] feat(security.gblib): Phone field and conversation refeerence. --- packages/security.gblib/models/index.ts | 7 ++++++ .../security.gblib/services/SecService.ts | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/packages/security.gblib/models/index.ts b/packages/security.gblib/models/index.ts index 2cb49ce8..c03f6bae 100644 --- a/packages/security.gblib/models/index.ts +++ b/packages/security.gblib/models/index.ts @@ -77,6 +77,13 @@ export class GuaribasUser extends Model { @BelongsTo(() => GuaribasInstance) public instance: GuaribasInstance; + + @Column + phone: string + + @Column(DataType.TEXT) + @Column + conversationReference: string } /** diff --git a/packages/security.gblib/services/SecService.ts b/packages/security.gblib/services/SecService.ts index 358da06b..6ec46e25 100644 --- a/packages/security.gblib/services/SecService.ts +++ b/packages/security.gblib/services/SecService.ts @@ -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. @@ -65,4 +66,26 @@ export class SecService extends GBService { .error(reject); }); } + + /** + * Retrives a conversation reference from contact phone. + */ + public async getConversationReference(phone: string): Promise { + 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(); + } + }