Objective
- Provide a backend API that creates a
pendingquote in a target company from a source inspection, carrying property and contact data without cross-company ID leakage. - Enforce dual-membership and a dedicated permission so only authorized users can hand off jobs across instances.
Background
- Parent epic: cross-instance quote from existing job (workorder entry point).
- Quotes are created per company via
createQuoteWithChargesinattik-backend/src/util/functions/quote/createQuoteWithCharges.tswith_companyIdonquoteSchema. - No existing route creates a quote in company B from an inspection in company A.
- Cross-instance action flow copy (
copyActionFlowToCompanyinattik-backend/src/util/functions/actionFlows/copyActionFlowToCompany.ts, endpoints inattik-backend/src/routes/flow.ts) is the closest pattern fortargetCompanyId+ allowed-company checks.
Scope
Backend
- New endpoint (e.g. under
instance-managementorinspection/:id/...) accepting source inspection id + targetCompanyId; validate user membership in both companies and new permission. - Load populated source inspection (property,
people, charges as reference); build quote payload for target_companyId. - Create quote with
status: 'pending'viacreateQuoteWithCharges(or equivalent transaction used byattik-backend/src/routes/quote.ts). - Contacts: match-or-create in target company (patterns similar to
findSpectoraContactMatchesinattik-backend/src/util/functions/spectora/findSpectoraContactMatches.ts); mappeople[]with destination_contactId/_roleIdonly. - Property: copy address/property fields onto destination quote
property. - Provenance: decision needed — optional fields on quote for
_sourceInspectionId,_sourceCompanyId, created-by metadata for audit. - Exclude from copy:
wcLeadId,_hubspotDealId,_finalInspectionId, source charge/service Mongo IDs, source inspector IDs. - Services/charges: initial create may omit charges or include empty charge list until service-mapping child lands; decision needed on minimum viable payload.
- Return created quote id/slug and target company id for frontend navigation.
Frontend
- None in this child (workorder UI is a separate child); expose types/server action contract as needed for the UI child.
Out of scope
- Workorder modal UX.
- Contact role mapping UI (separate child).
- Service mapping, report attachments.
- Creating unconfirmed inspections in destination.
References
attik-backend/src/util/functions/quote/createQuoteWithCharges.tsattik-backend/src/routes/quote.tsattik-backend/src/models/quoteSchema.tsattik-backend/src/routes/protectedRouteBarrel.ts(/instance-management)attik-backend/src/routes/flow.ts(cross-company copy guards)