Add mutation to add keywords (#24)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user