Skip to content

Commit c039a7f

Browse files
committed
Add currency to businessOperation
1 parent 94c59b1 commit c039a7f

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module.exports = {
2+
async up(db, client) {
3+
/**
4+
* Use one transaction for all requests
5+
*/
6+
const session = client.startSession();
7+
8+
try {
9+
await session.withTransaction(async () => {
10+
const businessOperationsCollection = db.collection('businessOperations');
11+
12+
await businessOperationsCollection.updateMany(
13+
{},
14+
{ $set: { 'payload.currency': 'RUB' } } // Set the default value for payload.currency
15+
);
16+
});
17+
18+
} finally {
19+
await session.endSession();
20+
}
21+
},
22+
23+
async down(db, client) {
24+
/**
25+
* Use one transaction for all requests
26+
*/
27+
const session = client.startSession();
28+
29+
try {
30+
31+
await session.withTransaction(async () => {
32+
const businessOperationsCollection = db.collection('businessOperations');
33+
34+
await businessOperationsCollection.updateMany(
35+
{},
36+
{ $unset: { 'payload.businessOperations': "" } } // Remove the businessOperations field
37+
);
38+
});
39+
40+
} finally {
41+
await session.endSession();
42+
}
43+
}
44+
};

src/billing/cloudpayments.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ export default class CloudPaymentsWebhooks {
244244
payload: {
245245
workspaceId: workspace._id,
246246
amount: +body.Amount * PENNY_MULTIPLIER,
247+
// @ts-ignore
248+
currency: body.Currency,
247249
userId: member._id,
248250
tariffPlanId: plan._id,
249251
},

src/typeDefs/billing.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,14 @@ type PayloadOfWorkspacePlanPurchase {
121121
workspace: Workspace!
122122
123123
"""
124-
Amount of payment in US cents
124+
Amount of payment * 100
125125
"""
126126
amount: Long!
127+
128+
"""
129+
Currency of payment
130+
"""
131+
currency: String!
127132
}
128133
129134
"""

test/models/businessOperation.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('Business operation model', () => {
1919
const payloadDepositByUser = {
2020
workspaceId: new ObjectId('5edd36fbb596d4759beb89f6'),
2121
amount: 100,
22+
currency: 'USD',
2223
userId: new ObjectId('5eb9034a1ccc4421e2623dc2'),
2324
cardPan: '4455',
2425
};

0 commit comments

Comments
 (0)