This commit is contained in:
Aditya Siregar
2025-07-30 23:18:20 +07:00
parent 4a921df55d
commit a759e0f57c
57 changed files with 3633 additions and 190 deletions
+29
View File
@@ -224,3 +224,32 @@ func (p *UserProcessorImpl) DeactivateUser(ctx context.Context, userID uuid.UUID
return nil
}
func (p *UserProcessorImpl) UpdateUserOutlet(ctx context.Context, userID uuid.UUID, req *models.UpdateUserOutletRequest) (*models.UserResponse, error) {
// Get user first to validate existence and get organization_id
existingUser, err := p.userRepo.GetByID(ctx, userID)
if err != nil {
return nil, fmt.Errorf("user not found: %w", err)
}
// Validate outlet exists
outlet, err := p.outletRepo.GetByID(ctx, req.OutletID)
if err != nil {
return nil, fmt.Errorf("outlet not found: %w", err)
}
// Validate outlet belongs to user's organization
if outlet.OrganizationID != existingUser.OrganizationID {
return nil, fmt.Errorf("outlet does not belong to user's organization")
}
// Update user's outlet_id
existingUser.OutletID = &req.OutletID
err = p.userRepo.Update(ctx, existingUser)
if err != nil {
return nil, fmt.Errorf("failed to update user outlet: %w", err)
}
return mappers.UserEntityToResponse(existingUser), nil
}