Added reviews/test/bookshop
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using { sap.capire.reviews as my } from '../db/schema';
|
||||
namespace sap.capire.reviews;
|
||||
|
||||
service ReviewsService {
|
||||
// Sync API
|
||||
|
||||
@@ -5,9 +5,9 @@ module.exports = cds.service.impl (function(){
|
||||
// ( Note: we explicitly specify the namespace to support embedded reuse )
|
||||
const { Reviews, Likes } = this.entities ('sap.capire.reviews')
|
||||
|
||||
// this.before (['CREATE','UPDATE'], 'Reviews', req => {
|
||||
// if (!req.data.rating) req.data.rating = Math.round(Math.random()*4)+1
|
||||
// })
|
||||
this.before (['CREATE','UPDATE'], 'Reviews', req => {
|
||||
if (!req.data.rating) req.data.rating = Math.round(Math.random()*4)+1
|
||||
})
|
||||
|
||||
// Emit an event to inform subscribers about new avg ratings for reviewed subjects
|
||||
// ( Note: req.on.succeeded ensures we only do that if there's no error )
|
||||
@@ -17,7 +17,7 @@ module.exports = cds.service.impl (function(){
|
||||
SELECT.one (['round(avg(rating),2) as rating']) .from (Reviews) .where ({subject})
|
||||
)
|
||||
req.on ('succeeded', ()=>{
|
||||
console.log ('< emitting:', 'reviewed', { subject, rating })
|
||||
global.it || console.log ('< emitting:', 'reviewed', { subject, rating })
|
||||
this.emit ('reviewed', { subject, rating })
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user