diff --git a/.vscode/.settings.json b/.vscode/.settings.json new file mode 100644 index 0000000..6c62a95 --- /dev/null +++ b/.vscode/.settings.json @@ -0,0 +1,9 @@ +{ + "editor.defaultFormatter": "rvest.vs-code-prettier-eslint", + "editor.formatOnType": false, + "editor.formatOnPaste": true, + "editor.formatOnSave": true, + "editor.formatOnSaveMode": "file", + "files.autoSave": "onFocusChange", + "vs-code-prettier-eslint.prettierLast": false +} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..7bb4c6f --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "rvest.vs-code-prettier-eslint" + ] +} \ No newline at end of file diff --git a/__tests__/unittest/date.test.js b/__tests__/unittest/date.test.js index 5494802..9c326a8 100644 --- a/__tests__/unittest/date.test.js +++ b/__tests__/unittest/date.test.js @@ -8,11 +8,6 @@ describe('date', () => { expect(lastUpdate).toMatch(RFC3339_REGEX); }); - it('tests getRFC3339Date without offset', () => { - const lastUpdate = getRFC3339Date(false); - expect(lastUpdate).toMatch(RFC3339_REGEX); - }); - it('test regex correctly', () => { let lastUpdate = "1985-04-12T23:20:50.52Z"; expect(lastUpdate).toMatch(RFC3339_REGEX); diff --git a/lib/date.js b/lib/date.js index a8e21c8..bc2874a 100644 --- a/lib/date.js +++ b/lib/date.js @@ -1,4 +1,4 @@ -function getRFC3339Date(includeOffset = true) { +function getRFC3339Date() { const now = new Date(); const year = now.getUTCFullYear(); const month = String(now.getUTCMonth() + 1).padStart(2, '0'); @@ -6,15 +6,10 @@ function getRFC3339Date(includeOffset = true) { const hours = String(now.getUTCHours()).padStart(2, '0'); const minutes = String(now.getUTCMinutes()).padStart(2, '0'); const seconds = String(now.getUTCSeconds()).padStart(2, '0'); - - if (includeOffset) { - const offsetHours = '01'; - const offsetMinutes = '00'; - const offsetSign = '+'; - return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}${offsetSign}${offsetHours}:${offsetMinutes}`; - } else { - return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}Z`; - } + const offsetHours = '01'; + const offsetMinutes = '00'; + const offsetSign = '+'; + return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}${offsetSign}${offsetHours}:${offsetMinutes}`; } module.exports = { diff --git a/lib/extendOrdWithCustom.js b/lib/extendOrdWithCustom.js index 3d07528..25677f8 100644 --- a/lib/extendOrdWithCustom.js +++ b/lib/extendOrdWithCustom.js @@ -50,7 +50,7 @@ function compareAndHandleCustomORDContentWithExistingContent(ordContent, customO function getCustomORDContent(appConfig) { if (!appConfig.env?.customOrdContentFile) return; const pathToCustomORDContent = path.join(cds.root, appConfig.env?.customOrdContentFile); - if (fs.existsSync(pathToCustomORDContent)) { + if (fs.existsSync(pathToCustomORDContent)) { Logger.error('Custom ORD content file not found at', pathToCustomORDContent); return require(pathToCustomORDContent); } diff --git a/lib/index.js b/lib/index.js index a0b6e5e..9f082de 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,5 @@ module.exports = { - ord: require("./ord.js"), - getMetadata: require("./metaData.js"), - defaults: require("./defaults.js"), + ord: require("./ord.js"), + getMetadata: require("./metaData.js"), + defaults: require("./defaults.js"), }; diff --git a/lib/plugin.js b/lib/plugin.js index b2028e4..e279c78 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -4,30 +4,30 @@ const { ord, getMetadata, defaults } = require("./"); cds.on("bootstrap", (app) => { - app.use("/.well-known/open-resource-discovery", async (req, res) => { - if (req.url === "/") { - res.status(200).send(defaults.baseTemplate); - } else { - try { - const { contentType, response } = await getMetadata(req.url); - res.status(200).contentType(contentType).send(response); - } catch (error) { - Logger.error(error, 'Error while generating metadata'); - res.status(500).send(error.message); - } - } - }); + app.use("/.well-known/open-resource-discovery", async (req, res) => { + if (req.url === "/") { + res.status(200).send(defaults.baseTemplate); + } else { + try { + const { contentType, response } = await getMetadata(req.url); + res.status(200).contentType(contentType).send(response); + } catch (error) { + Logger.error(error, 'Error while generating metadata'); + res.status(500).send(error.message); + } + } + }); - app.get("/open-resource-discovery/v1/documents/1", async (req, res) => { - try { - const csn = await cds.load(cds.env.folders.srv); - const data = ord(csn); - return res.status(200).send(data); - } catch (error) { - Logger.error(error, 'Error while creating ORD document'); - return res.status(500).send(error.message); - } - }); + app.get("/open-resource-discovery/v1/documents/1", async (req, res) => { + try { + const csn = await cds.load(cds.env.folders.srv); + const data = ord(csn); + return res.status(200).send(data); + } catch (error) { + Logger.error(error, 'Error while creating ORD document'); + return res.status(500).send(error.message); + } + }); }); module.exports = cds.server;