fix(BE): remove supplier price in master nonstock

This commit is contained in:
Hafizh A. Y
2026-01-15 15:49:15 +07:00
parent 2a884a8d09
commit fe002c9602
8 changed files with 38 additions and 54 deletions
@@ -61,30 +61,20 @@ func (r *NonstockRepositoryImpl) SyncSuppliersDiff(ctx context.Context, tx *gorm
return err
}
existingMap := make(map[uint]entity.NonstockSupplier, len(existing))
existingMap := make(map[uint]struct{}, len(existing))
for _, rel := range existing {
existingMap[rel.SupplierId] = rel
existingMap[rel.SupplierId] = struct{}{}
}
incomingMap := make(map[uint]struct{}, len(suppliers))
for _, rel := range suppliers {
incomingMap[rel.SupplierId] = struct{}{}
if existingRel, exists := existingMap[rel.SupplierId]; exists {
if existingRel.Price != rel.Price {
if err := db.WithContext(ctx).
Model(&entity.NonstockSupplier{}).
Where("nonstock_id = ? AND supplier_id = ?", nonstockID, rel.SupplierId).
Update("price", rel.Price).
Error; err != nil {
return err
}
}
if _, exists := existingMap[rel.SupplierId]; exists {
continue
}
record := entity.NonstockSupplier{
NonstockId: nonstockID,
SupplierId: rel.SupplierId,
Price: rel.Price,
}
if err := db.WithContext(ctx).Create(&record).Error; err != nil {
return err