Skip to content

Commit

Permalink
Added schema creation
Browse files Browse the repository at this point in the history
  • Loading branch information
kiran-rean committed Nov 26, 2024
1 parent 20c4aa6 commit eb6f9ab
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,51 @@ 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
}
]
},
"RootNode": {
"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."
}
]
}
}
}
]
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions bruno/Workflow service/environments/workflow-local.bru
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/api/engine/schema/schema.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
109 changes: 64 additions & 45 deletions src/api/engine/schema/schema.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

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

Expand All @@ -12,39 +12,57 @@ export class SchemaValidator extends BaseValidator {
public validateCreateRequest = async (request: express.Request): Promise<SchemaCreateModel> => {
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) {
Expand All @@ -55,24 +73,25 @@ export class SchemaValidator extends BaseValidator {
public validateUpdateRequest = async (request: express.Request): Promise<SchemaUpdateModel|undefined> => {
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);
Expand All @@ -82,7 +101,7 @@ export class SchemaValidator extends BaseValidator {
public validateSearchRequest = async (request: express.Request): Promise<SchemaSearchFilters> => {
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);
Expand All @@ -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;
Expand Down
18 changes: 10 additions & 8 deletions src/auth/auth.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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<boolean> => {

Expand Down
2 changes: 1 addition & 1 deletion src/auth/wrappers/client.authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ export class ClientAuthenticator {
public verify = async (request: express.Request): Promise<boolean> => {
const authResult = await this._authenticator.authenticate(request);
return authResult.Result;
}
};

}
2 changes: 1 addition & 1 deletion src/auth/wrappers/user.authorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ export class UserAuthorizer {
public verify = async (request: express.Request): Promise<boolean> => {
const authorized = await this._authorizer.authorize(request, null);
return authorized;
}
};

}
8 changes: 4 additions & 4 deletions src/common/utilities/string.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions src/database/mappers/engine/schema.instance.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down
19 changes: 7 additions & 12 deletions src/database/mappers/engine/schema.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Loading

0 comments on commit eb6f9ab

Please # to comment.