Using ES Modules

This commit is contained in:
Daniel Hutzel
2024-07-16 15:29:45 +02:00
parent 7a2e345cd5
commit cba8e0cc5c
12 changed files with 25 additions and 37 deletions

View File

@@ -1,4 +1,4 @@
const cds = require('@sap/cds')
import cds from '@sap/cds'
/**
* In order to keep basic bookshop sample as simple as possible, we don't add
@@ -8,7 +8,7 @@ const cds = require('@sap/cds')
// 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', ()=>
export default cds.on('served', ()=>
UPSERT.into ('sap.common.Currencies') .columns (
[ 'code', 'symbol', 'name' ]
) .rows (

View File

@@ -2,6 +2,7 @@
"name": "@capire/bookshop",
"version": "1.0.0",
"description": "A simple self-contained bookshop service.",
"type": "module",
"files": [
"app",
"srv",

View File

@@ -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()

View File

@@ -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
@@ -34,5 +34,3 @@ class CatalogService extends cds.ApplicationService { init() {
// Delegate requests to the underlying generic service
return super.init()
}}
module.exports = CatalogService

View File

@@ -1,5 +1,5 @@
const cds = require('@sap/cds')
module.exports = class UserService extends cds.Service { init(){
import cds from '@sap/cds'
export class UserService extends cds.Service { init(){
this.on('READ', 'me', ({ tenant, user, locale }) => ({ id: user.id, locale, tenant }))
this.on('login', (req) => {
if (req.user._is_anonymous)