Skip to content

Commit

Permalink
Fixed set next node and missing params on Question node.
Browse files Browse the repository at this point in the history
  • Loading branch information
kiran-rean committed Nov 28, 2024
1 parent 4659350 commit fd589fd
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ body:json {
{
"Name": "Q1-Medical Emergency",
"Description": "Question 1.",
"Question": "Are you facing medical emergency now?",
"Type": "QuestionNode",
"ParentNodeId": "{{SCHEMA_ROOT_NODE_ID}}",
"SchemaId": "{{SCHEMA_ID}}",
"QuestionText": "Are you facing medical emergency now?",
"ResponseType": "Single Choice Selection",
"Options": [
{
Expand Down Expand Up @@ -67,7 +67,7 @@ body:json {
script:post-response {
let status = res.getStatus();
console.log(status)
if (status == 200) {
if (status == 201) {
bru.setEnvVar("Q1_ID", res.body.Data.id);
}

Expand Down
16 changes: 10 additions & 6 deletions bruno/Workflow service/environments/workflow-local.bru
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
vars {
ADMIN_USER_NAME: admin
BASE_URL: http://localhost:2345/api/v1
ADMIN_JWT: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOiIxMzE5Yzc2OC03MmU0LTQzMTctODZlNS1lNWYxYzdiOTI2NmEiLCJVc2VyTmFtZSI6ImFkbWluIiwiRGlzcGxheU5hbWUiOiJBZG1pbiBTeXN0ZW0iLCJTZXNzaW9uSWQiOiJlYzk0Y2M0Ny1lNTNiLTRhZDQtYWNiMy1mODVkMzBkZmVlNjEiLCJQaG9uZSI6Iis5MS0wMDAwMDAwMDAwIiwiRW1haWwiOm51bGwsImlhdCI6MTczMjU1MDgyMywiZXhwIjoxNzM1MTQyODIzfQ.bPVKJtPx3hw4lB_WHhhUGNbIka1-m_p4XSKgqbUqxJ8
ADMIN_ACCESS_TOKEN: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOiIxMzE5Yzc2OC03MmU0LTQzMTctODZlNS1lNWYxYzdiOTI2NmEiLCJVc2VyTmFtZSI6ImFkbWluIiwiRGlzcGxheU5hbWUiOiJBZG1pbiBTeXN0ZW0iLCJTZXNzaW9uSWQiOiJmNzRjNjU3OS1jYmQ1LTQ3MGMtYmFkMi01NjI4NDIzYzc0ZDgiLCJQaG9uZSI6Iis5MS0wMDAwMDAwMDAwIiwiRW1haWwiOm51bGwsImlhdCI6MTczMjU1MTEzMCwiZXhwIjoxNzM1MTQzMTMwfQ.dLOX78PfK_7aA9-CIGUtSDD4itoL1IBmGrqTkj2ibRg
ADMIN_SESSION_ID: f74c6579-cbd5-470c-bad2-5628423c74d8
ADMIN_USER_ID: 1319c768-72e4-4317-86e5-e5f1c7b9266a
MODERATOR_USER_NAME: moderator
MODERATOR_PASSWORD: DcgH2TvvZ5zM
MODERATOR_ACCESS_TOKEN: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOiI4OTNjYjY2Zi1hZTIyLTQ0NTEtOGJhYi1mYTVmNWEzYTUwMjMiLCJVc2VyTmFtZSI6Im1vZGVyYXRvciIsIkRpc3BsYXlOYW1lIjoiQ29udGVudCBNb2RlcmF0b3IiLCJTZXNzaW9uSWQiOiI2OGNiM2NhYS01ZGU5LTRmODMtYmZhMC1hODU5ZjY1OWQ2OWIiLCJQaG9uZSI6Iis5MS0xMTExMTExMTExIiwiRW1haWwiOm51bGwsImlhdCI6MTczMjYxMjkxOCwiZXhwIjoxNzM1MjA0OTE4fQ.FJFMqoLmGfVnZXa9YIplO9bTO1W96thTWvNPyRhtEeo
MODERATOR_SESSION_ID: 68cb3caa-5de9-4f83-bfa0-a859f659d69b
MODERATOR_USER_ID: 893cb66f-ae22-4451-8bab-fa5f5a3a5023
MODERATOR_USER_JWT: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOiI4OTNjYjY2Zi1hZTIyLTQ0NTEtOGJhYi1mYTVmNWEzYTUwMjMiLCJVc2VyTmFtZSI6Im1vZGVyYXRvciIsIkRpc3BsYXlOYW1lIjoiQ29udGVudCBNb2RlcmF0b3IiLCJTZXNzaW9uSWQiOiI2OGNiM2NhYS01ZGU5LTRmODMtYmZhMC1hODU5ZjY1OWQ2OWIiLCJQaG9uZSI6Iis5MS0xMTExMTExMTExIiwiRW1haWwiOm51bGwsImlhdCI6MTczMjYxMjkxOCwiZXhwIjoxNzM1MjA0OTE4fQ.FJFMqoLmGfVnZXa9YIplO9bTO1W96thTWvNPyRhtEeo
MODERATOR_SESSION_ID: 2c774fb8-8fcf-4be3-aec4-656231141592
TENANT_ID: d2151e5c-86b8-4bad-a55d-4d3bd3453572
SCHEMA_ID: fc327e87-45e4-4719-a218-8eee59a35aa5
SCHEMA_ROOT_NODE_ID: f579cf69-7d2a-4ca3-827f-f806683f7e4c
NODE_01_ID: f579cf69-7d2a-4ca3-827f-f806683f7e4c
Q1_ID: 9d2fecaa-2002-4924-aae7-256c39c414d9
}
vars:secret [
ADMIN_JWT,
ADMIN_ACCESS_TOKEN,
MODERATOR_ACCESS_TOKEN,
MODERATOR_USER_ID,
MODERATOR_USER_JWT,
ADMIN_PASSWORD,
API_KEY
]
30 changes: 20 additions & 10 deletions src/api/engine/node/node.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class NodeValidator extends BaseValidator {
})).optional(),
ExecutionRuleId : joi.string().uuid().optional(),
ExecutionDelaySeconds : joi.number().integer().optional(),
RawData : joi.object().allow(null).optional(),
});
await node.validateAsync(request.body);
return {
Expand All @@ -43,6 +44,7 @@ export class NodeValidator extends BaseValidator {
Actions : request.body.Actions ?? null,
ExecutionDelaySeconds : request.body.ExecutionDelaySeconds ?? null,
ExecutionRuleId : request.body.ExecutionRuleId ?? null,
RawData : request.body.RawData ?? null,
};
} catch (error) {
ErrorHandler.handleValidationError(error);
Expand All @@ -65,14 +67,17 @@ export class NodeValidator extends BaseValidator {
RawInput : joi.any().optional(),
Input : joi.object().optional(),
})).optional(),
Question : joi.string().max(512).required(),
QuestionText : joi.string().max(512).required(),
ResponseType : joi.string().valid(...Object.values(QuestionResponseType)).required(),
Options : joi.array().items(joi.object({
Text : joi.string().allow(null).max(512).required(),
ImageUrl : joi.string().allow(null).max(512).optional(),
Sequence : joi.number().integer().allow(null).max(10).optional(),
Metadata : joi.string().allow(null).max(1024).optional(),
})).optional(),
ExecutionRuleId : joi.string().uuid().optional(),
ExecutionDelaySeconds : joi.number().integer().optional(),
RawData : joi.object().allow(null).optional(),
// Paths : joi.array().items(joi.object({
// Name : joi.string().max(512).required(),
// Code : joi.string().max(16).optional(),
Expand All @@ -82,15 +87,18 @@ export class NodeValidator extends BaseValidator {
});
await node.validateAsync(request.body);
return {
Type : request.body.Type,
Name : request.body.Name,
Description : request.body.Description ?? null,
ParentNodeId : request.body.ParentNodeId,
SchemaId : request.body.SchemaId,
Actions : request.body.Actions ?? null,
Question : request.body.Question ?? null,
ResponseType : request.body.ResponseType ?? null,
Options : request.body.Options ?? [],
Type : request.body.Type,
Name : request.body.Name,
Description : request.body.Description ?? null,
ParentNodeId : request.body.ParentNodeId,
SchemaId : request.body.SchemaId,
Actions : request.body.Actions ?? null,
QuestionText : request.body.QuestionText ?? null,
ResponseType : request.body.ResponseType ?? null,
Options : request.body.Options ?? [],
ExecutionDelaySeconds : request.body.ExecutionDelaySeconds ?? null,
ExecutionRuleId : request.body.ExecutionRuleId ?? null,
RawData : request.body.RawData ?? null,
};
} catch (error) {
ErrorHandler.handleValidationError(error);
Expand All @@ -107,6 +115,7 @@ export class NodeValidator extends BaseValidator {
SchemaId : joi.string().uuid().optional(),
ExecutionRuleId : joi.string().uuid().optional(),
ExecutionDelaySeconds : joi.number().integer().optional(),
RawData : joi.object().allow(null).optional(),
});
await node.validateAsync(request.body);
return {
Expand All @@ -117,6 +126,7 @@ export class NodeValidator extends BaseValidator {
SchemaId : request.body.SchemaId ?? null,
ExecutionRuleId : request.body.ExecutionRuleId ?? null,
ExecutionDelaySeconds : request.body.ExecutionDelaySeconds ?? null,
RawData : request.body.RawData ?? null,
};
} catch (error) {
ErrorHandler.handleValidationError(error);
Expand Down
24 changes: 14 additions & 10 deletions src/database/mappers/engine/node.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,22 @@ export class NodeMapper {
Description : x.Description,
};
}) : [],
Question : question ? question.QuestionText : null,
Options : question ? question.Options?.map(x => {
return {
id : x.id,
Text : x.Text,
ImageUrl : x.ImageUrl,
Sequence : x.Sequence,
Metadata : x.Metadata,
};
}) : null,
Question : question ? {
ResponseType : question.ResponseType,
QuestionText : question.QuestionText ?? null,
Options : question.Options ? question.Options.map(x => {
return {
id : x.id,
Text : x.Text,
ImageUrl : x.ImageUrl,
Sequence : x.Sequence,
Metadata : x.Metadata,
};
}) : null,
} : null,
ExecutionDelaySeconds : node.ExecutionDelaySeconds,
ExecutionRuleId : node.ExecutionRuleId,
RawData : node.RawData,
CreatedAt : node.CreatedAt,
UpdatedAt : node.UpdatedAt,
};
Expand Down
15 changes: 9 additions & 6 deletions src/database/services/engine/node.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ export class NodeService extends BaseService {
const parentNode = await this.getNode(createModel.ParentNodeId);
const prefix = createModel.Type === NodeType.QuestionNode ? 'QNODE' : 'ENODE';
const node = this._nodeRepository.create({
Code : StringUtils.generateDisplayCode_RandomChars(12, prefix),
Type : createModel.Type,
Schema : schema,
ParentNode : parentNode,
Name : createModel.Name,
Description : createModel.Description,
Code : StringUtils.generateDisplayCode_RandomChars(12, prefix),
Type : createModel.Type,
Schema : schema,
ParentNode : parentNode,
Name : createModel.Name,
Description : createModel.Description,
ExecutionDelaySeconds : createModel.ExecutionDelaySeconds,
ExecutionRuleId : createModel.ExecutionRuleId,
RawData : createModel.RawData,
});
var record = await this._nodeRepository.save(node);
if (record == null)
Expand Down
5 changes: 4 additions & 1 deletion src/database/services/engine/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Condition } from '../../models/engine/condition.model';
import { CommonUtilsService } from './common.utils.service';
import { NodeAction } from '../../models/engine/node.action.model';
import { StringUtils } from '../../../common/utilities/string.utils';
import { NodeType } from '../../../domain.types/engine/engine.enums';

///////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -49,7 +50,7 @@ export class SchemaService extends BaseService {
let rootNode: Node = null;
if (createModel.RootNode) {
rootNode = this._nodeRepository.create({
Code : StringUtils.generateDisplayCode_RandomChars(12, 'SCHMA'),
Code : StringUtils.generateDisplayCode_RandomChars(12, 'ENODE'),
ParentNode : null,
Name : createModel.RootNode.Name,
Type : createModel.RootNode.Type,
Expand All @@ -58,9 +59,11 @@ export class SchemaService extends BaseService {
}
else {
rootNode = await this._nodeRepository.create({
Code : StringUtils.generateDisplayCode_RandomChars(12, 'ENODE'),
Name : rootNodeName,
ParentNode : null,
Description : `Root node for ${createModel.Name}`,
Type : NodeType.ExecutionNode,
});
}
if (rootNode == null) {
Expand Down
16 changes: 11 additions & 5 deletions src/domain.types/engine/node.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ export interface NodeCreateModel {
Actions ?: XAction[];
ExecutionDelaySeconds?: number;
ExecutionRuleId ?: uuid;
RawData ?: any;
}

export interface QuestionNodeCreateModel extends NodeCreateModel {
Question : string;
ResponseType: QuestionResponseType;
Options : XQuestionOption[];
QuestionText : string;
ResponseType : QuestionResponseType;
Options : XQuestionOption[];
}

export interface NodeUpdateModel {
Expand All @@ -36,6 +37,7 @@ export interface NodeUpdateModel {
Actions ?: XAction[];
ExecutionDelaySeconds?: number;
ExecutionRuleId ?: uuid;
RawData ?: any;
}

export interface NodeResponseDto {
Expand All @@ -58,10 +60,14 @@ export interface NodeResponseDto {
Name : string;
Description: string;
};
Question? : string;
Options? : XQuestionOption[];
Question ? : {
ResponseType : QuestionResponseType;
QuestionText? : string;
Options? : XQuestionOption[];
},
ExecutionDelaySeconds?: number;
ExecutionRuleId? : uuid;
RawData? : any;
CreatedAt: Date;
UpdatedAt: Date;
}
Expand Down

0 comments on commit fd589fd

Please # to comment.