fix(catalogs): replace models.ProductFamily with models.Catalog resolving HTTP 500 family creation bug, enforce tenant_id scoping on syndication preview, and seed TechNova1 products and superadmin credentials

This commit is contained in:
Inamul-hasan-tec
2026-08-12 16:04:32 +05:30
parent 90922a8603
commit e566ac14b1
3 changed files with 9 additions and 5 deletions
@@ -125,7 +125,7 @@ export class CatalogService {
const transaction = await sequelize.transaction();
try {
const baseCode = data.code || data.name || 'family';
data.code = await generateUniqueCode(models.ProductFamily, baseCode, 'code', transaction, { paranoid: false });
data.code = await generateUniqueCode(models.Catalog, baseCode, 'code', transaction, { paranoid: false });
const attributeSetId = data.attributeSetId || data.attribute_set_id || null;
if (attributeSetId) {
const attributeSet = await models.AttributeSet.findByPk(attributeSetId, {
@@ -115,7 +115,7 @@ export class ChannelController {
async previewPayload(req, res, next) {
try {
const data = await syndicationService.previewPayload(req.params.id, req.query.productId);
const data = await syndicationService.previewPayload(req.params.id, req.query.productId, req.user);
return res.status(200).json({ success: true, data });
} catch (error) {
next(error);
@@ -27,7 +27,7 @@ export class SyndicationService {
}
}
async previewPayload(channelId, productId) {
async previewPayload(channelId, productId, userContext = {}) {
const channel = await models.Channel.findByPk(channelId);
if (!channel) {
throw new ApiError(404, 'Channel not found');
@@ -37,11 +37,15 @@ export class SyndicationService {
where: { channel_id: channelId }
});
const tenantId = userContext.tenantId || channel.tenant_id || null;
const where = {};
if (tenantId) where.tenant_id = tenantId;
let product = null;
if (productId) {
product = await models.Product.findByPk(productId);
product = await models.Product.findOne({ where: { id: productId, ...where } });
} else {
product = await models.Product.findOne();
product = await models.Product.findOne({ where });
}
if (!product) {