create or update product assign to product outlet
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"apskel-pos-be/internal/constants"
|
||||
"apskel-pos-be/internal/contract"
|
||||
"apskel-pos-be/internal/models"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func CreateProductRequestToModel(apctx *appcontext.ContextInfo, req *contract.CreateProductRequest) *models.CreateProductRequest {
|
||||
@@ -37,8 +39,15 @@ func CreateProductRequestToModel(apctx *appcontext.ContextInfo, req *contract.Cr
|
||||
metadata = make(map[string]interface{})
|
||||
}
|
||||
|
||||
// Prioritize outlet_id from context, fallback to request body
|
||||
outletID := apctx.OutletID
|
||||
if outletID == uuid.Nil && req.OutletID != nil {
|
||||
outletID = *req.OutletID
|
||||
}
|
||||
|
||||
return &models.CreateProductRequest{
|
||||
OrganizationID: apctx.OrganizationID,
|
||||
OutletID: outletID,
|
||||
CategoryID: req.CategoryID,
|
||||
SKU: req.SKU,
|
||||
Name: req.Name,
|
||||
@@ -53,13 +62,20 @@ func CreateProductRequestToModel(apctx *appcontext.ContextInfo, req *contract.Cr
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateProductRequestToModel(req *contract.UpdateProductRequest) *models.UpdateProductRequest {
|
||||
func UpdateProductRequestToModel(apctx *appcontext.ContextInfo, req *contract.UpdateProductRequest) *models.UpdateProductRequest {
|
||||
metadata := req.Metadata
|
||||
if metadata == nil {
|
||||
metadata = make(map[string]interface{})
|
||||
}
|
||||
|
||||
// Prioritize outlet_id from context, fallback to request body
|
||||
outletID := apctx.OutletID
|
||||
if outletID == uuid.Nil && req.OutletID != nil {
|
||||
outletID = *req.OutletID
|
||||
}
|
||||
|
||||
return &models.UpdateProductRequest{
|
||||
OutletID: outletID,
|
||||
CategoryID: req.CategoryID,
|
||||
SKU: req.SKU,
|
||||
Name: req.Name,
|
||||
|
||||
Reference in New Issue
Block a user