Skip to content

Commit 1e71080

Browse files
committed
refactor: add query parameter to get word without assets
1 parent 5e135c1 commit 1e71080

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

doc/api.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ paths:
189189
required: true
190190
schema:
191191
type: string
192+
- name: noAssets
193+
in: query
194+
required: false
195+
description: if true then get word with pathes to assets instead from assets itself
196+
schema:
197+
type: string
192198
get:
193199
tags:
194200
- Words

src/resources/words/word.router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ router.route('/count').get(async (req, res) => {
6464
});
6565

6666
router.route('/:id').get(async (req, res) => {
67-
const word = await wordService.get(req.params.id);
67+
const word = await wordService.get(req.params.id, req.query.noAssets);
6868
res.status(OK).send(word.toResponse());
6969
});
7070

src/resources/words/word.service.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,38 @@ const getAll = async conditions => wordRepo.getAll(conditions);
88
const getQuantity = async (group, wordsPerExampleSentenceLTE) =>
99
wordRepo.getQuantity(group, wordsPerExampleSentenceLTE);
1010

11-
const get = async wordId => {
11+
const get = async (wordId, noAssets) => {
1212
const word = await wordRepo.get(wordId);
1313

14-
word.image = await fs.readFile(
15-
path.join(__dirname, `../../../${word.image}`),
16-
{
17-
encoding: 'base64'
18-
}
19-
);
20-
21-
word.audio = await fs.readFile(
22-
path.join(__dirname, `../../../${word.audio}`),
23-
{
24-
encoding: 'base64'
25-
}
26-
);
27-
28-
word.audioMeaning = await fs.readFile(
29-
path.join(__dirname, `../../../${word.audioMeaning}`),
30-
{
31-
encoding: 'base64'
32-
}
33-
);
34-
35-
word.audioExample = await fs.readFile(
36-
path.join(__dirname, `../../../${word.audioExample}`),
37-
{
38-
encoding: 'base64'
39-
}
40-
);
14+
if (!noAssets) {
15+
word.image = await fs.readFile(
16+
path.join(__dirname, `../../../${word.image}`),
17+
{
18+
encoding: 'base64'
19+
}
20+
);
21+
22+
word.audio = await fs.readFile(
23+
path.join(__dirname, `../../../${word.audio}`),
24+
{
25+
encoding: 'base64'
26+
}
27+
);
28+
29+
word.audioMeaning = await fs.readFile(
30+
path.join(__dirname, `../../../${word.audioMeaning}`),
31+
{
32+
encoding: 'base64'
33+
}
34+
);
35+
36+
word.audioExample = await fs.readFile(
37+
path.join(__dirname, `../../../${word.audioExample}`),
38+
{
39+
encoding: 'base64'
40+
}
41+
);
42+
}
4143

4244
return word;
4345
};

0 commit comments

Comments
 (0)