DwightAI / .file
sujoydev99's picture
...
b7b7936
/**
* @swagger
* /company/{companyId}/departments:
* get:
* summary: Retrieve departments for a specific company
* description: Fetches a list of departments associated with the given company ID.
* tags: [Company]
* operationId: getCompanyDepartments
* parameters:
* - in: path
* name: companyId
* required: true
* schema:
* type: string
* description: The unique identifier of the company
* responses:
* 200:
* description: An array of department objects
* content:
* application/json:
* schema:
* type: array
* items:
* type: object
* properties:
* name:
* type: string
* description: Name of the department
* slug:
* type: string
* description: slug or identifier of the department
*/
app.get("/company/:companyId/departments", async (req, res, next) => {
try {
const { companyId } = req.params;
const client = await initClient(companyId);
let departments = await client.catalog.listDepartmentsData({
isActive: true, pageSize: 100, pageNo: 1
});
departments = departments?.items?.map(i => { return { name: i.name, slug: i.slug } })
res.json(departments);
} catch (e) { next(e) }
})
/**
* @swagger
* /company/{companyId}/departments/{departmentSlug}:
* get:
* summary: Retrieve categories for a specific department
* description: Retrieve categories for a specific department.
* tags: [Company]
* operationId: getDepartmentCategories
* parameters:
* - in: path
* name: companyId
* required: true
* schema:
* type: string
* description: The unique identifier of the company
* - in: path
* name: departmentSlug
* required: true
* schema:
* type: string
* description: The unique skug of the department to get categories
* responses:
* 200:
* description: An array of department objects
* content:
* application/json:
* schema:
* type: array
* items:
* type: object
* properties:
* name:
* type: string
* description: Name of the category
* slug:
* type: string
* description: slug or identifier of the catrgory
*/
app.get("/company/:companyId/departments/:departmentSlug", async (req, res, next) => {
try {
const { companyId, departmentSlug } = req.params;
const { item_type = 'single' } = req.query;
const client = await initClient(companyId);
let categories = await client.catalog.listProductTemplateCategories({
departments: departmentSlug, pageNo: 1, pageSize: 100, itemType: item_type
});
categories = categories?.items?.map(i => { return { name: i.name, slug: i.slug } })
res.json(categories);
} catch (e) { next(e) }
})