Skip to content

Commit 6e7f5ab

Browse files
Add info about product return to product history
1 parent 9521173 commit 6e7f5ab

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

openapi.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ components:
122122
type: integer
123123
example: 19
124124
description: Price (in cents) of the product bought.
125+
returned:
126+
type: boolean
127+
example: false
128+
description: Has the user returned this product or not?
125129
PurchaseEventProduct:
126130
type: object
127131
required:

src/db/historyStore.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const rowToPurchase = (row) => {
1010
price: row.sellprice,
1111
balanceAfter: row.saldo,
1212
stockAfter: row.count,
13+
returned: row.returned,
1314
};
1415
};
1516

@@ -31,6 +32,7 @@ export const createPurchaseHistoryQuery = () =>
3132
.leftJoin('RVPERSON', 'ITEMHISTORY.userid', 'RVPERSON.userid')
3233
.leftJoin('ROLE', 'RVPERSON.roleid', 'ROLE.roleid')
3334
.leftJoin('SALDOHISTORY', 'ITEMHISTORY.saldhistid', 'SALDOHISTORY.saldhistid')
35+
.leftJoin('ITEMHISTORY as ih2', 'ih2.itemhistid2', 'ITEMHISTORY.itemhistid')
3436
.select(
3537
'ITEMHISTORY.itemhistid',
3638
'ITEMHISTORY.time',
@@ -49,7 +51,8 @@ export const createPurchaseHistoryQuery = () =>
4951
'RVPERSON.saldo as currentsaldo',
5052
'ROLE.role',
5153
'SALDOHISTORY.saldo',
52-
'RVPERSON.privacy_level'
54+
'RVPERSON.privacy_level',
55+
knex.raw('(ih2.itemhistid2 is not null) as returned')
5356
)
5457
.where('ITEMHISTORY.actionid', actions.BOUGHT_BY) /* actionid 5 = buy action */
5558
.orderBy([

src/routes/userPurchaseHistory.ts

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ router.get('/', async (req: Authenticated_request, res) => {
2525
sellPrice: purchase.product.sellPrice,
2626
stock: purchase.product.stock,
2727
},
28+
returned: purchase.returned,
2829
price: purchase.price,
2930
balanceAfter: purchase.balanceAfter,
3031
};
@@ -75,6 +76,7 @@ router.get('/:purchaseId(\\d+)', async (req: Authenticated_request, res) => {
7576
sellPrice: purchase.product.sellPrice,
7677
stock: purchase.product.stock,
7778
},
79+
returned: purchase.returned,
7880
price: purchase.price,
7981
balanceAfter: purchase.balanceAfter,
8082
},

0 commit comments

Comments
 (0)