|
|
@@ -14,7 +14,6 @@ export interface TagDocument extends Document {
|
|
|
|
|
|
export interface TagModel extends Model<TagDocument>{
|
|
|
getIdToNameMap(tagIds: Types.ObjectId[])
|
|
|
- findOrCreate(tagName: string)
|
|
|
findOrCreateMany(tagNames: string[])
|
|
|
}
|
|
|
|
|
|
@@ -40,14 +39,6 @@ tagSchema.statics.getIdToNameMap = async function(tagIds: Types.ObjectId[]) {
|
|
|
return idToNameMap;
|
|
|
};
|
|
|
|
|
|
-tagSchema.statics.findOrCreate = async function(tagName: string) {
|
|
|
- const tag = await this.findOne({ name: tagName });
|
|
|
- if (!tag) {
|
|
|
- return this.create({ name: tagName });
|
|
|
- }
|
|
|
- return tag;
|
|
|
-};
|
|
|
-
|
|
|
tagSchema.statics.findOrCreateMany = async function(tagNames: string[]) {
|
|
|
const existTags = await this.find({ name: { $in: tagNames } });
|
|
|
const existTagNames = existTags.map((tag) => { return tag.name });
|