First push

This commit is contained in:
nkaputnik
2022-07-26 09:47:56 +02:00
parent 9617e576f0
commit 9c2a7598f2
16 changed files with 414 additions and 10438 deletions

View File

@@ -1,13 +1,16 @@
async function run() {
//debugger
//while (true) {}
//process.exit()
//1.substring()
let res = await cds.read(SELECT.one`title`.from(`Books`).where(`ID=201`))
// let res = await specialselect
let res = await SELECT.one`title`.from(`Books`).where(`ID=201`)
let { title } = res
const data = req.data
data.modifiedBy = "Custom Event handler read changed this!"
data.placeOfDeath = " --- Somewhere over " + title + " --- create in Sandbox"
return data
let Author = req.data
Author.modifiedBy = "Custom Event handler changed this!"
Author.placeOfDeath = " --- Somewhere over " + title + " --- create in Sandbox"
//await this.emit("createdAuthor", { Author })
return Author
}
output = run()
run()

View File

@@ -1,5 +1,28 @@
function getYear(v) {
return parseInt(v.substr(0, 4))
}
function getMonth(v) {
return parseInt(v.substr(5, 2))
}
function getDay(v) {
return parseInt(v.substr(8, 2))
}
function getAge(from, to) {
if (from === undefined || from == null) return 0
if (to === undefined || to == null) to = new Date().toISOString()
let year = getYear(to) - getYear(from) - 1
if (
getMonth(to) > getMonth(from) ||
(getMonth(to) === getMonth(from) && getDay(to) >= getDay(from))
) {
year++
}
return year
}
const result_ = Array.isArray(result) ? result : [result]
for (const row of result_) {
row.modifiedBy += " --- read in sandbox"
row.age = 27
row.age = getAge(row.dateOfBirth, row.dateOfDeath)
}

View File

@@ -0,0 +1,9 @@
async function run() {
const {author, newName} = req.data
let a = await SELECT `name`.from(`Authors`).where({ID: author})
if(!a) return req.error (404, `Can't rename a non-existing author`)
await UPDATE (`Authors`,author).with ({ name: newName })
//await this.emit ('renamedAuthor', { author, newName })
output.msg = 'Success'
}
run()

View File

@@ -0,0 +1,5 @@
async function run() {
let {Author} = req.data
Author.placeOfBirth += ' --- modified in custom event'
}
run()