-
Notifications
You must be signed in to change notification settings - Fork 0
/
repo_naming_proposal
75 lines (63 loc) · 1.77 KB
/
repo_naming_proposal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// The purpose of this is to have a proposed appraches for the repo namming conventions
// Actually I don't think any of these approahces is complete. in terms of ready for implementation
// Please don't hesistate to share any approach you have in mind
class TransactionRepo {
// first approach --------------------
getTransactionDetails (entityId, orderIds) {
return TransactionModel.query()
.joinRelated('receipt')
.skipUndefined()
.distinct('orderId')
.where('receipt.entityId', entityId)
.whereIn('orderId', orderIds)
}
// --------------------
// Second approach --------------------
getTransaction () {
return TransactionModel.query()
}
getTransactionsFiltered({id, state, orderId}){
return this.getTransactions()
.skipUndefined()
.where({id, state})
.whereIn({orderId})
}
getTransactionsWithReceipt ({id, state, orderId}) {
return this.getTransactionsFiltered({id, state, orderId})
.joinRelated('receipt')
}
getTransactionsDetails ({id, orderId, productIds}) {
return this.getTransactionsWithReceipt({id, orderId})
.distinct('productId')
.whereIn('productId', productIds)
}
// --------------------
// Third approach --------------------
getTransactions () {
return ReceiptItemModel.query()
}
joinReceipt () {
this.joinRelated('receipt')
return this
}
filter ({id, state, orderId}){
this.skipUndefined()
.where({id, state})
.whereIn({orderId})
return this
}
distinct (column){
this.distinct(column)
return this
}
filterReceipt ({entityId}){
this.skipUndefined()
.where('receipt.entityId', entityId)
return this
}
service(){
this.getTransactions().filter({orderId}).distinct("orderId").joinReceipt().filterReceipt({entityId})
}
}
// --------------------
module.exports = new TransactionRepo()