Added Asset getMany / getOne / create rest endpoints
MODIFY
src/server/rest/v1/router/api/AssetRouter.ts
src/server/rest/v1/router/api/AssetRouter.ts
@@ -14,12 +14,34 @@ export default class AssetRouter {
public buildRoutes(): express.Router {
this.buildRouteCreateAssetConsumption();
+ this.buildRouteCreateAsset();
+ this.buildRouteGetAssets();
+ this.buildRouteGetAsset();
return this.router;
}
protected buildRouteCreateAssetConsumption(): void {
this.router.post(`/${ServerRoute.REST_ASSET_CONSUMPTION}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.assetID = req.params.id;
await RouterUtils.handleServerAction(AssetService.handleCreateAssetConsumption.bind(this), ServerAction.ASSET_CONSUMPTION, req, res, next);
});
}
+
+ protected buildRouteCreateAsset(): void {
+ this.router.post(`/${ServerRoute.REST_ASSETS}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(AssetService.handleCreateAsset.bind(this), ServerAction.ASSET_CREATE, req, res, next);
+ });
+ }
+
+ protected buildRouteGetAssets(): void {
+ this.router.get(`/${ServerRoute.REST_ASSETS}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(AssetService.handleGetAssets.bind(this), ServerAction.ASSETS, req, res, next);
+ });
+ }
+
+ protected buildRouteGetAsset(): void {
+ this.router.get(`/${ServerRoute.REST_ASSET}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(AssetService.handleGetAsset.bind(this), ServerAction.ASSET, req, res, next);
+ });
+ }
}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -526,7 +526,9 @@ export enum ServerRoute {
REST_TAGS_IMPORT = 'tags/action/import',
REST_TAGS_EXPORT = 'tags/action/export',
- REST_ASSET_CONSUMPTION = 'assets/:assetID/consumption',
+ REST_ASSETS = 'assets',
+ REST_ASSET = 'assets/:id',
+ REST_ASSET_CONSUMPTION = 'assets/:id/consumption',
REST_PING = 'ping',

MODIFY
test/api/AssetTest.ts
test/api/AssetTest.ts
import chai, { expect } from 'chai';
+import Asset from '../../src/types/Asset';
import CentralServerService from './client/CentralServerService';
+import Company from '../../src/types/Company';
import ContextDefinition from './context/ContextDefinition';
import ContextProvider from './context/ContextProvider';
import Factory from '../factories/Factory';
+import Site from '../../src/types/Site';
+import SiteArea from '../../src/types/SiteArea';
import TenantContext from './context/TenantContext';
import chaiSubset from 'chai-subset';
@@ -15,14 +19,14 @@ class TestData {
public centralUserService: CentralServerService;
public userContext: any;
public userService: CentralServerService;
- public newCompany: any;
- public createdCompanies: any[] = [];
- public newSite: any;
- public createdSites: any[] = [];
- public newSiteArea: any;
- public createdSiteAreas: any[] = [];
- public newAsset: any;
- public createdAssets: any[] = [];
+ public newCompany: Company;
+ public createdCompanies: Company[] = [];
+ public newSite: Site;
+ public createdSites: Site[] = [];
+ public newSiteArea: SiteArea;
+ public createdSiteAreas: SiteArea[] = [];
+ public newAsset: Asset;
+ public createdAssets: Asset[] = [];
}
const testData: TestData = new TestData();

MODIFY
test/api/client/AssetApi.ts
test/api/client/AssetApi.ts
+import Asset from '../../../src/types/Asset';
import AuthenticatedBaseApi from './utils/AuthenticatedBaseApi';
import CrudApi from './utils/CrudApi';
+import { ServerRoute } from '../../../src/types/Server';
import TestConstants from './utils/TestConstants';
export default class AssetApi extends CrudApi {
@@ -7,23 +9,23 @@ export default class AssetApi extends CrudApi {
super(authenticatedApi);
}
- public async readById(id): Promise<any> {
- return super.readById(id, '/client/api/Asset');
+ public async readById(id: string): Promise<any> {
+ return super.readById(id, this.buildRestEndpointUrl(ServerRoute.REST_ASSET, { id }));
}
public async readAll(params, paging = TestConstants.DEFAULT_PAGING, ordering = TestConstants.DEFAULT_ORDERING): Promise<any> {
- return super.readAll(params, paging, ordering, '/client/api/Assets');
+ return super.readAll(params, paging, ordering, this.buildRestEndpointUrl(ServerRoute.REST_ASSETS));
}
- public async create(data): Promise<any> {
- return super.create(data, '/client/api/AssetCreate');
+ public async create(data: Asset): Promise<any> {
+ return super.create(data, this.buildRestEndpointUrl(ServerRoute.REST_ASSETS));
}
- public async update(data: Promise<any>) {
+ public async update(data: Asset): Promise<any> {
return super.update(data, '/client/api/AssetUpdate');
}
- public async delete(id): Promise<any> {
+ public async delete(id: string): Promise<any> {
return super.delete(id, '/client/api/AssetDelete');
}
}

Added Asset getMany / getOne / create rest endpoints