Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 2328be5

Browse files
mathieugeisslerwardbell
authored andcommitted
Bugfix : correct behavior when id===0 in delete and get (#95)
Delete: ok to delete when id equals 0; return an error when id is null or undefined. Get: when id is 0, should try to retrieve record with id==0. Only get all when id is null or undefined.
1 parent 06b708b commit 2328be5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/in-memory-backend.service.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,9 @@ export class InMemoryBackendService {
490490
return createObservableResponse(reqInfo.req, resOptions);
491491
}
492492

493-
protected delete({ id, collection, collectionName, headers, req }: RequestInfo) {
494-
if (!id) {
493+
protected delete({id, collection, collectionName, headers, req}: RequestInfo) {
494+
// tslint:disable-next-line:triple-equals
495+
if (id == undefined) {
495496
return createErrorResponse(req, STATUS.NOT_FOUND, `Missing "${collectionName}" id`);
496497
}
497498
const exists = this.removeById(collection, id);
@@ -517,10 +518,11 @@ export class InMemoryBackendService {
517518
protected get({ id, query, collection, collectionName, headers, req }: RequestInfo) {
518519
let data = collection;
519520

520-
if (id) {
521-
data = this.findById(collection, id);
522-
} else if (query) {
521+
// tslint:disable-next-line:triple-equals
522+
if (id == undefined) {
523523
data = this.applyQuery(collection, query);
524+
} else if (query) {
525+
data = this.findById(collection, id);
524526
}
525527

526528
if (!data) {

0 commit comments

Comments
 (0)