SAP Community Call

This commit is contained in:
sjvans
2022-02-24 08:30:26 +01:00
parent b13ed5cc8d
commit d53d4de105
8 changed files with 62 additions and 2763 deletions

View File

@@ -1,5 +0,0 @@
using {sap.capire.graphql} from '../db/schema';
extend service AdminService with {
entity Chapters as projection on graphql.Chapters;
}

View File

@@ -0,0 +1,11 @@
using {
sap.capire.bookshop,
sap.capire.graphql
} from '../db/schema';
service BookshopService {
entity Books as projection on bookshop.Books;
entity Authors as projection on bookshop.Authors;
entity Chapters as projection on graphql.Chapters;
entity Orders as projection on graphql.Orders;
}

View File

@@ -0,0 +1,11 @@
module.exports = function() {
const { Orders, Books } = this.entities
this.before('CREATE', Orders, async function(req) {
const { book_ID, quantity } = req.data
// reduce the stock, if enough are available, else reject the order
const applied = await UPDATE(Books, book_ID).set({ stock: { '-=': quantity } }).where({ stock: { '>=': quantity }})
if (!applied) req.reject(400, `Sorry, ${quantity} are not in stock`)
})
}