1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/src/lib/services/user-feedback-service.ts
2024-02-06 15:44:25 +01:00

48 lines
1.4 KiB
TypeScript

import { Logger } from '../logger';
import { IUnleashStores } from '../types/stores';
import { IUnleashConfig } from '../types/option';
import { IUser } from '../types/user';
import {
IUserFeedback,
IUserFeedbackStore,
} from '../types/stores/user-feedback-store';
export default class UserFeedbackService {
private userFeedbackStore: IUserFeedbackStore;
private logger: Logger;
constructor(
{ userFeedbackStore }: Pick<IUnleashStores, 'userFeedbackStore'>,
{ getLogger }: Pick<IUnleashConfig, 'getLogger'>,
) {
this.userFeedbackStore = userFeedbackStore;
this.logger = getLogger('services/user-feedback-service.js');
}
async getAllUserFeedback(user: IUser): Promise<IUserFeedback[]> {
if (user.isAPI) {
return [];
}
try {
return await this.userFeedbackStore.getAllUserFeedback(user.id);
} catch (err) {
this.logger.error('Cannot read user feedback', err);
return [];
}
}
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;