From 540fd5944fbc8dd35602d568db84c4b406791540 Mon Sep 17 00:00:00 2001 From: Daniel Hutzel Date: Tue, 3 Mar 2026 13:18:57 +0100 Subject: [PATCH 1/2] Use ESM --- db/data/sap.common-Currencies.csv | 7 +++++++ db/init.js | 21 --------------------- package.json | 1 + srv/admin-service.js | 4 ++-- srv/cat-service.js | 6 ++---- 5 files changed, 12 insertions(+), 27 deletions(-) create mode 100644 db/data/sap.common-Currencies.csv delete mode 100644 db/init.js diff --git a/db/data/sap.common-Currencies.csv b/db/data/sap.common-Currencies.csv new file mode 100644 index 0000000..2e01ae9 --- /dev/null +++ b/db/data/sap.common-Currencies.csv @@ -0,0 +1,7 @@ +code;symbol;name +EUR;€;Euro +USD;$;US Dollar +GBP;£;British Pound +ILS;₪;Shekel +JPY;¥;Yen +CNY;¥;Yuan \ No newline at end of file diff --git a/db/init.js b/db/init.js deleted file mode 100644 index 77a50c0..0000000 --- a/db/init.js +++ /dev/null @@ -1,21 +0,0 @@ -const cds = require('@sap/cds') - -/** - * In order to keep basic bookshop sample as simple as possible, we don't add - * reuse dependencies. This db/init.js ensures we still have a minimum set of - * currencies, if not obtained through @capire/common. - */ - -// NOTE: We use cds.on('served') to delay the UPSERTs after the db init -// to run after all INSERTs from .csv files happened. -module.exports = cds.on('served', ()=> - UPSERT.into ('sap.common.Currencies') .columns ( - [ 'code', 'symbol', 'name' ] - ) .rows ( - [ 'EUR', '€', 'Euro' ], - [ 'USD', '$', 'US Dollar' ], - [ 'GBP', '£', 'British Pound' ], - [ 'ILS', '₪', 'Shekel' ], - [ 'JPY', '¥', 'Yen' ], - ) -) diff --git a/package.json b/package.json index 20395ed..7619179 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.1.9", "description": "Our primer sample for getting started in a nutshell.", "repository": "https://github.com/capire/bookshop", + "type": "module", "files": [ "app", "srv", diff --git a/srv/admin-service.js b/srv/admin-service.js index f3e910f..4508c75 100644 --- a/srv/admin-service.js +++ b/srv/admin-service.js @@ -1,6 +1,6 @@ -const cds = require('@sap/cds') +import cds from '@sap/cds' -module.exports = class AdminService extends cds.ApplicationService { init(){ +export class AdminService extends cds.ApplicationService { init(){ this.before (['NEW','CREATE'],'Authors', genid) this.before (['NEW','CREATE'],'Books', genid) return super.init() diff --git a/srv/cat-service.js b/srv/cat-service.js index 1598f05..26595a4 100644 --- a/srv/cat-service.js +++ b/srv/cat-service.js @@ -1,6 +1,6 @@ -const cds = require('@sap/cds') +import cds from '@sap/cds' -class CatalogService extends cds.ApplicationService { init() { +export class CatalogService extends cds.ApplicationService { init() { const { Books } = cds.entities ('sap.capire.bookshop') const { ListOfBooks } = this.entities @@ -25,5 +25,3 @@ class CatalogService extends cds.ApplicationService { init() { // Delegate requests to the underlying generic service return super.init() }} - -module.exports = CatalogService From 7c5155a3c9317934b9b3e60facd6edc88d964824 Mon Sep 17 00:00:00 2001 From: Daniel Hutzel Date: Tue, 2 Jun 2026 09:18:39 +0200 Subject: [PATCH 2/2] Reverting dependencies on deploy via UPSERTS --- db/data/sap.common-Currencies.csv | 7 ------- db/init.js | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) delete mode 100644 db/data/sap.common-Currencies.csv create mode 100644 db/init.js diff --git a/db/data/sap.common-Currencies.csv b/db/data/sap.common-Currencies.csv deleted file mode 100644 index 2e01ae9..0000000 --- a/db/data/sap.common-Currencies.csv +++ /dev/null @@ -1,7 +0,0 @@ -code;symbol;name -EUR;€;Euro -USD;$;US Dollar -GBP;£;British Pound -ILS;₪;Shekel -JPY;¥;Yen -CNY;¥;Yuan \ No newline at end of file diff --git a/db/init.js b/db/init.js new file mode 100644 index 0000000..9a59dd4 --- /dev/null +++ b/db/init.js @@ -0,0 +1,21 @@ +import cds from '@sap/cds' + +/** + * In order to keep basic bookshop sample as simple as possible, we don't add + * reuse dependencies. This db/init.js ensures we still have a minimum set of + * currencies, if not obtained through @capire/common. + */ + +// NOTE: We use cds.on('served') to delay the UPSERTs after the db init +// to run after all INSERTs from .csv files happened. +cds.on('served', ()=> + UPSERT.into ('sap.common.Currencies') .columns ( + [ 'code', 'symbol', 'name' ] + ) .rows ( + [ 'EUR', '€', 'Euro' ], + [ 'USD', '$', 'US Dollar' ], + [ 'GBP', '£', 'British Pound' ], + [ 'ILS', '₪', 'Shekel' ], + [ 'JPY', '¥', 'Yen' ], + ) +)