Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/cap-js/ORD into fix/69-add-…
Browse files Browse the repository at this point in the history
…missing-top-level-property-entitytypes
  • Loading branch information
aramovic79 committed Dec 9, 2024
2 parents d01f752 + 341a514 commit 0135366
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 42 deletions.
9 changes: 9 additions & 0 deletions .vscode/.settings.json
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"rvest.vs-code-prettier-eslint"
]
}
5 changes: 0 additions & 5 deletions __tests__/unittest/date.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 5 additions & 10 deletions lib/date.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
function getRFC3339Date(includeOffset = true) {
function getRFC3339Date() {
const now = new Date();
const year = now.getUTCFullYear();
const month = String(now.getUTCMonth() + 1).padStart(2, '0');
const day = String(now.getUTCDate()).padStart(2, '0');
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 = {
Expand Down
2 changes: 1 addition & 1 deletion lib/extendOrdWithCustom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -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"),
};
46 changes: 23 additions & 23 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 0135366

Please sign in to comment.