Skip to content

Commit

Permalink
Add isDebug (#339)
Browse files Browse the repository at this point in the history
* Add isDebug

* Update index.ts

* Update index.ts

* Lint

* Update ubuntu version
  • Loading branch information
TatianaFomina authored Jan 11, 2025
1 parent 4d1973c commit 6c8271e
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions workers/paymaster/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ export default class PaymasterWorker extends Worker {
* Pay day is calculated by formula: last charge date + 30 days
*
* @param date - last charge date
* @param isDebug

Check warning on line 66 in workers/paymaster/src/index.ts

View workflow job for this annotation

GitHub Actions / ESlint

Missing JSDoc @param "isDebug" description
*/
private static isTimeToPay(date: Date): boolean {
const numberOfDays = 30;
private static isTimeToPay(date: Date, isDebug = false): boolean {
const expectedPayDay = new Date(date);

expectedPayDay.setDate(date.getDate() + numberOfDays);
if (isDebug) {
expectedPayDay.setDate(date.getDate() + 1);
} else {
expectedPayDay.setMonth(date.getMonth() + 1);
}

const now = new Date().getTime();

Expand All @@ -81,12 +85,16 @@ export default class PaymasterWorker extends Worker {
* Pay day is calculated by formula: last charge date + 30 days
*
* @param date - last charge date
* @param isDebug

Check warning on line 88 in workers/paymaster/src/index.ts

View workflow job for this annotation

GitHub Actions / ESlint

Missing JSDoc @param "isDebug" description
*/
private static daysBeforePayday(date: Date): number {
const numberOfDays = 30;
private static daysBeforePayday(date: Date, isDebug = false): number {
const expectedPayDay = new Date(date);

expectedPayDay.setDate(date.getDate() + numberOfDays);
if (isDebug) {
expectedPayDay.setDate(date.getDate() + 1);
} else {
expectedPayDay.setMonth(date.getMonth() + 1);
}

const now = new Date().getTime();

Expand All @@ -99,12 +107,16 @@ export default class PaymasterWorker extends Worker {
* Pay day is calculated by formula: last charge date + 30 days
*
* @param date - last charge date
* @param isDebug

Check warning on line 110 in workers/paymaster/src/index.ts

View workflow job for this annotation

GitHub Actions / ESlint

Missing JSDoc @param "isDebug" description
*/
private static daysAfterPayday(date: Date): number {
const numberOfDays = 30;
private static daysAfterPayday(date: Date, isDebug = false): number {
const expectedPayDay = new Date(date);

expectedPayDay.setDate(date.getDate() + numberOfDays);
if (isDebug) {
expectedPayDay.setDate(date.getDate() + 1);
} else {
expectedPayDay.setMonth(date.getMonth() + 1);
}

const now = new Date().getTime();

Expand Down Expand Up @@ -196,17 +208,20 @@ export default class PaymasterWorker extends Worker {
/**
* Is it time to pay
*/
const isTimeToPay = PaymasterWorker.isTimeToPay(workspace.lastChargeDate);
// @ts-expect-error debug
const isTimeToPay = PaymasterWorker.isTimeToPay(workspace.lastChargeDate, workspace.isDebug);

/**
* How many days have passed since payments the expected day of payments
*/
const daysAfterPayday = PaymasterWorker.daysAfterPayday(workspace.lastChargeDate);
// @ts-expect-error debug
const daysAfterPayday = PaymasterWorker.daysAfterPayday(workspace.lastChargeDate, workspace.isDebug);

/**
* How many days left for the expected day of payments
*/
const daysLeft = PaymasterWorker.daysBeforePayday(workspace.lastChargeDate);
// @ts-expect-error debug
const daysLeft = PaymasterWorker.daysBeforePayday(workspace.lastChargeDate, workspace.isDebug);

/**
* Do we need to ask for money
Expand All @@ -215,6 +230,7 @@ export default class PaymasterWorker extends Worker {

/**
* Today is not payday for workspace
* Alerting admins to pay for the workspace
*/
if (!isTimeToPay) {
/**
Expand Down

0 comments on commit 6c8271e

Please sign in to comment.