UNPKG

@novo-learning/novo-sdk

Version:

SDK for the Novolanguage Speech Analysis API

71 lines 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataApi = void 0; const exercise_result_mapper_1 = require("../../mappers/exercise-result.mapper"); const generated_1 = require("./generated"); class DataApi { constructor(configuration, basePath, axios) { this.attemptsApi = new generated_1.AttemptsApi(configuration, basePath, axios); this.filesApi = new generated_1.FilesApi(configuration, basePath, axios); this.exerciseResultMapper = new exercise_result_mapper_1.ExerciseResultMapper(); } mapGeneratedExerciseResponse(dto) { return { ...dto, data: { ...dto.data, exerciseResult: this.exerciseResultMapper.mapFromGenerated(dto.data.exerciseResult), }, }; } mapGeneratedExerciseResponses(dto) { return { ...dto, data: dto.data.map((response) => ({ ...response, exerciseResult: this.exerciseResultMapper.mapFromGenerated(response.exerciseResult), })), }; } async createAttempt(attempt, audio, options) { const response = await this.attemptsApi.createAttempt(attempt, audio, options); return this.mapGeneratedExerciseResponse(response); } async getAttempt(id, options) { const response = await this.attemptsApi.getAttempt(id, options); return this.mapGeneratedExerciseResponse(response); } getAttempts(options) { return (this.attemptsApi .getAttempts(undefined, undefined, undefined, false, options) .then((response) => this.mapGeneratedExerciseResponses(response))); } removeAttempt(id, options) { return this.attemptsApi.removeAttempt(id, options); } async updateAttempt(id, replaceAttemptDtoV1, options) { const response = await this.attemptsApi.updateAttempt(id, { ...replaceAttemptDtoV1, exerciseResult: { ...replaceAttemptDtoV1.exerciseResult, respondedAt: replaceAttemptDtoV1.exerciseResult.respondedAt.toISOString(), }, }, options); return this.mapGeneratedExerciseResponse(response); } async getAudio(audioKey, options) { const response = await this.filesApi.downloadFile(audioKey, { ...options, responseType: 'arraybuffer' }); return response.data; } async downloadAttempts(publisherId, offset, limit, filter, options) { const response = await this.attemptsApi.downloadAttempts({ publisherId, offset, limit, ...filter, }, options); return this.mapGeneratedExerciseResponses(response); } } exports.DataApi = DataApi; //# sourceMappingURL=data-api.js.map