Make contractor residence optional with visibility rules
- Make residence_id nullable in contractor model - Add created_by_id field to track contractor creator - Update access control: personal contractors visible only to creator, residence contractors visible to all residence users - Add database migration for schema changes - Update admin panel DTOs and handlers for optional residence - Fix test utilities for new model structure 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -17,8 +17,8 @@ func (ContractorSpecialty) TableName() string {
|
||||
// Contractor represents the task_contractor table
|
||||
type Contractor struct {
|
||||
BaseModel
|
||||
ResidenceID uint `gorm:"column:residence_id;index;not null" json:"residence_id"`
|
||||
Residence Residence `gorm:"foreignKey:ResidenceID" json:"-"`
|
||||
ResidenceID *uint `gorm:"column:residence_id;index" json:"residence_id"`
|
||||
Residence *Residence `gorm:"foreignKey:ResidenceID" json:"-"`
|
||||
CreatedByID uint `gorm:"column:created_by_id;index;not null" json:"created_by_id"`
|
||||
CreatedBy User `gorm:"foreignKey:CreatedByID" json:"created_by,omitempty"`
|
||||
|
||||
|
||||
@@ -205,8 +205,9 @@ func TestTaskCompletion_JSONSerialization(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestContractor_JSONSerialization(t *testing.T) {
|
||||
residenceID := uint(1)
|
||||
contractor := Contractor{
|
||||
ResidenceID: 1,
|
||||
ResidenceID: &residenceID,
|
||||
CreatedByID: 1,
|
||||
Name: "Mike's Plumbing",
|
||||
Company: "Mike's Plumbing Co.",
|
||||
|
||||
Reference in New Issue
Block a user