Add mutation to add keywords (#24)

This commit is contained in:
Niklas Fondberg
2021-09-06 12:53:51 +02:00
committed by GitHub
parent 8d83205747
commit d5945da7ae
5 changed files with 48 additions and 4 deletions
+25
View File
@@ -68,6 +68,31 @@ ORDER BY keywords.value
return this.knex('product_keyword').insert(fieldsToInsert);
}
// Mutations
async addKeyword(name: string, type: KeywordType): Promise<number> {
const res = await this.knex('keywords')
.insert({ value: name })
.returning('id');
const keywordId = res[0];
if (type) {
const typeRes = await this.knex
.select('*')
.from('keywordtypes')
.where('name', type.toString().toLowerCase());
if (typeRes.length > 0) {
const typeId = typeRes[0].id;
await this.knex('keyword_type').insert({
keyword_id: keywordId,
type_id: typeId,
});
}
}
return keywordId;
}
}
/*