Skip to content

Commit 3d16bf7

Browse files
committed
fix(json-api-nestjs-sdk): add id field in atomic body for add operation with tmpId
if set Id should be use as id and tmpId.
1 parent 6d166ba commit 3d16bf7

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

libs/json-api/json-api-nestjs-sdk/src/lib/utils/generate-atomic-body.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('GenerateAtomicBody', () => {
9999

100100
const expectedBodyData = {
101101
op: Operation.add,
102-
ref: { type: 'book-list', tmpId: entity.id },
102+
ref: { type: 'book-list', tmpId: entity.id, id: 'tmpId' },
103103
data: {
104104
attributes: {
105105
text: entity.text,

libs/json-api/json-api-nestjs-sdk/src/lib/utils/generate-atomic-body.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ export class GenerateAtomicBody<
4646
const rel = relationType ? { relationship: String(relationType) } : {};
4747
const tmpId =
4848
op === 'add' && id && !relationType ? { tmpId: String(id) } : {};
49+
if (op === 'add' && id && !relationType) {
50+
idObj['id'] = String(id);
51+
}
4952
this.bodyData = {
5053
op,
5154
ref: { type, ...idObj, ...rel, ...tmpId },

0 commit comments

Comments
 (0)