Skip to content

Commit

Permalink
feat(api): update asset link routes
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamTownsley committed Nov 19, 2023
1 parent 855dca5 commit 06368b7
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion electron/api/routes/AssetLinkRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ router.post('/', async (req: Request, res: Response) => {

// @ROUTE: GET api/asset-links/hardware/:id
// @DESCRIPTION: Used for getting ALL Asset Links for a specific Hardware Asset.
router.get('/hardware/:id', async (req: Request, res: Response) => {
router.get('/hardware/:id/get-all', async (req: Request, res: Response) => {
await wrapper(async (db: any) => {
const collection: Collection = db.collection(DATABASE);
const id = req.params.id;
Expand All @@ -72,6 +72,27 @@ router.get('/hardware/:id', async (req: Request, res: Response) => {
return res.json(resp_arr.filter(x => !!x));
});
});

// @ROUTE: GET api/asset-links/hardware/:id
// @DESCRIPTION: Used for getting ALL Asset Links for a specific Hardware Asset.
router.get('/software/:id/get-all', async (req: Request, res: Response) => {
await wrapper(async (db: any) => {
const collection: Collection = db.collection(DATABASE);
const id = req.params.id;

const resp = await collection.find({ software_id: new mongo.ObjectId(id) }).toArray();

let resp_arr = [];
for (const [i, link] of resp.entries()) {
const subresp = await db.collection('hardware').findOne({ _id: link.hardware_id }) ?? undefined;
resp_arr.push({
hardware: subresp,
link: resp[i]
});
}
return res.json(resp_arr.filter(x => !!x));
});
});
// @ROUTE: DELETE api/asset-links/hardware/:id
// @DESCRIPTION: Used for getting ALL Asset Links for a specific Hardware Asset.
router.delete('/hardware/:hwid/:swid', async (req: Request, res: Response) => {
Expand Down

0 comments on commit 06368b7

Please sign in to comment.