mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 04:10:32 +00:00
add server to monorepo.
This commit is contained in:
60
packages/server/src/api/controllers/Jobs.ts
Normal file
60
packages/server/src/api/controllers/Jobs.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import BaseController from '@/api/controllers/BaseController';
|
||||
import { ServiceError } from '@/exceptions';
|
||||
import JobsService from '@/services/Jobs/JobsService';
|
||||
|
||||
@Service()
|
||||
export default class ItemsController extends BaseController {
|
||||
@Inject()
|
||||
jobsService: JobsService;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.get('/:id', this.getJob, this.handlerServiceErrors);
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve job details.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
private getJob = async (req: Request, res: Response, next: NextFunction) => {
|
||||
const { id } = req.params;
|
||||
|
||||
try {
|
||||
const job = await this.jobsService.getJob(id);
|
||||
|
||||
return res.status(200).send({
|
||||
job: this.transfromToResponse(job),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles service errors.
|
||||
* @param {Error} error
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
private handlerServiceErrors = (
|
||||
error: Error,
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) => {
|
||||
if (error instanceof ServiceError) {
|
||||
}
|
||||
next(error);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user