Skip to content

Commit

Permalink
feat: add update and delete item routes to BaseAPI and improve monito…
Browse files Browse the repository at this point in the history
…r ID handling in WorkspaceNotificationRuleService
  • Loading branch information
simlarsen committed Feb 14, 2025
1 parent 4d083f9 commit 8ec0825
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
49 changes: 49 additions & 0 deletions Common/Server/API/BaseAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,31 @@ export default class BaseAPI<
},
);

router.post(
`${new this.entityType().getCrudApiPath()?.toString()}/:id/update-item`,
UserMiddleware.getUserMiddleware,
async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
try {
await this.updateItem(req, res);
} catch (err) {
next(err);
}
},
);


router.get(
`${new this.entityType().getCrudApiPath()?.toString()}/:id/update-item`,
UserMiddleware.getUserMiddleware,
async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
try {
await this.updateItem(req, res);
} catch (err) {
next(err);
}
},
);

// Delete
router.delete(
`${new this.entityType().getCrudApiPath()?.toString()}/:id`,
Expand All @@ -144,6 +169,30 @@ export default class BaseAPI<
},
);

router.post(
`${new this.entityType().getCrudApiPath()?.toString()}/:id/delete-item`,
UserMiddleware.getUserMiddleware,
async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
try {
await this.deleteItem(req, res);
} catch (err) {
next(err);
}
},
);

router.get(
`${new this.entityType().getCrudApiPath()?.toString()}/:id/delete-item`,
UserMiddleware.getUserMiddleware,
async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
try {
await this.deleteItem(req, res);
} catch (err) {
next(err);
}
},
);

this.router = router;
this.service = service;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/Server/Services/WorkspaceNotificationRuleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class Service extends DatabaseService<Model> {

const monitorLabels: Array<Label> =
await MonitorService.getLabelsForMonitors({
monitorIds: alert?.monitor?.id! ? [alert?.monitor?.id!] : [],
monitorIds: alert?.monitor?.id ? [alert?.monitor?.id] : [],
});

return {
Expand Down

0 comments on commit 8ec0825

Please sign in to comment.