Skip to content

Company Settings

1. Purpose

Define the Manager-facing Company settings contract for reading and updating Company profile data, and for regenerating the Company enrollment code.

Sources: Domain Model, Invariants & Naming, Company Onboarding, Client-Service Contract.

2. Scope

Slice 11 covers Manager-only, company-scoped Company settings:

  • Read current Company settings/profile.
  • Update allowed Company/profile fields.
  • Regenerate the active Company Code.

This slice does not cover Platform Admin company/tier/status management, billing, tier changes, Company suspension/activation, member management, or D2D settings (/company/d2d/settings).

3. Contract

All routes require auth:sanctum and the company middleware. company_id is never accepted from a client. Cross-tenant access returns 404; a suspended Company returns 403 {"message":"Company is suspended."}. Only Managers may access these routes (403 for other roles).

Method Path Auth / role Purpose
GET /api/company/settings auth:sanctum + company + Manager Return current Company settings.
PUT /api/company/settings Same Update allowed Company settings fields.
POST /api/company/settings/company-code/regenerate Same Deactivate current active Company Code and create a new unique active code.

3.1 GET /api/company/settings

200 response (JsonResource, unwrapped):

{
  "id": 1,
  "name_en": "Acme Logistics",
  "name_ar": "أكمي للخدمات اللوجستية",
  "status": "pending",
  "company_code": "AB12CD34",
  "locale": "en",
  "seats_used": 3,
  "seats_limit": 50,
  "tier": {
    "code": "starter",
    "name": "Starter",
    "max_users": 50
  },
  "manager": {
    "id": 1,
    "name": "Ahmad Ali",
    "phone": "+967700000000",
    "email": "ahmad@acme.example"
  }
}

Field rules:

Field Source Notes
id Company Company id.
name_en, name_ar Company Company profile names.
status Company pending\|active\|suspended; read-only in this slice.
company_code Active Company Code Current active code; read-only except regeneration endpoint.
locale Authenticated Manager User Manager preferred locale (en\|ar); updatable through settings.
seats_used Enrollment count Approved Passenger memberships in Company.
seats_limit Tier Tier max_users; null means unlimited.
tier Tier Read-only. name localized by Manager locale.
manager Authenticated Manager User Current Manager contact; email may be null.

3.2 PUT /api/company/settings

Request body (all fields optional; at least one allowed field required):

{
  "name_en": "Acme Logistics",
  "name_ar": "أكمي للخدمات اللوجستية",
  "locale": "ar",
  "manager_name": "Ahmad Ali",
  "manager_phone": "+967700000001",
  "manager_email": "ahmad@acme.example"
}

Allowed fields:

Field Type Rules
name_en string sometimes, required when present, string, max 255
name_ar string sometimes, required when present, string, max 255
locale string sometimes, required when present, en or ar
manager_name string sometimes, required when present, string, max 255
manager_phone string sometimes, required when present, string; must remain unique across Users
manager_email string|null sometimes, nullable, email, max 255; when present and non-null must remain unique across Users

Immutable / prohibited client control: id, status, tier, tier_id, tier_code, company_id, company_code, seats_used, seats_limit, manager.id. These fields are not accepted for mutation. Requests containing immutable fields return 422 with field-level errors.

200 response: same shape as GET.

3.3 POST /api/company/settings/company-code/regenerate

No request body. The endpoint:

  1. Finds the current active Company Code for the authenticated Manager's Company.
  2. Deactivates it (status=inactive).
  3. Generates a new unique uppercase 8-character active Company Code for the same Company.
  4. Returns the updated settings resource.

200 response: same shape as GET with the new company_code.

If no active Company Code exists (unexpected data state), the endpoint creates a new active Company Code and returns 200.

4. Invariants and security

  • Tenancy: Company is derived from authenticated membership/TenantContext; company_id is never client-supplied.
  • Manager-only: non-manager roles receive 403.
  • Suspended Company: blocked with 403 + {"message":"Company is suspended."}.
  • Cross-tenant: missing/foreign company resources return 404.
  • Immutable fields: status, tier, company_code cannot be changed through PUT. Company code changes only through the explicit regeneration endpoint.
  • Company Code uniqueness: regenerated codes must be unique across company_codes.code.
  • No auth changes: this slice does not change phone+OTP auth, token issuance, or role assignment.
  • No Passenger payment behavior: not applicable.

5. Errors

Case Status Envelope
Validation failure / immutable field / duplicate manager phone/email 422 message + field-level errors
Unauthenticated 401 message only
Non-manager or suspended company 403 message only
Missing company context / cross-tenant 404 message only

6. Tests

  • Unit: Company name/locale validation rules, Company Code regeneration produces unique active code and invalidates old code, immutable field rejection rules.
  • Feature: GET settings returns expected shape; PUT updates allowed fields; PUT rejects immutable fields; PUT rejects duplicate manager phone/email; manager-only 403; passenger/driver 403; suspended company 403; cross-tenant/unknown company context 404; regenerate returns new code and invalidates old code.
  • Contract: {message, errors?} on errors; JsonResource snake_case; no company_id accepted from client.

7. Implementation notes

  • DDD layering: FormRequest/DTO/Application Service/Domain/Infrastructure/JsonResource.
  • Extend the Company domain/application as needed; do not leak framework concerns into Domain.
  • Reuse TenantContext, CompanyScope, CompanyCodeRepository, CompanyRepository, TierRepository, membership/enrollment seat counting.
  • Update docs/02-architecture/05-client-service-contract.md and this spec in the same slice.