package services import "errors" // Where a staff assignment request is actually asking to put somebody. // // Its own function because the dangerous case is a quiet one. Unassigning is a // real instruction — people leave a shop before the next one opens, and the // alternative to holding them unassigned is deleting the account and losing who // did what — but it looks exactly like a `locationid` that failed to arrive. // A JSON body missing the field, a form that posted a blank, a client that // dropped it: all of them present as 0. // // So 0 alone never unassigns. `unassign` has to be sent, deliberately, and a // request that names no branch and does not ask to unassign is refused rather // than guessed at. func ResolveAssignment(locationID int, unassign bool) (int, error) { if unassign { // An explicit request wins even if a branch was also sent — the caller // said what they wanted, and honouring the leftover id instead would be // the same silent guess in reverse. return 0, nil } if locationID <= 0 { return 0, errors.New( "give a locationid, or send unassign:true to take them off a branch") } return locationID, nil }