From 3451583e3a0fcdbe76eebc080417308d6e5e58ea Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Mon, 12 Sep 2022 20:21:56 +0100 Subject: [PATCH] fix bugs --- Common/Models/BaseModel.ts | 5 +++-- CommonServer/API/BaseAPI.ts | 2 ++ CommonServer/Services/DomainService.ts | 1 + CommonUI/src/Components/Forms/ModelForm.tsx | 25 +++++++++++++++++++++ Dashboard/src/Pages/Incidents/Incidents.tsx | 9 ++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Common/Models/BaseModel.ts b/Common/Models/BaseModel.ts index 6d0c5758ff..5db8313cb1 100644 --- a/Common/Models/BaseModel.ts +++ b/Common/Models/BaseModel.ts @@ -402,7 +402,8 @@ export default class BaseModel extends BaseEntity { } - public static toJSONObject(model: BaseModel, modelType: { new (): BaseModel }): JSONObject { + public static toJSONObject(model: BaseModel, modelType: { new(): BaseModel }): JSONObject { + const json: JSONObject = {}; const vanillaModel = new modelType(); @@ -423,7 +424,7 @@ export default class BaseModel extends BaseEntity { } else if ((model as any)[key] && Array.isArray((model as any)[key]) && (model as any)[key].length > 0 && tableColumnMetadata.modelType && tableColumnMetadata.type === TableColumnType.EntityArray) { (json as any)[key] = BaseModel.toJSONObjectArray((model as any)[key] as Array, tableColumnMetadata.modelType); } else { - (json as any)[key] = json[key]; + (json as any)[key] = (model as any)[key]; } } } diff --git a/CommonServer/API/BaseAPI.ts b/CommonServer/API/BaseAPI.ts index 0ee6f943e6..c76b95f28d 100644 --- a/CommonServer/API/BaseAPI.ts +++ b/CommonServer/API/BaseAPI.ts @@ -189,6 +189,7 @@ export default class BaseAPI< req: ExpressRequest, res: ExpressResponse ): Promise { + const skip: PositiveNumber = req.query['skip'] ? new PositiveNumber(req.query['skip'] as string) : new PositiveNumber(0); @@ -246,6 +247,7 @@ export default class BaseAPI< props: databaseProps, }); + debugger; return Response.sendListResponse(req, res, list, count, this.entityType); } diff --git a/CommonServer/Services/DomainService.ts b/CommonServer/Services/DomainService.ts index da5c0a9099..e47646eca2 100644 --- a/CommonServer/Services/DomainService.ts +++ b/CommonServer/Services/DomainService.ts @@ -21,6 +21,7 @@ export class Service extends DatabaseService { } protected override async onBeforeUpdate(updateBy: UpdateBy): Promise> { + debugger; if (updateBy.data.isVerified && updateBy.data._id && !updateBy.props.isRoot) { // check the verification of the domain. diff --git a/CommonUI/src/Components/Forms/ModelForm.tsx b/CommonUI/src/Components/Forms/ModelForm.tsx index f44289d7ae..7169eda395 100644 --- a/CommonUI/src/Components/Forms/ModelForm.tsx +++ b/CommonUI/src/Components/Forms/ModelForm.tsx @@ -33,6 +33,8 @@ import BadDataException from 'Common/Types/Exception/BadDataException'; import { LIMIT_PER_PROJECT } from 'Common/Types/Database/LimitMax'; import Populate from '../../Utils/ModelAPI/Populate'; import FileModel from 'Common/Models/FileModel'; +import TableColumnType from 'Common/Types/Database/TableColumnType'; +import Typeof from 'Common/Types/Typeof'; export enum FormType { Create, @@ -376,6 +378,28 @@ const ModelForm: Function = ( delete valuesToSend[key]; } + + for (const key of model.getTableColumns().columns) { + const tableColumnMetadata = model.getTableColumnMetadata(key); + + if (tableColumnMetadata && tableColumnMetadata.modelType && tableColumnMetadata.type === TableColumnType.Entity && valuesToSend[key] && typeof valuesToSend[key] === Typeof.String) { + let baseModel = new tableColumnMetadata.modelType(); + baseModel._id = valuesToSend[key] as string; + valuesToSend[key] = baseModel; + + } + + if (tableColumnMetadata && tableColumnMetadata.modelType && tableColumnMetadata.type === TableColumnType.EntityArray && Array.isArray(valuesToSend[key]) && (valuesToSend[key] as Array).length > 0 && typeof ((valuesToSend[key] as Array)[0]) === Typeof.String) { + const arr: Array = []; + for (const id of valuesToSend[key] as Array) { + let baseModel = new tableColumnMetadata.modelType(); + baseModel._id = id as string; + arr.push(baseModel); + } + valuesToSend[key] = arr; + } + } + let tBaseModel: TBaseModel = model.fromJSON( valuesToSend, props.modelType @@ -385,6 +409,7 @@ const ModelForm: Function = ( tBaseModel = await props.onBeforeCreate(tBaseModel); } + result = await ModelAPI.createOrUpdate( tBaseModel, props.modelType, diff --git a/Dashboard/src/Pages/Incidents/Incidents.tsx b/Dashboard/src/Pages/Incidents/Incidents.tsx index 697ef9ddf1..a6555fcd9c 100644 --- a/Dashboard/src/Pages/Incidents/Incidents.tsx +++ b/Dashboard/src/Pages/Incidents/Incidents.tsx @@ -208,6 +208,15 @@ const IncidentsPage: FunctionComponent = ( color: true, }, }, + isFilterable: true, + filterEntityType: IncidentSeverity, + filterQuery: { + projectId: props.currentProject?._id, + }, + filterDropdownField: { + label: 'name', + value: '_id', + }, title: 'Incident Severity', type: FieldType.Entity, getElement: (item: JSONObject): ReactElement => {