Bansari Akhani commited on
Commit
647348b
·
1 Parent(s): 1c91800

api to fetch all workorders

Browse files
src/controllers/propertyware/workorders.controller.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Request, Response } from 'express';
2
+
3
+ import { fetchAllWorkorders } from '../../shared/services/propertyware.service';
4
+ import { logger } from '../../utils/logger';
5
+
6
+ export const fetchWorkorders = async (req: Request, res: Response) => {
7
+ try {
8
+
9
+ const workorders = await fetchAllWorkorders();
10
+ console.log(workorders);
11
+
12
+ const workordersResponseData = workorders.map((workorder: { id: any; number: any; }) => ({
13
+ id: workorder.id,
14
+ number: workorder.number,
15
+ }));
16
+
17
+ res.status(200).json(workordersResponseData);
18
+ } catch (error) {
19
+ console.log(error);
20
+ logger.error('Error fetching Workorders:', error);
21
+ res.status(500).json({ error: 'Error fetching Workorders' });
22
+ }
23
+ };
src/routes/propertyware.routes.ts CHANGED
@@ -7,10 +7,10 @@ import { LocationLookup, syncUnitsData } from "../controllers/propertyware/units
7
  import { fetchVendorsData } from "../controllers/propertyware/vendors.controller";
8
  import { syncInvoices } from "../controllers/propertyware/bills.controller";
9
  import { jwtMiddleware } from '../middlewares/authMiddleware';
 
10
 
11
  const pwRouter = express.Router();
12
 
13
-
14
  /**
15
  * @swagger
16
  * /api/pw/syncPortfolio:
@@ -208,6 +208,19 @@ pwRouter.use(jwtMiddleware);
208
  */
209
  pwRouter.get('/locationLookup', LocationLookup);
210
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
 
212
 
213
  export default pwRouter;
 
7
  import { fetchVendorsData } from "../controllers/propertyware/vendors.controller";
8
  import { syncInvoices } from "../controllers/propertyware/bills.controller";
9
  import { jwtMiddleware } from '../middlewares/authMiddleware';
10
+ import { fetchWorkorders } from "../controllers/propertyware/workorders.controller";
11
 
12
  const pwRouter = express.Router();
13
 
 
14
  /**
15
  * @swagger
16
  * /api/pw/syncPortfolio:
 
208
  */
209
  pwRouter.get('/locationLookup', LocationLookup);
210
 
211
+ /**
212
+ * @swagger
213
+ * /api/pw/workorders:
214
+ * get:
215
+ * summary: Location lookup
216
+ * tags: [Propertyware]
217
+ * responses:
218
+ * 200:
219
+ * description: Workorders fetched successfully
220
+ * 500:
221
+ * description: Error fetching workorders
222
+ */
223
+ pwRouter.get('/workorders', fetchWorkorders);
224
 
225
 
226
  export default pwRouter;
src/shared/services/propertyware.service.ts CHANGED
@@ -65,4 +65,8 @@ export const uploadBill = async (billId: string, params: FormData) => {
65
  return response.data;
66
  };
67
 
68
-
 
 
 
 
 
65
  return response.data;
66
  };
67
 
68
+ export const fetchAllWorkorders = async () => {
69
+ const response = await apiClientPW.get(`/workorders`);
70
+ console.log(response);
71
+ return response.data;
72
+ };