-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from samagra-comms/main
Feedback+User Module
- Loading branch information
Showing
12 changed files
with
200 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import axios from 'axios'; | ||
|
||
@Injectable() | ||
export class FeedbackService { | ||
private readonly logger = new Logger(FeedbackService.name); | ||
|
||
constructor(private readonly configService: ConfigService) {} | ||
|
||
async givePositiveFeedback(messageId) { | ||
const orchestratorUrl = this.configService.get<string>('ORCHESTRATOR_API_ENDPOINT'); | ||
const feedbackUrl = `${orchestratorUrl}/feedback/query/like/${messageId}`; | ||
|
||
await axios.get(feedbackUrl); | ||
} | ||
|
||
async giveNegativeFeedback(messageId) { | ||
const orchestratorUrl = this.configService.get<string>('ORCHESTRATOR_API_ENDPOINT'); | ||
const feedbackUrl = `${orchestratorUrl}/feedback/query/dislike/${messageId}`; | ||
|
||
await axios.get(feedbackUrl) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { createClient, SupabaseClient } from '@supabase/supabase-js'; | ||
import { XMessage, MessageState } from '@samagra-x/xmessage'; | ||
import { XMessageDbDto } from '../dto/xmessage.dto'; | ||
import { ConfigService } from '@nestjs/config'; | ||
|
||
@Injectable() | ||
export class SupabaseService { | ||
private supabase: SupabaseClient; | ||
|
||
constructor(private readonly configService: ConfigService) { | ||
this.supabase = createClient( | ||
this.configService.get<string>('SUPABASE_URL'), | ||
this.configService.get<string>('SUPABASE_KEY') | ||
); | ||
} | ||
|
||
createXMessageDTO(msg: XMessage) { | ||
const msgData: XMessageDbDto = { | ||
userid: msg.to.userID as string, | ||
fromid: msg.from.userID, | ||
channel: msg.channelURI, | ||
provider: msg.providerURI, | ||
timestamp: msg.timestamp, | ||
messagestate: msg.messageState, | ||
app: msg.app, | ||
xmessage: msg, | ||
//auxdata: | ||
messageid: msg.messageId.channelMessageId, | ||
replyid: msg.messageId.replyId, | ||
status: msg.messageState | ||
}; | ||
return msgData; | ||
} | ||
|
||
// async readMessagesByBotId(botUuid: string): Promise<any[]> { | ||
// const { data, error } = await this.supabase.from('xmessage').select('*').eq('botUuid', botUuid); | ||
|
||
// if (error) throw error; | ||
// return data; | ||
// } | ||
|
||
// async readMessagesByUserId(userId: string): Promise<any[]> { | ||
// const { data, error } = await this.supabase.from('xmessage').select('*').eq('userId', userId); | ||
|
||
// if (error) throw error; | ||
// return data; | ||
// } | ||
|
||
// async readAggregateData(startDate: string, endDate: string): Promise<any[]> { | ||
// const { data, error } = await this.supabase | ||
// .from('xmessage') | ||
// .select('*') | ||
// .gte('timestamp', startDate) | ||
// .lte('timestamp', endDate); | ||
|
||
// if (error) throw error; | ||
// return data; | ||
// } | ||
|
||
async writeMessage(message: XMessage): Promise<any> { | ||
const msgData = this.createXMessageDTO(message); | ||
const { data, error } = await this.supabase.from('xmessage').insert([message]); | ||
if (error) throw error; | ||
return data; | ||
} | ||
|
||
async writeMultipleMessages(messages: XMessage[]): Promise<any[]> { | ||
const msgData = new Array<XMessageDbDto>(); | ||
messages.forEach((msg) => { | ||
msgData.push(this.createXMessageDTO(msg)); | ||
}); | ||
|
||
const { data, error } = await this.supabase.from('xmessage').insert(msgData); | ||
|
||
if (error) throw error; | ||
return data; | ||
} | ||
|
||
async updateMessageStatus(messageId: string, newStatus: MessageState): Promise<any> { | ||
const { data, error } = await this.supabase | ||
.from('xmessage') | ||
.update({ status: newStatus }) | ||
.eq('messageid', messageId); | ||
|
||
if (error) throw error; | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { UserService } from './user.service'; | ||
import { HttpModule } from '@nestjs/axios'; | ||
|
||
@Module({ | ||
providers: [UserService], | ||
imports: [HttpModule], | ||
exports: [UserService] | ||
}) | ||
export class UserModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { UserService } from './user.service'; | ||
|
||
describe('UserService', () => { | ||
let service: UserService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [UserService], | ||
}).compile(); | ||
|
||
service = module.get<UserService>(UserService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { HttpService } from '@nestjs/axios'; | ||
import { AxiosResponse } from 'axios'; | ||
import { Observable } from 'rxjs'; | ||
import { ConfigService } from '@nestjs/config'; | ||
|
||
@Injectable() | ||
export class UserService { | ||
private configService: ConfigService; | ||
|
||
constructor(private readonly httpService: HttpService) {} | ||
|
||
private getHeaders() { | ||
return { | ||
headers: { | ||
'Authorization': this.configService.get<string>('FA_AUTH_KEY'), | ||
'Content-Type': 'application/json', | ||
'X-FusionAuth-Application-Id': this.configService.get<string>('FA_APP_ID') | ||
} | ||
}; | ||
} | ||
|
||
private getBaseUrl() { | ||
return this.configService.get<string>('FA_URL'); | ||
} | ||
|
||
getUserById(userId: string): Observable<AxiosResponse<any>> { | ||
const url = `${this.getBaseUrl()}/api/user/${userId}`; | ||
return this.httpService.get(url, this.getHeaders()); | ||
} | ||
|
||
getUserByUsername(username: string): Observable<AxiosResponse<any>> { | ||
const url = `${this.getBaseUrl}api/user/search?queryString=username%3A${username}&exactMatch=true` | ||
return this.httpService.get(url, this.getHeaders()); | ||
} | ||
|
||
createUser(userPayload: any): Observable<AxiosResponse<any>> { | ||
const url = `${this.getBaseUrl()}/api/user`; | ||
return this.httpService.post(url, userPayload, this.getHeaders()); | ||
} | ||
} |