From eb6f9ab6a54b10d32408831abffcc2f58f72bd64 Mon Sep 17 00:00:00 2001 From: Kiran Kharade Date: Tue, 26 Nov 2024 22:19:47 +0530 Subject: [PATCH] Added schema creation --- .../Create schema.bru | 50 ++++---- .../environments/workflow-local.bru | 5 + src/api/engine/schema/schema.controller.ts | 1 + src/api/engine/schema/schema.validator.ts | 109 ++++++++++-------- src/auth/auth.handler.ts | 18 +-- src/auth/wrappers/client.authenticator.ts | 2 +- src/auth/wrappers/user.authorizer.ts | 2 +- src/common/utilities/string.utils.ts | 8 +- .../mappers/engine/schema.instance.mapper.ts | 9 +- src/database/mappers/engine/schema.mapper.ts | 19 ++- src/database/models/engine/schema.model.ts | 19 +-- .../services/engine/common.utils.service.ts | 3 +- .../engine/schema.instance.service.ts | 11 +- .../services/engine/schema.service.ts | 69 ++++------- .../engine/schema.domain.types.ts | 39 +++---- .../engine/schema.instance.types.ts | 9 +- 16 files changed, 171 insertions(+), 202 deletions(-) diff --git a/bruno/Workflow service/04 - Schema construction/ALERT v1/01 - Create and update schema/Create schema.bru b/bruno/Workflow service/04 - Schema construction/ALERT v1/01 - Create and update schema/Create schema.bru index d880489..a5b4c60 100644 --- a/bruno/Workflow service/04 - Schema construction/ALERT v1/01 - Create and update schema/Create schema.bru +++ b/bruno/Workflow service/04 - Schema construction/ALERT v1/01 - Create and update schema/Create schema.bru @@ -29,20 +29,22 @@ body:json { "Name": "Phone", "Type": "Phonenumber", "Description": "This is phone number of CFR responding to emergency", - "Value": "+91-9970155165" + "Value": null }, { "Name": "Location", "Description": "This is the location where the emergency has occurred.", + "Type": "Location", "Value": { - "Longitude": 23.434343, - "Lattitude": 43.454353 + "Longitude": null, + "Lattitude": null } }, { "Name": "Timestamp", "Description": "This is the timestamp the emergency has been reported.", - "Value": "2024-11-26T10:07:56.255Z" + "Type": "DateTime", + "Value": null } ] }, @@ -50,26 +52,28 @@ body:json { "Type": "ExecutionNode", "Name": "Root Node", "Description": "Send first message upon triggering of the workflow", - "Action": { - "ActionType": "SendMessage", - "Name": "Send First message", - "Input": { - "Params": [ - { - "ActionType": "SendMessage", - "Type": "Phonenumber", - "Value": null, - "Source": "Almanac", - "Key": "ContextParams:Phone" - }, - { - "ActionType": "Send Message", - "Type": "Text", - "Value": "Hope you are safe." - } - ] + "Actions": [ + { + "Type": "SendMessage", + "Name": "Send First message", + "Input": { + "Params": [ + { + "ActionType": "SendMessage", + "Type": "Phonenumber", + "Value": null, + "Source": "Almanac", + "Key": "ContextParams:Phone" + }, + { + "ActionType": "SendMessage", + "Type": "Text", + "Value": "Hope you are safe." + } + ] + } } - } + ] } } } diff --git a/bruno/Workflow service/environments/workflow-local.bru b/bruno/Workflow service/environments/workflow-local.bru index 4909284..b5e5fde 100644 --- a/bruno/Workflow service/environments/workflow-local.bru +++ b/bruno/Workflow service/environments/workflow-local.bru @@ -7,6 +7,11 @@ vars { 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 + TENANT_ID: d2151e5c-86b8-4bad-a55d-4d3bd3453572 } vars:secret [ ADMIN_PASSWORD, diff --git a/src/api/engine/schema/schema.controller.ts b/src/api/engine/schema/schema.controller.ts index dc75dd1..8fc4a3f 100644 --- a/src/api/engine/schema/schema.controller.ts +++ b/src/api/engine/schema/schema.controller.ts @@ -25,6 +25,7 @@ export class SchemaController { if (record === null) { ErrorHandler.throwInternalServerError('Unable to add schema!'); } + const message = 'Schema added successfully!'; return ResponseHandler.success(request, response, message, 201, record); } catch (error) { diff --git a/src/api/engine/schema/schema.validator.ts b/src/api/engine/schema/schema.validator.ts index baa545b..6dcbfe1 100644 --- a/src/api/engine/schema/schema.validator.ts +++ b/src/api/engine/schema/schema.validator.ts @@ -3,7 +3,7 @@ import express from 'express'; import { SchemaCreateModel, SchemaUpdateModel, SchemaSearchFilters } from '../../../domain.types/engine/schema.domain.types'; import { ErrorHandler } from '../../../common/handlers/error.handler'; import BaseValidator from '../../base.validator'; -import { NodeType, SchemaType } from '../../../domain.types/engine/engine.enums'; +import { ActionType, InputSourceType, NodeType, OutputDestinationType, ParamType, SchemaType } from '../../../domain.types/engine/engine.enums'; /////////////////////////////////////////////////////////////////////////////////////////////// @@ -12,39 +12,57 @@ export class SchemaValidator extends BaseValidator { public validateCreateRequest = async (request: express.Request): Promise => { try { const schema = joi.object({ - ClientId : joi.string().uuid().required(), - Name : joi.string().max(32).required(), - Type : joi.string().valid(...Object.values(SchemaType)).required(), - Description : joi.string().max(256).optional(), - ValidFrom : joi.date().iso().greater('now').optional(), - ValidTill : joi.date().iso().greater(joi.ref('ValidFrom')).optional(), - IsValid : joi.boolean().optional(), - EventTypeIds : joi.array().items(joi.string().uuid()).optional(), - RootNode : joi.object({ + TenantId : joi.string().uuid().required(), + Name : joi.string().max(32).required(), + Type : joi.string().valid(...Object.values(SchemaType)).required(), + Description : joi.string().max(256).optional(), + ContextParams : joi.object({ + Name : joi.string().max(128).required(), + Params : joi.array().items(joi.object({ + Name : joi.string().max(128).required(), + Type : joi.string().valid(...Object.values(ParamType)).required(), + Description : joi.string().max(256).optional(), + Value : joi.any().required(), + })).required() + }).optional(), + RootNode : joi.object({ Type : joi.string().valid(...Object.values(NodeType)).required(), - Name : joi.string().max(32).required(), + Name : joi.string().max(128).required(), Description : joi.string().max(256).optional(), + Actions : joi.array().items({ + Type : joi.string().valid(...Object.values(ActionType)).required(), + Name : joi.string().max(128).required(), + Input : joi.object({ + Params : joi.array().items(joi.object({ + ActionType : joi.string().valid(...Object.values(ActionType)).optional(), + Type : joi.string().valid(...Object.values(ParamType)).required(), + Value : joi.any().allow(null).required(), + Source : joi.string().valid(...Object.values(InputSourceType)).optional(), + Key : joi.string().max(256).optional(), + })).required(), + }).required(), + Output : joi.object({ + Params : joi.array().items(joi.object({ + ActionType : joi.string().valid(...Object.values(ActionType)).optional(), + Type : joi.string().valid(...Object.values(ParamType)).required(), + Value : joi.any().allow(null).required(), + Destination : joi.string().valid(...Object.values(OutputDestinationType)).optional(), + Key : joi.string().max(256).optional(), + })).required(), + }).optional(), + }).optional() }).optional() }); await schema.validateAsync(request.body); - const node = request.body.RootNode; - // if (node) { - // node.Type = node.NodeType; - // delete node.NodeType; - // } - return { - ClientId : request.body.ClientId, - Name : request.body.Name, - Description : request.body.Description ?? null, - Type : request.body.Type, - ValidFrom : request.body.ValidFrom ?? new Date(), - ValidTill : request.body.ValidTill ?? null, - IsValid : request.body.IsValid ?? true, - EventTypeIds : request.body.EventTypeIds ?? [], - RootNode : node ?? null, + TenantId : request.body.TenantId, + Name : request.body.Name, + Description : request.body.Description ?? null, + Type : request.body.Type, + RootNode : request.body.RootNode ?? null, + ContextParams : request.body.ContextParams ?? null, }; } catch (error) { @@ -55,24 +73,25 @@ export class SchemaValidator extends BaseValidator { public validateUpdateRequest = async (request: express.Request): Promise => { try { const schema = joi.object({ - ClientId : joi.string().uuid().optional(), - Name : joi.string().max(32).optional(), - Type : joi.string().valid(...Object.values(SchemaType)).optional(), - Description : joi.string().max(256).optional(), - ValidFrom : joi.date().iso().greater('now').optional(), - ValidTill : joi.date().iso().greater(joi.ref('ValidFrom')).optional(), - IsValid : joi.boolean().optional(), - EventTypeIds : joi.array().items(joi.string().uuid()).optional(), + Name : joi.string().max(32).optional(), + Type : joi.string().valid(...Object.values(SchemaType)).optional(), + Description : joi.string().max(256).optional(), + ContextParams : joi.object({ + Name : joi.string().max(128).required(), + Params : joi.array().items(joi.object({ + Name : joi.string().max(128).required(), + Type : joi.string().valid(...Object.values(ParamType)).required(), + Description : joi.string().max(256).optional(), + Value : joi.any().required(), + })).required() + }).optional(), }); await schema.validateAsync(request.body); return { - ClientId : request.body.ClientId ?? null, - Name : request.body.Name ?? null, - Type : request.body.Type ?? null, - Description : request.body.Description ?? null, - ValidFrom : request.body.ValidFrom ?? null, - ValidTill : request.body.ValidTill ?? null, - IsValid : request.body.IsValid ?? null, + Name : request.body.Name ?? null, + Type : request.body.Type ?? null, + Description : request.body.Description ?? null, + ContextParams : request.body.ContextParams ?? null, }; } catch (error) { ErrorHandler.handleValidationError(error); @@ -82,7 +101,7 @@ export class SchemaValidator extends BaseValidator { public validateSearchRequest = async (request: express.Request): Promise => { try { const schema = joi.object({ - clientId : joi.string().uuid().optional(), + tenantId : joi.string().uuid().optional(), name : joi.string().max(64).optional(), }); await schema.validateAsync(request.query); @@ -105,9 +124,9 @@ export class SchemaValidator extends BaseValidator { if (name != null) { filters['Name'] = name; } - var clientId = query.clientId ? query.clientId : null; - if (clientId != null) { - filters['ClientId'] = clientId; + var tenantId = query.tenantId ? query.tenantId : null; + if (tenantId != null) { + filters['TenantId'] = tenantId; } return filters; diff --git a/src/auth/auth.handler.ts b/src/auth/auth.handler.ts index 643f3ed..cdbc809 100644 --- a/src/auth/auth.handler.ts +++ b/src/auth/auth.handler.ts @@ -13,9 +13,9 @@ export type AuthMiddleware = (request: Request, response: Response, next: NextFu export class AuthHandler { public static handle = ( - context:string, - authenticateClient = true, - authenticateUser = true, + context:string, + authenticateClient = true, + authenticateUser = true, authorizeUser = true): AuthMiddleware[] => { var middlewares: AuthMiddleware[] = []; @@ -47,13 +47,15 @@ export class AuthHandler { var userAuthenticator = Injector.Container.resolve(UserAuthenticator); middlewares.push(userAuthenticator.authenticate); } - if (authorizeUser) { - var authorizer = Injector.Container.resolve(UserAuthorizer); - middlewares.push(authorizer.authorize); - } + + // KK: Temporary commented out + // if (authorizeUser) { + // var authorizer = Injector.Container.resolve(UserAuthorizer); + // middlewares.push(authorizer.authorize); + // } return middlewares; - } + }; public static verifyAccess = async(request: Request): Promise => { diff --git a/src/auth/wrappers/client.authenticator.ts b/src/auth/wrappers/client.authenticator.ts index bb020d9..80a3398 100644 --- a/src/auth/wrappers/client.authenticator.ts +++ b/src/auth/wrappers/client.authenticator.ts @@ -36,6 +36,6 @@ export class ClientAuthenticator { public verify = async (request: express.Request): Promise => { const authResult = await this._authenticator.authenticate(request); return authResult.Result; - } + }; } diff --git a/src/auth/wrappers/user.authorizer.ts b/src/auth/wrappers/user.authorizer.ts index 0ac8584..48d13c1 100644 --- a/src/auth/wrappers/user.authorizer.ts +++ b/src/auth/wrappers/user.authorizer.ts @@ -31,6 +31,6 @@ export class UserAuthorizer { public verify = async (request: express.Request): Promise => { const authorized = await this._authorizer.authorize(request, null); return authorized; - } + }; } diff --git a/src/common/utilities/string.utils.ts b/src/common/utilities/string.utils.ts index 2c77d1b..1cfd340 100644 --- a/src/common/utilities/string.utils.ts +++ b/src/common/utilities/string.utils.ts @@ -84,12 +84,12 @@ export class StringUtils { return identifier; }; - public static generateDisplayCode_RandomChars = (prefix = null) => { + public static generateDisplayCode_RandomChars = (length = 12, prefix = null) => { const code = genpass.generate({ - length : 24, + length : length, numbers : true, - lowercase : true, - uppercase : false, + lowercase : false, + uppercase : true, symbols : false, }); return prefix ? prefix + '#' + code : code; diff --git a/src/database/mappers/engine/schema.instance.mapper.ts b/src/database/mappers/engine/schema.instance.mapper.ts index 5fed332..73131e4 100644 --- a/src/database/mappers/engine/schema.instance.mapper.ts +++ b/src/database/mappers/engine/schema.instance.mapper.ts @@ -2,13 +2,12 @@ import { SchemaInstance } from '../../models/engine/schema.instance.model'; import { SchemaInstanceResponseDto } from '../../../domain.types/engine/schema.instance.types'; -import { EventType } from '../../../domain.types/enums/event.type'; /////////////////////////////////////////////////////////////////////////////////// export class SchemaInstanceMapper { - static toResponseDto = (instance: SchemaInstance, eventTypes?: EventType[]): SchemaInstanceResponseDto => { + static toResponseDto = (instance: SchemaInstance): SchemaInstanceResponseDto => { if (instance == null) { return null; } @@ -18,11 +17,7 @@ export class SchemaInstanceMapper { id : instance.Schema.id, Name : instance.Schema.Name, Description : instance.Schema.Description, - Client : instance.Schema.Client ? { - id : instance.Schema.Client.id, - Name : instance.Schema.Client.Name, - } : null, - EventTypes : eventTypes ?? [], + TenantId : instance.Schema.TenantId, }, RootNodeInstance : instance.RootNodeInstance ? { id : instance.RootNodeInstance.id, diff --git a/src/database/mappers/engine/schema.mapper.ts b/src/database/mappers/engine/schema.mapper.ts index 96e2ddb..7aa116a 100644 --- a/src/database/mappers/engine/schema.mapper.ts +++ b/src/database/mappers/engine/schema.mapper.ts @@ -13,26 +13,21 @@ export class SchemaMapper { return null; } const dto: SchemaResponseDto = { - id : schema.id, - Type : schema.Type, - Client : schema.Client ? { - id : schema.Client.id, - Name : schema.Client.Name, - Code : schema.Client.Code, - } : null, + id : schema.id, + Type : schema.Type, + TenantId : schema.TenantId, Name : schema.Name, Description : schema.Description, - ValidFrom : schema.ValidFrom, - ValidTill : schema.ValidTill, - IsValid : schema.IsValid, RootNode : rootNode ? { id : rootNode.id, Description : rootNode.Description, Name : rootNode.Name, Type : rootNode.Type, + Actions : rootNode.Actions, } : null, - CreatedAt : schema.CreatedAt, - UpdatedAt : schema.UpdatedAt, + ContextParams : schema.ContextParams, + CreatedAt : schema.CreatedAt, + UpdatedAt : schema.UpdatedAt, }; return dto; }; diff --git a/src/database/models/engine/schema.model.ts b/src/database/models/engine/schema.model.ts index 6edbe70..f22ad33 100644 --- a/src/database/models/engine/schema.model.ts +++ b/src/database/models/engine/schema.model.ts @@ -6,13 +6,11 @@ import { CreateDateColumn, UpdateDateColumn, DeleteDateColumn, - ManyToOne, OneToMany, - JoinColumn, } from 'typeorm'; -import { Client } from "../client/client.model"; import { Node } from "../engine/node.model"; import { SchemaType } from "../../../domain.types/engine/engine.enums"; +import { ContextParams } from "../../../domain.types/engine/intermediate.types"; //////////////////////////////////////////////////////////////////////// @@ -31,9 +29,8 @@ export class Schema { @Column({ type: 'enum', enum: SchemaType, nullable: false, default: SchemaType.ChatBot }) Type : SchemaType; - @ManyToOne(() => Client, { nullable: true, onDelete: 'CASCADE' }) - @JoinColumn() - Client : Client; + @Column({ type: 'uuid', nullable: false }) + TenantId : string; @Column({ type: 'uuid', nullable: true }) RootNodeId: string; @@ -43,14 +40,8 @@ export class Schema { }) Nodes: Node[]; - @Column({ type: 'date', nullable: true }) - ValidFrom : Date; - - @Column({ type: 'date', nullable: true }) - ValidTill : Date; - - @Column({ type: 'boolean', nullable: false, default: true }) - IsValid : boolean; + @Column({ type: 'simple-json', nullable: true }) + ContextParams : ContextParams; @CreateDateColumn() CreatedAt : Date; diff --git a/src/database/services/engine/common.utils.service.ts b/src/database/services/engine/common.utils.service.ts index 0116eb0..9d51e3d 100644 --- a/src/database/services/engine/common.utils.service.ts +++ b/src/database/services/engine/common.utils.service.ts @@ -33,8 +33,7 @@ export class CommonUtilsService { id : schemaId as string }, relations : { - Client : true, - Nodes : true, + Nodes : true, } }); if (!schema) { diff --git a/src/database/services/engine/schema.instance.service.ts b/src/database/services/engine/schema.instance.service.ts index b68cab4..9f98da9 100644 --- a/src/database/services/engine/schema.instance.service.ts +++ b/src/database/services/engine/schema.instance.service.ts @@ -82,8 +82,7 @@ export class SchemaInstanceService extends BaseService { }, relations : { Schema : { - Client : true, - Nodes : true, + Nodes : true, }, CurrentNodeInstance : { Node : true, @@ -171,8 +170,7 @@ export class SchemaInstanceService extends BaseService { var search : FindManyOptions = { relations : { Schema : { - Client : true, - Nodes : true, + Nodes : true, }, CurrentNodeInstance : { Node : true, @@ -192,10 +190,7 @@ export class SchemaInstanceService extends BaseService { id : true, Name : true, Description : true, - Client : { - id : true, - Name : true, - } + TenantId : true, }, RootNodeInstance : { id : true, diff --git a/src/database/services/engine/schema.service.ts b/src/database/services/engine/schema.service.ts index 3f531c6..24bba4a 100644 --- a/src/database/services/engine/schema.service.ts +++ b/src/database/services/engine/schema.service.ts @@ -18,7 +18,7 @@ import { Node } from '../../models/engine/node.model'; import { Condition } from '../../models/engine/condition.model'; import { CommonUtilsService } from './common.utils.service'; import { NodeAction } from '../../models/engine/node.action.model'; -import { NodeResponseDto } from '../../../domain.types/engine/node.types'; +import { StringUtils } from '../../../common/utilities/string.utils'; /////////////////////////////////////////////////////////////////////// @@ -45,12 +45,11 @@ export class SchemaService extends BaseService { public create = async (createModel: SchemaCreateModel) : Promise => { - const client = await this._commonUtils.getClient(createModel.ClientId); - - const rootNodeName = 'Root Node' + createModel.Name.substring(0, 25); - let rootNode: NodeResponseDto = null; + const rootNodeName = 'RootNode-' + createModel.Name.substring(0, 25); + let rootNode: Node = null; if (createModel.RootNode) { rootNode = this._nodeRepository.create({ + Code : StringUtils.generateDisplayCode_RandomChars(), ParentNode : null, Name : createModel.RootNode.Name, Type : createModel.RootNode.Type, @@ -64,21 +63,22 @@ export class SchemaService extends BaseService { Description : `Root node for ${createModel.Name}`, }); } + if (rootNode == null) { + ErrorHandler.throwInternalServerError('Unable to create Root Node!'); + } var rootNodeRecord = await this._nodeRepository.save(rootNode); - const schema = this._schemaRepository.create({ - Client : client, - Name : createModel.Name, - Description : createModel.Description, - Type : createModel.Type, - ValidFrom : createModel.ValidFrom, - ValidTill : createModel.ValidTill, - IsValid : createModel.IsValid ?? true, - RootNodeId : rootNodeRecord.id, + const schema = await this._schemaRepository.create({ + TenantId : createModel.TenantId, + Name : createModel.Name, + Description : createModel.Description, + Type : createModel.Type, + RootNodeId : rootNodeRecord.id, + ContextParams : createModel.ContextParams, }); var schemaRecord = await this._schemaRepository.save(schema); - rootNode.Schema = schemaRecord; + rootNodeRecord.Schema = schemaRecord; rootNodeRecord = await this._nodeRepository.save(rootNode); return SchemaMapper.toResponseDto(schemaRecord, rootNodeRecord); @@ -91,8 +91,7 @@ export class SchemaService extends BaseService { id : id }, relations : { - Client : true, - Nodes : true, + Nodes : true, } }); const rootNode = await this._commonUtils.getNode(schema.RootNodeId); @@ -139,10 +138,6 @@ export class SchemaService extends BaseService { //Schema code is not modifiable //Use renew key to update ApiKey, ValidFrom and ValidTill - if (model.ClientId != null) { - const client = await this._commonUtils.getClient(model.ClientId); - schema.Client = client; - } if (model.Name != null) { schema.Name = model.Name; } @@ -152,14 +147,8 @@ export class SchemaService extends BaseService { if (model.Type != null) { schema.Type = model.Type; } - if (model.ValidFrom != null) { - schema.ValidFrom = model.ValidFrom; - } - if (model.ValidTill != null) { - schema.ValidTill = model.ValidTill; - } - if (model.IsValid != null) { - schema.IsValid = model.IsValid; + if (model.ContextParams != null) { + schema.ContextParams = model.ContextParams; } const rootNode = await this._commonUtils.getNode(schema.RootNodeId); var record = await this._schemaRepository.save(schema); @@ -193,30 +182,18 @@ export class SchemaService extends BaseService { relations : { }, where : { - }, - select : { - id : true, - Client : { - id : true, - Name : true, - Code : true, - }, - Name : true, - Description : true, - ValidFrom : true, - ValidTill : true, - IsValid : true, - CreatedAt : true, - UpdatedAt : true, } }; - if (filters.ClientId) { - search.where['Client'].id = filters.ClientId; + if (filters.TenantId) { + search.where['TenantId'] = filters.TenantId; } if (filters.Name) { search.where['Name'] = Like(`%${filters.Name}%`); } + if (filters.Description) { + search.where['Description'] = Like(`%${filters.Description}%`); + } return search; }; diff --git a/src/domain.types/engine/schema.domain.types.ts b/src/domain.types/engine/schema.domain.types.ts index 419f7fc..b507d16 100644 --- a/src/domain.types/engine/schema.domain.types.ts +++ b/src/domain.types/engine/schema.domain.types.ts @@ -1,4 +1,3 @@ -import { EventType } from "../enums/event.type"; import { BaseSearchFilters, BaseSearchResults @@ -8,6 +7,7 @@ import { } from "../miscellaneous/system.types"; import { NodeType, SchemaType } from "./engine.enums"; import { ContextParams } from "./intermediate.types"; +import { NodeActionResponseDto } from "./node.action.types"; import { NodeCreateModel } from "./node.types"; ////////////////////////////////////////////////////////////// @@ -22,45 +22,34 @@ export interface SchemaCreateModel { } export interface SchemaUpdateModel { - ClientId? : uuid; Type? : SchemaType; Name? : string; Description? : string; - ValidFrom ?: Date; - ValidTill ?: Date; - IsValid ?: boolean; - EventTypeIds?: uuid[]; ContextParams?: ContextParams; } export interface SchemaResponseDto { - id : uuid; - Type : SchemaType; - Name : string; - Description: string; - ValidFrom : Date; - ValidTill : Date; - IsValid : boolean; - RootNode ?: { + id : uuid; + Type : SchemaType; + TenantId : uuid; + Name : string; + Description : string; + RootNode ?: { id : uuid, Name : string; Description: string; Type : NodeType; + Actions : NodeActionResponseDto[]; }; - Client : { - id : uuid; - Name: string; - Code: string; - }; - EventTypes ?: EventType[]; - IdentificationParams?: Map; - CreatedAt: Date; - UpdatedAt: Date; + ContextParams?: ContextParams; + CreatedAt : Date; + UpdatedAt : Date; } export interface SchemaSearchFilters extends BaseSearchFilters { - Name ? : string; - ClientId ? : uuid; + Name? : string; + Description? : string; + TenantId ? : uuid; } export interface SchemaSearchResults extends BaseSearchResults { diff --git a/src/domain.types/engine/schema.instance.types.ts b/src/domain.types/engine/schema.instance.types.ts index 764d469..0408368 100644 --- a/src/domain.types/engine/schema.instance.types.ts +++ b/src/domain.types/engine/schema.instance.types.ts @@ -1,4 +1,3 @@ -import { EventType } from "../enums/event.type"; import { BaseSearchFilters, BaseSearchResults @@ -6,6 +5,7 @@ import { import { uuid } from "../miscellaneous/system.types"; +import { ContextParams } from "./intermediate.types"; ////////////////////////////////////////////////////////////// @@ -25,12 +25,9 @@ export interface SchemaInstanceResponseDto { id : uuid; Name : string; Description: string; - Client : { - id : uuid; - Name: string; - }, - EventTypes : EventType[], + TenantId : uuid; }; + ContextParams ?: ContextParams; RootNodeInstance : { id: uuid; Node: {