EntityAction guard error while using add in ngrx data

365 Views Asked by At

dears, I get this error when trying to add() ngrx-data.mjs:4531 Error: test EntityAction guard for "[test] @ngrx/data/save/add-one/success": payload should have a single entity.

here's the "test" interface / entity config

export interface test {num: number; name: string, _id?: string, __v?: number}
 
getTestId(st: test): number {return st.num}

const entityMetadata: EntityMetadataMap = {Test: {entityName: 'test',selectId: getTestId}}

nothing special about the service too:

@Injectable({ providedIn: 'root' })export class testService extends EntityCollectionServiceBase {constructor(serviceElementsFactory: EntityCollectionServiceElementsFactory) {super('test', serviceElementsFactory);}}

here's the add code: const dtt = JSON.parse(JSON.stringify(this.testt)) this.testServ.add(dtt)

here's the package.json
"dependencies": { "@angular/animations": "~13.0.0", "@angular/cdk": "^12.2.13", "@angular/common": "~13.0.0", "@angular/compiler": "~13.0.0", "@angular/core": "~13.0.0", "@angular/flex-layout": "^12.0.0-beta.35", "@angular/forms": "~13.0.0", "@angular/material": "^12.2.13", "@angular/platform-browser": "~13.0.0", "@angular/platform-browser-dynamic": "~13.0.0", "@angular/router": "~13.0.0", "@ngrx/data": "^13.0.2", "@ngrx/effects": "^13.0.2", "@ngrx/entity": "^13.0.2", "@ngrx/store": "^13.0.2", "@ngrx/store-devtools": "^13.0.2", "angular-google-charts": "^2.2.2", "rxjs": "~7.4.0", "tslib": "^2.3.0", "zone.js": "~0.11.4" }, "devDependencies": { "@angular-devkit/build-angular": "~13.0.1", "@angular/cli": "~13.0.1", "@angular/compiler-cli": "~13.0.0", "@types/jasmine": "~3.10.0", "@types/node": "^12.11.1", "jasmine-core": "~3.10.0", "karma": "~6.3.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.0.3", "karma-jasmine": "~4.0.0", "karma-jasmine-html-reporter": "~1.7.0", "typescript": "~4.4.3" }

about to try using fake backend instead of the real node/mongoose

1

There are 1 best solutions below

1
On

turns out to be a silly issue: backend was not returning the added entity I was just adding it to the DB