feat: add printer types
This commit is contained in:
@@ -59,8 +59,8 @@ func (v *ProductValidatorImpl) ValidateCreateProductRequest(req *contract.Create
|
||||
return errors.New("image_url cannot exceed 500 characters"), constants.MalformedFieldErrorCode
|
||||
}
|
||||
|
||||
if req.PrinterType != nil && len(*req.PrinterType) > 50 {
|
||||
return errors.New("printer_type cannot exceed 50 characters"), constants.MalformedFieldErrorCode
|
||||
if err, code := validatePrinterTypes(req.PrinterTypes); err != nil {
|
||||
return err, code
|
||||
}
|
||||
|
||||
if err, code := validateSellBy(req.SellBy, req.UnitID); err != nil {
|
||||
@@ -70,6 +70,18 @@ func (v *ProductValidatorImpl) ValidateCreateProductRequest(req *contract.Create
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
// validatePrinterTypes holds each printer to the 50 characters the single printer_type
|
||||
// column allowed.
|
||||
func validatePrinterTypes(printerTypes []string) (error, string) {
|
||||
for _, printerType := range printerTypes {
|
||||
if len(strings.TrimSpace(printerType)) > 50 {
|
||||
return errors.New("each printer_types entry cannot exceed 50 characters"), constants.MalformedFieldErrorCode
|
||||
}
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
// validateSellBy checks how a product is sold and that it carries what that choice
|
||||
// needs. A weight-based product without a unit would produce order lines with no unit
|
||||
// to print, so the receipt could show "4,2" with no idea of what.
|
||||
@@ -100,7 +112,7 @@ func (v *ProductValidatorImpl) ValidateUpdateProductRequest(req *contract.Update
|
||||
// At least one field should be provided for update
|
||||
if req.CategoryID == nil && req.SKU == nil && req.Name == nil && req.Description == nil &&
|
||||
req.Price == nil && req.Cost == nil && req.BusinessType == nil && req.ImageURL == nil &&
|
||||
req.PrinterType == nil && req.PrintToChecker == nil && req.UnitID == nil &&
|
||||
req.PrinterTypes == nil && req.PrintToChecker == nil && req.UnitID == nil &&
|
||||
req.SellBy == nil && req.Metadata == nil && req.IsActive == nil {
|
||||
return errors.New("at least one field must be provided for update"), constants.MissingFieldErrorCode
|
||||
}
|
||||
@@ -134,8 +146,8 @@ func (v *ProductValidatorImpl) ValidateUpdateProductRequest(req *contract.Update
|
||||
return errors.New("image_url cannot exceed 500 characters"), constants.MalformedFieldErrorCode
|
||||
}
|
||||
|
||||
if req.PrinterType != nil && len(*req.PrinterType) > 50 {
|
||||
return errors.New("printer_type cannot exceed 50 characters"), constants.MalformedFieldErrorCode
|
||||
if err, code := validatePrinterTypes(req.PrinterTypes); err != nil {
|
||||
return err, code
|
||||
}
|
||||
|
||||
// Only the value is checked here. Whether the product ends up with a unit depends on
|
||||
|
||||
Reference in New Issue
Block a user