2021-06-07 11:11:42 +02:00
|
|
|
import { Logger } from '../logger';
|
|
|
|
import { IUnleashStores } from '../types/stores';
|
|
|
|
import { IUnleashConfig } from '../types/option';
|
2021-06-08 20:15:03 +02:00
|
|
|
import User from '../types/user';
|
2021-08-12 15:04:37 +02:00
|
|
|
import {
|
|
|
|
IUserFeedback,
|
|
|
|
IUserFeedbackStore,
|
|
|
|
} from '../types/stores/user-feedback-store';
|
2021-06-07 11:11:42 +02:00
|
|
|
|
|
|
|
export default class UserFeedbackService {
|
2021-08-12 15:04:37 +02:00
|
|
|
private userFeedbackStore: IUserFeedbackStore;
|
2021-06-07 11:11:42 +02:00
|
|
|
|
|
|
|
private logger: Logger;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
{ userFeedbackStore }: Pick<IUnleashStores, 'userFeedbackStore'>,
|
|
|
|
{ getLogger }: Pick<IUnleashConfig, 'getLogger'>,
|
|
|
|
) {
|
|
|
|
this.userFeedbackStore = userFeedbackStore;
|
|
|
|
this.logger = getLogger('services/user-feedback-service.js');
|
|
|
|
}
|
|
|
|
|
2021-06-08 20:15:03 +02:00
|
|
|
async getAllUserFeedback(user: User): Promise<IUserFeedback[]> {
|
|
|
|
if (user.isAPI) {
|
|
|
|
return [];
|
|
|
|
}
|
2021-06-08 20:21:14 +02:00
|
|
|
try {
|
|
|
|
return await this.userFeedbackStore.getAllUserFeedback(user.id);
|
|
|
|
} catch (err) {
|
|
|
|
this.logger.error(err);
|
|
|
|
return [];
|
|
|
|
}
|
2021-06-07 11:11:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async getFeedback(
|
|
|
|
user_id: number,
|
|
|
|
feedback_id: string,
|
|
|
|
): Promise<IUserFeedback> {
|
|
|
|
return this.userFeedbackStore.getFeedback(user_id, feedback_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateFeedback(feedback: IUserFeedback): Promise<IUserFeedback> {
|
|
|
|
return this.userFeedbackStore.updateFeedback(feedback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = UserFeedbackService;
|