This commit is contained in:
@@ -52,20 +52,40 @@ func (dv *DuplicateValidator) ValidateDuplicate(ctx context.Context, config Vali
|
||||
|
||||
// ValidateDuplicateWithCustomFields checks for duplicates with additional custom fields
|
||||
func (dv *DuplicateValidator) ValidateDuplicateWithCustomFields(ctx context.Context, config ValidationConfig, fields map[string]interface{}) error {
|
||||
whereClause := fmt.Sprintf("%s = ANY($1) AND DATE(%s) = CURRENT_DATE", config.StatusColumn, config.DateColumn)
|
||||
args := []interface{}{config.ActiveStatuses}
|
||||
argIndex := 2
|
||||
whereClause := ""
|
||||
args := []interface{}{}
|
||||
argIndex := 1
|
||||
|
||||
// Add additional field conditions
|
||||
// for fieldName, fieldValue := range config.AdditionalFields {
|
||||
// whereClause += fmt.Sprintf(" AND %s = $%d", fieldName, argIndex)
|
||||
// args = append(args, fieldValue)
|
||||
// argIndex++
|
||||
// }
|
||||
|
||||
// Add additional field conditions from config
|
||||
for fieldName, fieldValue := range config.AdditionalFields {
|
||||
whereClause += fmt.Sprintf(" AND %s = $%d", fieldName, argIndex)
|
||||
if whereClause != "" {
|
||||
whereClause += " AND "
|
||||
}
|
||||
whereClause += fmt.Sprintf("%s = $%d", fieldName, argIndex)
|
||||
args = append(args, fieldValue)
|
||||
argIndex++
|
||||
}
|
||||
|
||||
// Add dynamic fields
|
||||
// for fieldName, fieldValue := range fields {
|
||||
// whereClause += fmt.Sprintf(" AND %s = $%d", fieldName, argIndex)
|
||||
// args = append(args, fieldValue)
|
||||
// argIndex++
|
||||
// }
|
||||
|
||||
// Add dynamic fields from input
|
||||
for fieldName, fieldValue := range fields {
|
||||
whereClause += fmt.Sprintf(" AND %s = $%d", fieldName, argIndex)
|
||||
if whereClause != "" {
|
||||
whereClause += " AND "
|
||||
}
|
||||
whereClause += fmt.Sprintf("%s = $%d", fieldName, argIndex)
|
||||
args = append(args, fieldValue)
|
||||
argIndex++
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user