tango-app-api-payment-subscription 3.5.4 → 3.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-payment-subscription",
3
- "version": "3.5.4",
3
+ "version": "3.5.6",
4
4
  "description": "paymentSubscription",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  "nodemon": "^3.1.0",
30
30
  "puppeteer": "^24.41.0",
31
31
  "swagger-ui-express": "^5.0.0",
32
- "tango-api-schema": "^2.5.77",
32
+ "tango-api-schema": "^2.6.25",
33
33
  "tango-app-api-middleware": "^3.6.18",
34
34
  "winston": "^3.12.0",
35
35
  "winston-daily-rotate-file": "^5.0.0",
@@ -0,0 +1,66 @@
1
+ // One-shot migration: replaces the legacy billing-group proRata values
2
+ // 'before15' → 'flat' and 'after15' → 'prorate'. Idempotent — safe to
3
+ // re-run; rows already on the new values are skipped.
4
+ //
5
+ // Usage:
6
+ // MONGO_URI="mongodb://..." node scripts/migrate-billing-prorata-pricing.js
7
+ //
8
+ // Sequencing: MUST run BEFORE deploying the tightened schema enum
9
+ // ['prorate','flat'] in tango-api-schema, otherwise updateBillingGroup
10
+ // calls on unmigrated rows will fail Mongoose ValidationError.
11
+
12
+ import mongoose from 'mongoose';
13
+ import 'dotenv/config';
14
+
15
+ const NEW_VALUES = [ 'prorate', 'flat' ];
16
+
17
+ async function run() {
18
+ const uri = process.env.MONGO_URI;
19
+ if ( !uri ) {
20
+ console.error( 'MONGO_URI env var is required' );
21
+ process.exit( 1 );
22
+ }
23
+
24
+ await mongoose.connect( uri );
25
+ // strict:false so we don't pin to a specific tango-api-schema version.
26
+ const Billing = mongoose.model(
27
+ '_migrateBilling',
28
+ new mongoose.Schema( {}, { strict: false } ),
29
+ 'billings',
30
+ );
31
+
32
+ // before15 (legacy "full-month for stores active most of the month") → flat
33
+ const flatResult = await Billing.updateMany(
34
+ { proRata: 'before15' },
35
+ { $set: { proRata: 'flat' } },
36
+ );
37
+ console.log( `Migrated ${flatResult.modifiedCount} billing group(s) from 'before15' → 'flat'` );
38
+
39
+ // after15 (legacy "always actual working days") → prorate
40
+ const prorateResult = await Billing.updateMany(
41
+ { proRata: 'after15' },
42
+ { $set: { proRata: 'prorate' } },
43
+ );
44
+ console.log( `Migrated ${prorateResult.modifiedCount} billing group(s) from 'after15' → 'prorate'` );
45
+
46
+ // Surface any rows whose proRata is something unexpected (manual review).
47
+ const stray = await Billing.find(
48
+ { proRata: { $exists: true, $nin: [ ...NEW_VALUES, null, '' ] } },
49
+ { _id: 1, clientId: 1, groupName: 1, proRata: 1 },
50
+ ).limit( 50 ).lean();
51
+
52
+ if ( stray.length ) {
53
+ console.warn( `Found ${stray.length} row(s) with unexpected proRata values:` );
54
+ stray.forEach( ( s ) => console.warn( ' -', s._id.toString(), s.clientId, s.groupName, '=>', s.proRata ) );
55
+ console.warn( 'Review these manually before tightening the schema enum.' );
56
+ } else {
57
+ console.log( 'No stray proRata values found. Safe to tighten the schema.' );
58
+ }
59
+
60
+ await mongoose.disconnect();
61
+ }
62
+
63
+ run().catch( ( err ) => {
64
+ console.error( err );
65
+ process.exit( 1 );
66
+ } );