mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: WIP advanced filter.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { param, query } from 'express-validator';
|
||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||
import { param } from 'express-validator';
|
||||
import BaseController from './BaseController';
|
||||
import { ServiceError } from 'exceptions';
|
||||
import ResourceService from 'services/Resource/ResourceService';
|
||||
@@ -19,32 +18,15 @@ export default class ResourceController extends BaseController {
|
||||
|
||||
router.get(
|
||||
'/:resource_model/meta',
|
||||
[...this.resourceModelParamSchema],
|
||||
[
|
||||
param('resource_model').exists().trim().escape()
|
||||
],
|
||||
this.asyncMiddleware(this.resourceMeta.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/:resource_model/fields',
|
||||
[...this.resourceModelParamSchema],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.resourceFields.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
router.get(
|
||||
'/:resource_model/data',
|
||||
[...this.resourceModelParamSchema],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.resourceData.bind(this)),
|
||||
this.handleServiceErrors
|
||||
);
|
||||
return router;
|
||||
}
|
||||
|
||||
get resourceModelParamSchema() {
|
||||
return [param('resource_model').exists().trim().escape()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve resource model meta.
|
||||
* @param {Request} req -
|
||||
@@ -52,7 +34,7 @@ export default class ResourceController extends BaseController {
|
||||
* @param {NextFunction} next -
|
||||
* @returns {Response}
|
||||
*/
|
||||
private resourceMeta = (
|
||||
public resourceMeta = (
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
@@ -73,56 +55,6 @@ export default class ResourceController extends BaseController {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve resource fields of the given resource.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
resourceFields(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const { resource_model: resourceModel } = req.params;
|
||||
|
||||
try {
|
||||
// const resourceFields = this.resourcesService.getResourceFields(
|
||||
// tenantId,
|
||||
// resourceModel
|
||||
// );
|
||||
|
||||
return res.status(200).send({
|
||||
resource_fields: [],
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve resource data of the give resource based on the given query.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
async resourceData(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const { resource_model: resourceModel } = req.params;
|
||||
const filter = req.query;
|
||||
|
||||
try {
|
||||
const resourceData = await this.resourcesService.getResourceData(
|
||||
tenantId,
|
||||
resourceModel,
|
||||
filter
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
resource_data: this.transfromToResponse(resourceData),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles service errors.
|
||||
* @param {Error} error
|
||||
|
||||
Reference in New Issue
Block a user