This commit is contained in:
Simon Larsen 2022-09-12 20:21:56 +01:00
parent 23e8b67532
commit 3451583e3a
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
5 changed files with 40 additions and 2 deletions

View File

@ -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<BaseModel>, tableColumnMetadata.modelType);
} else {
(json as any)[key] = json[key];
(json as any)[key] = (model as any)[key];
}
}
}

View File

@ -189,6 +189,7 @@ export default class BaseAPI<
req: ExpressRequest,
res: ExpressResponse
): Promise<void> {
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);
}

View File

@ -21,6 +21,7 @@ export class Service extends DatabaseService<Model> {
}
protected override async onBeforeUpdate(updateBy: UpdateBy<Model>): Promise<OnUpdate<Model>> {
debugger;
if (updateBy.data.isVerified && updateBy.data._id && !updateBy.props.isRoot) {
// check the verification of the domain.

View File

@ -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 = <TBaseModel extends BaseModel>(
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<any>).length > 0 && typeof ((valuesToSend[key] as Array<any>)[0]) === Typeof.String) {
const arr: Array<BaseModel> = [];
for (const id of valuesToSend[key] as Array<string>) {
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 extends BaseModel>(
tBaseModel = await props.onBeforeCreate(tBaseModel);
}
result = await ModelAPI.createOrUpdate<TBaseModel>(
tBaseModel,
props.modelType,

View File

@ -208,6 +208,15 @@ const IncidentsPage: FunctionComponent<PageComponentProps> = (
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 => {