Skip to content

Commit caf75d0

Browse files
committed
Add plan.monthlyChargeCurrency
1 parent 3e7571a commit caf75d0

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 plansCollection = db.collection('plans');
11+
12+
await plansCollection.updateMany(
13+
{},
14+
{ $set: { monthlyChargeCurrency: 'RUB' } } // Set the default value for monthlyChargeCurrency
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 plansCollection = db.collection('plans');
33+
34+
await plansCollection.updateMany(
35+
{},
36+
{ $unset: { monthlyChargeCurrency: "" } } // Remove the monthlyChargeCurrency field
37+
);
38+
39+
});
40+
41+
} finally {
42+
await session.endSession();
43+
}
44+
}
45+
};

src/models/plan.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ export default class PlanModel extends AbstractModel<PlanDBScheme> implements Pl
1717
public name!: string;
1818

1919
/**
20-
* Monthly charge for plan in dollars
20+
* Monthly charge for plan in currencry specified in `monthlyChargeCurrency`
2121
*/
2222
public monthlyCharge!: number;
2323

24+
/**
25+
* Currency of `monthlyCharge`
26+
*/
27+
public monthlyChargeCurrency!: string;
28+
2429
/**
2530
* Maximum amount of events available for plan
2631
*/

src/typeDefs/plans.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ export default gql`
2020
"""
2121
monthlyCharge: Int!
2222
23+
"""
24+
Currency of monthlyCharge
25+
"""
26+
monthlyChargeCurrency: String!
27+
2328
"""
2429
Events limit for plan
2530
"""

0 commit comments

Comments
 (0)