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:
@@ -1,8 +1,9 @@
|
||||
import { createRoute } from "../../modules/api-utils/createRoute";
|
||||
import { procurement } from "../../managers/procurement";
|
||||
import { procurement, CatalogFilterOpts } from "../../managers/procurement";
|
||||
import { apiResponse } from "../../modules/api-utils/apiResponse";
|
||||
import { ContentfulStatusCode } from "hono/utils/http-status";
|
||||
import { authMiddleware } from "../middleware/authorization";
|
||||
import { processObjectValuePerms } from "../../modules/permission-utils/processObjectPermissions";
|
||||
|
||||
/* /v1/procurement/items */
|
||||
export default createRoute(
|
||||
@@ -14,17 +15,53 @@ export default createRoute(
|
||||
const search = c.req.query("search") as string;
|
||||
const includeInactive = c.req.query("includeInactive") === "true";
|
||||
|
||||
const data = search
|
||||
? await procurement.search(search, page, rpp, { includeInactive })
|
||||
: await procurement.fetchPages(page, rpp, { includeInactive });
|
||||
// Category / filter params
|
||||
const category = c.req.query("category") as string | undefined;
|
||||
const subcategory = c.req.query("subcategory") as string | undefined;
|
||||
const group = c.req.query("group") as string | undefined;
|
||||
const manufacturer = c.req.query("manufacturer") as string | undefined;
|
||||
const ecosystem = c.req.query("ecosystem") as string | undefined;
|
||||
const inStock = c.req.query("inStock") === "true" ? true : undefined;
|
||||
const minPrice = c.req.query("minPrice")
|
||||
? Number(c.req.query("minPrice"))
|
||||
: undefined;
|
||||
const maxPrice = c.req.query("maxPrice")
|
||||
? Number(c.req.query("maxPrice"))
|
||||
: undefined;
|
||||
|
||||
const totalRecords = await procurement.count({
|
||||
activeOnly: !includeInactive,
|
||||
});
|
||||
const filterOpts: CatalogFilterOpts = {
|
||||
includeInactive,
|
||||
category,
|
||||
subcategory,
|
||||
group,
|
||||
manufacturer,
|
||||
ecosystem,
|
||||
inStock,
|
||||
minPrice,
|
||||
maxPrice,
|
||||
};
|
||||
|
||||
const data = search
|
||||
? await procurement.search(search, page, rpp, filterOpts)
|
||||
: await procurement.fetchPages(page, rpp, filterOpts);
|
||||
|
||||
const totalRecords = search
|
||||
? await procurement.countSearch(search, filterOpts)
|
||||
: await procurement.count(filterOpts);
|
||||
|
||||
const gatedData = await Promise.all(
|
||||
data.map((item) =>
|
||||
processObjectValuePerms(
|
||||
item.toJson(),
|
||||
"obj.catalogItem",
|
||||
c.get("user"),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const response = apiResponse.successful(
|
||||
"Catalog items fetched successfully!",
|
||||
data.map((item) => item.toJson()),
|
||||
gatedData,
|
||||
{
|
||||
pagination: {
|
||||
previousPage: page <= 1 ? null : page - 1,
|
||||
|
||||
Reference in New Issue
Block a user