prettier
This commit is contained in:
3
packages/bookshop/.prettierrc
Normal file
3
packages/bookshop/.prettierrc
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"printWidth": 120
|
||||
}
|
||||
@@ -27,9 +27,7 @@ module.exports = cds.service.impl(async () => {
|
||||
const local = db.transaction(req)
|
||||
const [replica] = await local.read(Addresses).where(assigned)
|
||||
if (replica) return //> already replicated
|
||||
const [address] = await bupa
|
||||
.tx(req)
|
||||
.run(SELECT.from(externalAddresses).where(assigned))
|
||||
const [address] = await bupa.tx(req).run(SELECT.from(externalAddresses).where(assigned))
|
||||
if (address) return local.create(Addresses).entries(address)
|
||||
})
|
||||
|
||||
@@ -68,13 +66,8 @@ module.exports = cds.service.impl(async () => {
|
||||
const { Items } = req.data
|
||||
|
||||
// validate input...
|
||||
if (!Items || Items.length === 0)
|
||||
return req.reject('Please order at least one item.')
|
||||
if (!req.data.shippingAddress_ID)
|
||||
return req.reject(
|
||||
'Please enter a valid shipping address.',
|
||||
'shippingAddress_ID'
|
||||
)
|
||||
if (!Items || Items.length === 0) return req.reject('Please order at least one item.')
|
||||
if (!req.data.shippingAddress_ID) return req.reject('Please enter a valid shipping address.', 'shippingAddress_ID')
|
||||
|
||||
// reduce stock on ordered books...
|
||||
const all = await db.tx(req).run(
|
||||
@@ -85,14 +78,7 @@ module.exports = cds.service.impl(async () => {
|
||||
.set('stock -=', each.amount)
|
||||
)
|
||||
)
|
||||
all.forEach(
|
||||
(affectedRows, i) =>
|
||||
affectedRows > 0 ||
|
||||
req.error(
|
||||
409,
|
||||
`${Items[i].amount} exceeds stock for book #${Items[i].book_ID}`
|
||||
)
|
||||
)
|
||||
all.forEach((affectedRows, i) => affectedRows > 0 || req.error(409, `${Items[i].amount} exceeds stock for book #${Items[i].book_ID}`))
|
||||
})
|
||||
})
|
||||
require('./utils')
|
||||
|
||||
@@ -3,11 +3,7 @@ const { Books } = cds.entities
|
||||
|
||||
/** Service implementation for CatalogService */
|
||||
module.exports = cds.service.impl(function () {
|
||||
this.after(
|
||||
'READ',
|
||||
'Books',
|
||||
each => each.stock > 111 && _addDiscount2(each, 11)
|
||||
)
|
||||
this.after('READ', 'Books', each => each.stock > 111 && _addDiscount2(each, 11))
|
||||
this.before('CREATE', 'Orders', _reduceStock)
|
||||
})
|
||||
|
||||
@@ -28,12 +24,6 @@ async function _reduceStock (req) {
|
||||
)
|
||||
)
|
||||
all.forEach((affectedRows, i) => {
|
||||
if (affectedRows === 0)
|
||||
req.error(
|
||||
409,
|
||||
`${OrderItems[i].amount} exceeds stock for book #${
|
||||
OrderItems[i].book_ID
|
||||
}`
|
||||
)
|
||||
if (affectedRows === 0) req.error(409, `${OrderItems[i].amount} exceeds stock for book #${OrderItems[i].book_ID}`)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,33 +4,18 @@ process.env['https_proxy'] = ''
|
||||
process.env['HTTP_PROXY'] = ''
|
||||
process.env['HTTPS_PROXY'] = ''
|
||||
|
||||
const diff = (obj1, obj2) =>
|
||||
Object.keys(obj1).reduce(
|
||||
(res, curr) =>
|
||||
obj1[curr] === obj2[curr] ? res : (res[curr] = obj2[curr]) && res,
|
||||
{}
|
||||
)
|
||||
const diff = (obj1, obj2) => Object.keys(obj1).reduce((res, curr) => (obj1[curr] === obj2[curr] ? res : (res[curr] = obj2[curr]) && res), {})
|
||||
|
||||
const queriesToUpdateDifferences = (entity, ownEntries, otherEntries) =>
|
||||
ownEntries
|
||||
.map(ownEntry => {
|
||||
const otherEntry = otherEntries.find(otherEntry =>
|
||||
Object.keys(entity.keys).reduce(
|
||||
(res, curr) => res && otherEntry[curr] === ownEntry[curr],
|
||||
true
|
||||
)
|
||||
)
|
||||
const otherEntry = otherEntries.find(otherEntry => Object.keys(entity.keys).reduce((res, curr) => res && otherEntry[curr] === ownEntry[curr], true))
|
||||
if (otherEntry) {
|
||||
const differences = diff(ownEntry, otherEntry)
|
||||
if (Object.keys(differences).length) {
|
||||
return UPDATE(entity)
|
||||
.set(differences)
|
||||
.where(
|
||||
Object.keys(entity.keys).reduce(
|
||||
(res, curr) => (res[curr] = ownEntry[curr]) && res,
|
||||
{}
|
||||
)
|
||||
)
|
||||
.where(Object.keys(entity.keys).reduce((res, curr) => (res[curr] = ownEntry[curr]) && res, {}))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user