Skip to content

Commit

Permalink
Merge branch 'release/5.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
nsteenbeek committed Jul 30, 2021
2 parents 8e80e60 + e8fe31a commit 5449038
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bin/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hso/d365-cli",
"version": "5.3.0",
"version": "5.3.1",
"author": "HSO Innovation <[email protected]> (http://www.hso.com)",
"description": "HSO D365 Command Line Interface",
"repository": {
Expand Down
50 changes: 49 additions & 1 deletion src/generator/Enum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as shell from 'shelljs';
import * as fs from 'fs';
import {NodeApi} from '../root/tools/NodeApi/NodeApi';
import {SavedQueryService} from '../root/tools/SavedQuery/SavedQuery.service';
import {SolutionService} from '../root/tools/Solution/Solution.service';
import {SolutionComponentService} from '../root/tools/SolutionComponent/SolutionComponent.service';

export class Enum {
private readonly bearer: string;
Expand All @@ -24,6 +27,7 @@ export class Enum {
await this.log(`Generating ${this.entityName}.enum.ts<br/>`);
const enumAttributeNames = await this.getAttributeNamesEnumString();
const navigationPropertyNames = await this.getNavigationPropertyNamesString();
const savedQueries = await this.getSavedQueriesString();
const enumStrings = await this.getEnumStrings();
const enumFilepath = `src/${this.entityName}/${this.entityName}.enum.ts`;
shell.cp('-r', `${__dirname}/Entity/Entity.enum.ts`, `src/${this.entityName}`);
Expand All @@ -32,7 +36,51 @@ export class Enum {
shell.exec(`git add ${enumFilepath}`);
const fileData = String(fs.readFileSync(enumFilepath));
await this.log(`Generated ${this.entityName}.enum.ts<br/>`);
shell.ShellString(fileData + enumAttributeNames + navigationPropertyNames + enumStrings).to(enumFilepath);
shell.ShellString(fileData + enumAttributeNames + navigationPropertyNames + enumStrings + savedQueries).to(enumFilepath);
}

// eslint-disable-next-line max-lines-per-function
private async getSavedQueriesString(): Promise<string> {
let savedQueriesString = '';
const solution = await SolutionService.getSolution(['solutionid'], this.bearer);
const solutionComponents = await SolutionComponentService.retrieveMultipleRecords({
select: ['objectid'],
filters: [{
conditions: [{
attribute: '_solutionid_value',
value: solution.solutionid
}]
}, {
type: 'or',
conditions: [{
attribute: 'componenttype',
value: 26
}]
}]
}, this.bearer);
savedQueriesString += `export const ${this.entityName}Views = {\n`;
for (const solutionComponent of solutionComponents) {
const objectid = solutionComponent.objectid;
const savedQueries = await SavedQueryService.retrieveMultipleRecords({
select: ['savedqueryid', 'name', 'returnedtypecode', 'savedqueryidunique'],
filters: [{
conditions: [{
attribute: 'savedqueryid',
value: objectid
}]
}]
}, this.bearer);
const savedQuery = savedQueries[0];
if (savedQuery && savedQuery.returnedtypecode === this.entityLogicalName) {
const {name, savedqueryidunique} = savedQuery;
savedQueriesString += ` ${Enum.capitalize(name.replace(/ /g, ''))}: {\n`;
savedQueriesString += ` name: '${name}',\n`;
savedQueriesString += ` savedqueryidunique: '${savedqueryidunique}',\n`;
savedQueriesString += ` },\n`;
}
}
savedQueriesString += `};\n`;
return savedQueriesString;
}

private async getNavigationPropertyNamesString(): Promise<string> {
Expand Down
8 changes: 8 additions & 0 deletions src/root/tools/SavedQuery/SavedQuery.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export interface SavedQueryModel extends Model {
savedqueryid?: string;
name?: string;
returnedtypecode?: string;
savedqueryidunique?: string;
solutionid?: string;
}
14 changes: 14 additions & 0 deletions src/root/tools/SavedQuery/SavedQuery.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {NodeApi} from '../NodeApi/NodeApi';
import {SavedQueryModel} from './SavedQuery.model';

export class SavedQueryService {
private static entitySetName = 'savedqueries';

public static async retrieveMultipleRecords(multipleSystemQueryOptions: MultipleSystemQueryOptions, bearer: string): Promise<SavedQueryModel[]> {
return NodeApi.retrieveMultipleRecords(SavedQueryService.entitySetName, multipleSystemQueryOptions, bearer);
}

public static async updateRecord(id: string, savedQueryModel: SavedQueryModel, bearer: string): Promise<SavedQueryModel> {
return NodeApi.updateRecord(SavedQueryService.entitySetName, id, savedQueryModel, bearer);
}
}

0 comments on commit 5449038

Please sign in to comment.