forked from rmanguinho/clean-ts-api
-
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.
refactor: optimize DbLoadAnswersBySurvey
- Loading branch information
1 parent
f50ee20
commit c8f9d2f
Showing
7 changed files
with
80 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './add-survey-repository' | ||
export * from './load-survey-by-id-repository' | ||
export * from './load-answers-by-survey-repository' | ||
export * from './check-survey-by-id-repository' | ||
export * from './load-surveys-repository' |
7 changes: 7 additions & 0 deletions
7
src/data/protocols/db/survey/load-answers-by-survey-repository.ts
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,7 @@ | ||
export interface LoadAnswersBySurveyRepository { | ||
loadAnswers: (id: string) => Promise<LoadAnswersBySurveyRepository.Result> | ||
} | ||
|
||
export namespace LoadAnswersBySurveyRepository { | ||
export type Result = string[] | ||
} |
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 |
---|---|---|
@@ -1,11 +1,10 @@ | ||
import { LoadAnswersBySurvey } from '@/domain/usecases' | ||
import { LoadSurveyByIdRepository } from '@/data/protocols' | ||
import { LoadAnswersBySurveyRepository } from '@/data/protocols' | ||
|
||
export class DbLoadAnswersBySurvey implements LoadAnswersBySurvey { | ||
constructor (private readonly loadSurveyByIdRepository: LoadSurveyByIdRepository) {} | ||
constructor (private readonly loadAnswersBySurveyRepository: LoadAnswersBySurveyRepository) {} | ||
|
||
async loadAnswers (id: string): Promise<LoadAnswersBySurvey.Result> { | ||
const survey = await this.loadSurveyByIdRepository.loadById(id) | ||
return survey?.answers.map(a => a.answer) || [] | ||
return this.loadAnswersBySurveyRepository.loadAnswers(id) | ||
} | ||
} |
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