I have an object model that has an array as one of its values. I'm trying to populate it but I get an error in my VS Code environment:
Type 'Promise
' is missing the following properties from type 'GenericViewModel': rating, reportingDate, comments, and 4 more.ts(2740)
I have searched and can't determine how to populate the property correctly. Everything I have seen online says that this is the correct way. I am using Visual Studio Code and building an Angular application.
My function and model are as follows:
async getRawData(){
let pList: PViewModel[] = [];
let criteria = {storedProcedure: 'sp_Get_Data_For_ESM'};
await super.post(
'universal-sp-pass-thru/spPassThroughnoBody',
criteria,
'api-eprs'
); //this runs the sql
pList = this.apiPostResponse.data;
const scorecardData: ScorecardModel = {pcorecardModel: []};
// Process each
pList.forEach((p) => {
const pData: PScorecardModel = {
pId: p.pId,
OpenViewModel: [],
};
// Populate the specific view model list (example for ENG_STAFFING_3_LA)
// Replace `new Date()` with the actual reporting date if it is available.
pData.OpenViewModel[] = this.getGenericData(p.pId, p.reportingDate,p.OpenViewModel_ST,p.OpenViewModel_TABLE)
// Append the populated program data to the scorecard
scorecardData.pScorecardModel.push(pData);
});
async getGenericData(pId:string,reportingDate:Date | null, ised:string, tablename:string): Promise {
let GenericViewModel: GenericViewModel[] = [];
let body = {
pId: pId,
reportingDate:reportingDate,
ised: ised,
tablename: tablename,
};
let criteria = {
storedProcedure: 'sp_GetScorecard',
body: body,
};
await super.post(
'sword-universal-sp-pass-thru/spPassThrough',
criteria,
'api-eprs'
); //this runs the sql
GenericViewModel = this.apiPostResponse.data; /
return GenericViewModel;
}
/** Generic view‑model used in many collections */
export interface GenericViewModel {
rating: string;
reportingDate: Date | null;
comments: string;
results: string;
rtg_date: string;
phase: string;
denominator: number;
}
export interface ProgramScorecardModel {
pId: string;
OpenViewModel: GenericViewModel[];
}
I get the error on this line:
pData.OpenViewModel[] = this.getGenericData(p.pId, p.reportingDate,p.OpenViewModel_ST,p.OpenViewModel_TABLE)
How do I properly populate the pData.OpenViewModel[]?