mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: ability to activate and inactivate the given item.
This commit is contained in:
@@ -30,6 +30,22 @@ export default class ItemsController extends BaseController {
|
||||
asyncMiddleware(this.newItem.bind(this)),
|
||||
this.handlerServiceErrors,
|
||||
);
|
||||
router.post(
|
||||
'/:id/activate', [
|
||||
...this.validateSpecificItemSchema,
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.activateItem.bind(this)),
|
||||
this.handlerServiceErrors
|
||||
);
|
||||
router.post(
|
||||
'/:id/inactivate', [
|
||||
...this.validateSpecificItemSchema,
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.inactivateItem.bind(this)),
|
||||
this.handlerServiceErrors,
|
||||
)
|
||||
router.post(
|
||||
'/:id', [
|
||||
...this.validateItemSchema,
|
||||
@@ -226,6 +242,50 @@ export default class ItemsController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates the given item.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
async activateItem(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const itemId: number = req.params.id;
|
||||
|
||||
try {
|
||||
await this.itemsService.activateItem(tenantId, itemId);
|
||||
|
||||
return res.status(200).send({
|
||||
id: itemId,
|
||||
message: 'The item has been activated successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inactivates the given item.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
async inactivateItem(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const itemId: number = req.params.id;
|
||||
|
||||
try {
|
||||
await this.itemsService.inactivateItem(tenantId, itemId);
|
||||
|
||||
return res.status(200).send({
|
||||
id: itemId,
|
||||
message: 'The item has been inactivated successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given item from the storage.
|
||||
* @param {Request} req
|
||||
|
||||
Reference in New Issue
Block a user