forked from longtao.wu/droboticflow
28 lines
768 B
Go
28 lines
768 B
Go
package store
|
|
|
|
import "go.mongodb.org/mongo-driver/bson"
|
|
|
|
// Existing identity ownership is immutable. Even stale full-record saves never
|
|
// write supplierId; approved historical backfills are a separate offline action.
|
|
func bsonDocumentWithoutSupplier(value any) (bson.M, error) {
|
|
data, err := bson.Marshal(value)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var fields bson.M
|
|
if err = bson.Unmarshal(data, &fields); err != nil {
|
|
return nil, err
|
|
}
|
|
delete(fields, "supplierId")
|
|
return fields, nil
|
|
}
|
|
|
|
func immutableSupplierFilter(id, supplierID string) bson.M {
|
|
filter := bson.M{"id": id, "supplierId": supplierID}
|
|
if supplierID == "" {
|
|
delete(filter, "supplierId")
|
|
filter["$or"] = bson.A{bson.M{"supplierId": ""}, bson.M{"supplierId": nil}}
|
|
}
|
|
return filter
|
|
}
|