Spaces:
Runtime error
Runtime error
File size: 3,280 Bytes
146b1cb b7b7936 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
/**
* @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) }
})
|