add ranking of variants to product creation implementation

This commit is contained in:
pKorsholm committed 2021-09-03 17:18:20 +02:00
1 parent 32880dbed3
commit 3ae6bdb7fc
1 file changed
+12
@@ -327,7 +327,13 @@ export default async (req, res) => {
.withTransaction(manager) .withTransaction(manager)
.create({ ...value, profile_id: shippingProfile.id }) .create({ ...value, profile_id: shippingProfile.id })
// console.log(variants)
// console.log(value)
// console.log(newProduct)
if (variants) { if (variants) {
for (const [i, variant] of variants.entries()) variant.rank = i
const optionIds = value.options.map( const optionIds = value.options.map(
o => newProduct.options.find(newO => newO.title === o.title).id o => newProduct.options.find(newO => newO.title === o.title).id
) )
@@ -341,6 +347,7 @@ export default async (req, res) => {
option_id: optionIds[index], option_id: optionIds[index],
})), })),
} }
await productVariantService await productVariantService
.withTransaction(manager) .withTransaction(manager)
.create(newProduct.id, variant) .create(newProduct.id, variant)
@@ -349,13 +356,18 @@ export default async (req, res) => {
} }
}) })
// console.log("got to after variants")
const product = await productService.retrieve(newProduct.id, { const product = await productService.retrieve(newProduct.id, {
select: defaultFields, select: defaultFields,
relations: defaultRelations, relations: defaultRelations,
}) })
// console.log(product)
res.json({ product }) res.json({ product })
} catch (err) { } catch (err) {
// console.log(err)
throw err throw err
} }
} }