-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9634ce
commit 83c8924
Showing
10 changed files
with
61 additions
and
52 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,7 +261,7 @@ paths: | |
email: "[email protected]" | ||
createdAt: '2019-02-06T09:47:27.482Z' | ||
updatedAt: '2019-02-06T09:47:27.482Z' | ||
stemmedWords: [] | ||
extractedTags: [] | ||
500: | ||
description: Internal server error | ||
examples: | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,46 @@ | ||
const Tag = require("../tags/tag-model"); | ||
|
||
exports.findTag = tagName => { | ||
return Tag.findOne({ | ||
name: { | ||
$regex: tagName, | ||
$options: "i" | ||
} | ||
}); | ||
}; | ||
|
||
exports.findTags = query => { | ||
return Tag.find({ | ||
name: { | ||
$regex: query, | ||
$options: "i" | ||
} | ||
}); | ||
}; | ||
|
||
exports.resolveTagNames = async tags => { | ||
const resolvedTags = await Promise.all(tags.map(async tag => { | ||
try { | ||
const tagDoc = await Tag.findOne({name: tag}).exec(); | ||
const tagDoc = await exports.findTag(tag); | ||
return tagDoc ? tagDoc._id : false; | ||
} catch (_) { | ||
return false; | ||
} | ||
})); | ||
|
||
/* (Commented out the creation of the tag since it has | ||
to be submitted to approval.) | ||
return resolvedTags.filter(Boolean); | ||
}; | ||
|
||
const newTag = await new Tag({name: tag}).save(); | ||
return newTag._id; | ||
*/ | ||
exports.filterTags = async words => { | ||
const tags = await Promise.all(words.map(async word => { | ||
try { | ||
const tagDoc = await exports.findTag(word); | ||
|
||
return tagDoc && tagDoc._id ? word : false; | ||
} catch (_) { | ||
return false; | ||
} | ||
})); | ||
|
||
return resolvedTags.filter(Boolean); | ||
return tags.filter(Boolean); | ||
}; |
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