d7b374f8ab
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
80 lines
2.2 KiB
TypeScript
80 lines
2.2 KiB
TypeScript
import { connectWiseApi } from "../../../constants";
|
|
|
|
export interface CWCompanySite {
|
|
id: number;
|
|
name: string;
|
|
addressLine1: string;
|
|
addressLine2?: string;
|
|
city: string;
|
|
stateReference: { id: number; identifier: string; name: string } | null;
|
|
zip: string;
|
|
country: { id: number; name: string } | null;
|
|
phoneNumber: string;
|
|
faxNumber: string;
|
|
taxCodeId: number | null;
|
|
expenseReimbursement: number;
|
|
primaryAddressFlag: boolean;
|
|
defaultShippingFlag: boolean;
|
|
defaultBillingFlag: boolean;
|
|
defaultMailingFlag: boolean;
|
|
mobileGuid: string;
|
|
calendar: { id: number; name: string } | null;
|
|
timeZone: { id: number; name: string } | null;
|
|
company: { id: number; identifier: string; name: string };
|
|
_info: Record<string, string>;
|
|
}
|
|
|
|
/**
|
|
* Fetch all sites for a ConnectWise company.
|
|
*
|
|
* @param cwCompanyId - The ConnectWise company ID
|
|
* @returns Array of CW company sites
|
|
*/
|
|
export const fetchCompanySites = async (
|
|
cwCompanyId: number,
|
|
): Promise<CWCompanySite[]> => {
|
|
const response = await connectWiseApi.get(
|
|
`/company/companies/${cwCompanyId}/sites?pageSize=1000`,
|
|
);
|
|
return response.data;
|
|
};
|
|
|
|
/**
|
|
* Fetch a single site by CW site ID for a given company.
|
|
*
|
|
* @param cwCompanyId - The ConnectWise company ID
|
|
* @param cwSiteId - The ConnectWise site ID
|
|
* @returns The CW company site
|
|
*/
|
|
export const fetchCompanySite = async (
|
|
cwCompanyId: number,
|
|
cwSiteId: number,
|
|
): Promise<CWCompanySite> => {
|
|
const response = await connectWiseApi.get(
|
|
`/company/companies/${cwCompanyId}/sites/${cwSiteId}`,
|
|
);
|
|
return response.data;
|
|
};
|
|
|
|
/**
|
|
* Serialize a CW site into a clean API-friendly object.
|
|
*/
|
|
export const serializeCwSite = (site: CWCompanySite) => ({
|
|
id: site.id,
|
|
name: site.name,
|
|
address: {
|
|
line1: site.addressLine1,
|
|
line2: site.addressLine2 ?? null,
|
|
city: site.city,
|
|
state: site.stateReference?.name ?? null,
|
|
zip: site.zip,
|
|
country: site.country?.name ?? "United States",
|
|
},
|
|
phoneNumber: site.phoneNumber || null,
|
|
faxNumber: site.faxNumber || null,
|
|
primaryAddressFlag: site.primaryAddressFlag,
|
|
defaultShippingFlag: site.defaultShippingFlag,
|
|
defaultBillingFlag: site.defaultBillingFlag,
|
|
defaultMailingFlag: site.defaultMailingFlag,
|
|
});
|