Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ Use cases for tracing changes

#### Use Case 1: Trace the changes of child nodes from the current entity and display the meaningful data from child nodes (composition relation)

> [!WARNING]
> When you don't need to track the deep changes, but still want to track the additions and removals in the composition, you can set it up as described below. At this point, updates to child entity will not generate a changelog.

Modelling in `db/schema.cds`

```cds
Expand Down
5 changes: 1 addition & 4 deletions lib/change-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,11 @@ const _formatCompositionValue = function (
childNodeChange,
childNodeChanges
) {
if (curChange.modification === undefined) {
if (curChange.modification === undefined || curChange.modification === "update") {
return
} else if (curChange.modification === "delete") {
curChange.valueChangedFrom = objId
curChange.valueChangedTo = ""
} else if (curChange.modification === "update") {
curChange.valueChangedFrom = objId
curChange.valueChangedTo = objId
} else {
curChange.valueChangedFrom = ""
curChange.valueChangedTo = objId
Expand Down
42 changes: 0 additions & 42 deletions tests/integration/fiori-draft-enabled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,22 +291,6 @@ describe("change log integration test", () => {
price: 3000
});
await utils.apiAction("admin", "BookStores", "64625905-c234-4d0d-9bc1-283ee8946770", "AdminService", action);
const bookChanges = await adminService.run(
SELECT.from(ChangeView).where({
entity: "sap.capire.bookshop.BookStores",
attribute: "books",
})
);
expect(bookChanges.length).to.equal(1);

const bookChange = bookChanges[0];
expect(bookChange.entityKey).to.equal("64625905-c234-4d0d-9bc1-283ee8946770");
expect(bookChange.attribute).to.equal("Books");
expect(bookChange.modification).to.equal("Update");
expect(bookChange.objectID).to.equal("Shakespeare and Company");
expect(bookChange.entity).to.equal("Book Store");
expect(bookChange.valueChangedFrom).to.equal("new title");
expect(bookChange.valueChangedTo).to.equal("new title");

const titleChanges = await adminService.run(
SELECT.from(ChangeView).where({
Expand Down Expand Up @@ -843,32 +827,6 @@ describe("change log integration test", () => {
expect(bookChangesInDb.valueChangedTo).to.equal("test title, 2, 2.3");
expect(bookChangesInDb.valueDataType).to.equal("cds.String, cds.Integer, cds.Decimal");

// adjust sequence
cds.services.AdminService.entities.BookStores.elements.books["@changelog"] = [
{ "=": "books.stock" },
{ "=": "books.title" },
{ "=": "books.price" },
];

const actionPH = PATCH.bind({}, `/odata/v4/admin/Books(ID=9d703c23-54a8-4eff-81c1-cdce6b8376b2,IsActiveEntity=false)`, {
stock: 3,
});
await utils.apiAction("admin", "BookStores", "64625905-c234-4d0d-9bc1-283ee8946770", "AdminService", actionPH);

// valueDataType field only appears in db table Changes
// there are no localization features for table Changes
const booksUpdateChangesInDb = await SELECT.from(ChangeEntity).where({
entity: "sap.capire.bookshop.BookStores",
attribute: "books",
modification: "update",
});
expect(booksUpdateChangesInDb.length).to.equal(1);

const bookUpdateChangesInDb = booksUpdateChangesInDb[0];
expect(bookUpdateChangesInDb.valueChangedFrom).to.equal("3, test title, 2.3");
expect(bookUpdateChangesInDb.valueChangedTo).to.equal("3, test title, 2.3");
expect(bookUpdateChangesInDb.valueDataType).to.equal("cds.Integer, cds.String, cds.Decimal");

// recover @changelog context on composition books
cds.services.AdminService.entities.BookStores.elements.books["@changelog"] = originalChangelog;
});
Expand Down