feat: sales activities, forecast products, catalog categories, member cache, procurement filters, and comprehensive tests

New features:
- ActivityController and manager for CW sales activities (CRUD)
- ForecastProductController for opportunity forecast/product lines
- CW member cache with dual-layer (in-memory + Redis) resolution
- Catalog category/subcategory/ecosystem taxonomy module
- Quote statuses type definitions with CW mapping
- User-defined fields (UDF) module with cache and event refresh
- Company sites CW module with serialization
- Procurement manager filters (category, ecosystem, manufacturer, price, stock)
- Opportunity notes CRUD and product line management via CW API
- Opportunity type definitions endpoint

Updates:
- OpportunityController: CW refresh, company hydration, activities, custom fields
- UserController: cwIdentifier field for CW member linking
- CatalogItemController: category/subcategory fields from CW
- PermissionNodes: sales note/product CRUD nodes, subCategories, collectPermissions
- API routes: procurement categories/filters, sales notes/products, opportunity types
- Global events: UDF and member refresh intervals on startup

Tests (414 passing):
- ActivityController, ForecastProductController, OpportunityController unit tests
- UserController cwIdentifier tests
- catalogCategories, companySites, memberCache, procurement module tests
- activityTypes, opportunityTypes, quoteStatuses type tests
- permissionNodes subCategories and getAllPermissionNodes tests
- Updated test setup with redis mock, API method mocks, and builder helpers
This commit is contained in:
2026-03-01 13:19:00 -06:00
parent 883b648d5e
commit d7b374f8ab
96 changed files with 7752 additions and 205 deletions
@@ -3,8 +3,11 @@ import { connectWiseApi } from "../../../constants";
import {
CWOpportunity,
CWOpportunitySummary,
CWForecast,
CWForecastItem,
CWOpportunityNote,
CWOpportunityNoteCreate,
CWOpportunityNoteUpdate,
CWOpportunityContact,
} from "./opportunity.types";
@@ -106,14 +109,35 @@ export const opportunityCw = {
},
/**
* Fetch Opportunity Forecasts
* Fetch Opportunity Products
*
* Fetches forecast/revenue items for a given opportunity.
* Fetches the full forecast object (products, revenue summaries, totals)
* for a given opportunity.
*/
fetchForecasts: async (opportunityId: number): Promise<CWForecastItem[]> => {
fetchProducts: async (opportunityId: number): Promise<CWForecast> => {
const response = await connectWiseApi.get(
`/sales/opportunities/${opportunityId}/forecast`,
);
console.log(
`[CW fetchProducts] Opportunity ${opportunityId} forecast raw data:`,
JSON.stringify(response.data, null, 2),
);
return response.data;
},
/**
* Update Forecast Item
*
* Updates a single forecast item (product) on an opportunity using PUT.
*/
updateProduct: async (
opportunityId: number,
forecastItemId: number,
data: Record<string, unknown>,
): Promise<CWForecastItem> => {
const url = `/sales/opportunities/${opportunityId}/forecast/${forecastItemId}`;
const response = await connectWiseApi.put(url, data);
return response.data;
},
@@ -129,6 +153,69 @@ export const opportunityCw = {
return response.data;
},
/**
* Fetch Single Note
*
* Fetches a single note by its ID on the given opportunity.
*/
fetchNote: async (
opportunityId: number,
noteId: number,
): Promise<CWOpportunityNote> => {
const response = await connectWiseApi.get(
`/sales/opportunities/${opportunityId}/notes/${noteId}`,
);
return response.data;
},
/**
* Create Note
*
* Creates a new note on the given opportunity.
*/
createNote: async (
opportunityId: number,
data: CWOpportunityNoteCreate,
): Promise<CWOpportunityNote> => {
const response = await connectWiseApi.post(
`/sales/opportunities/${opportunityId}/notes`,
data,
);
return response.data;
},
/**
* Update Note
*
* Updates an existing note on the given opportunity.
*/
updateNote: async (
opportunityId: number,
noteId: number,
data: CWOpportunityNoteUpdate,
): Promise<CWOpportunityNote> => {
const response = await connectWiseApi.patch(
`/sales/opportunities/${opportunityId}/notes/${noteId}`,
Object.entries(data).map(([key, value]) => ({
op: "replace",
path: key,
value,
})),
);
return response.data;
},
/**
* Delete Note
*
* Deletes a note from the given opportunity.
*/
deleteNote: async (opportunityId: number, noteId: number): Promise<void> => {
await connectWiseApi.delete(
`/sales/opportunities/${opportunityId}/notes/${noteId}`,
);
},
/**
* Fetch Opportunity Contacts
*
@@ -142,4 +229,20 @@ export const opportunityCw = {
);
return response.data;
},
/**
* Fetch Procurement Products
*
* Fetches procurement product records linked to an opportunity.
* These contain cancellation data (cancelledFlag, cancelledReason, etc.)
* that the forecast endpoint does not provide.
*/
fetchProcurementProducts: async (
opportunityId: number,
): Promise<Record<string, unknown>[]> => {
const response = await connectWiseApi.get(
`/procurement/products?conditions=${encodeURIComponent(`opportunity/id=${opportunityId}`)}&fields=id,forecastDetailId,cancelledFlag,quantityCancelled,cancelledReason,cancelledBy,cancelledDate`,
);
return response.data;
},
};