Skip to content

Commit 534abef

Browse files
author
Ajit Kumar
committed
fix(cron-jobs)
1 parent 25a7063 commit 534abef

File tree

8 files changed

+1463
-1140
lines changed

8 files changed

+1463
-1140
lines changed

cron-jobs/updateEarnings.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/* eslint-disable no-console */
2-
const { config } = require('dotenv');
32
const path = require('path');
3+
const { config } = require('dotenv');
44
const setAuth = require('../server/gapis');
55
const updateEarnings = require('../server/updateEarnings');
66
const { sendNotification } = require('../server/helpers');
77

8+
config({ path: path.resolve(__dirname, '../.env') });
9+
810
(async () => {
911
try {
10-
config({ path: path.resolve(__dirname, '../.env') });
1112
await setAuth();
1213
await updateEarnings();
1314
sendNotification(

package.json

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,66 +9,63 @@
99
"node": ">=12.16.1"
1010
},
1111
"devDependencies": {
12-
"@babel/core": "^7.24.0",
13-
"@babel/plugin-transform-runtime": "^7.24.0",
14-
"@babel/preset-env": "^7.24.0",
15-
"autoprefixer": "^10.4.18",
12+
"@babel/core": "^7.26.0",
13+
"@babel/plugin-transform-runtime": "^7.25.9",
14+
"@babel/preset-env": "^7.26.0",
15+
"autoprefixer": "^10.4.20",
1616
"babel-cli": "^6.26.0",
17-
"babel-loader": "^9.1.3",
18-
"css-loader": "^6.10.0",
17+
"babel-loader": "^9.2.1",
18+
"css-loader": "^7.1.2",
1919
"eslint": "^8.57.0",
2020
"eslint-config-airbnb-base": "^15.0.0",
2121
"eslint-import-resolver-typescript": "^3.6.1",
2222
"eslint-plugin-import": "^2.29.1",
2323
"eslint-plugin-jsx": "^0.1.0",
2424
"file-loader": "^6.2.0",
2525
"kill-port": "^2.0.1",
26-
"mini-css-extract-plugin": "^2.8.1",
27-
"nodemon": "^3.1.0",
28-
"postcss": "^8.4.35",
26+
"mini-css-extract-plugin": "^2.9.2",
27+
"nodemon": "^3.1.9",
28+
"postcss": "^8.4.49",
2929
"postcss-loader": "^8.1.1",
3030
"raw-loader": "^4.0.0",
31-
"sass": "^1.72.0",
32-
"sass-loader": "^14.1.1",
33-
"style-loader": "^3.3.4",
34-
"terser-webpack-plugin": "^5.3.10",
31+
"sass": "^1.83.0",
32+
"sass-loader": "^16.0.4",
33+
"style-loader": "^4.0.0",
34+
"terser-webpack-plugin": "^5.3.11",
3535
"url-loader": "^4.1.1",
36-
"webpack": "5.90.3",
37-
"webpack-bundle-analyzer": "^4.10.1",
36+
"webpack": "5.97.1",
37+
"webpack-bundle-analyzer": "^4.10.2",
3838
"webpack-cli": "5.1.4"
3939
},
4040
"dependencies": {
41-
"@anthropic-ai/sdk": "^0.18.0",
42-
"@google-cloud/storage": "^7.8.0",
41+
"@anthropic-ai/sdk": "^0.32.1",
42+
"@google-cloud/storage": "^7.14.0",
4343
"autosize": "^6.0.1",
44-
"cookie-parser": "^1.4.6",
45-
"core-js": "^3.36.0",
44+
"cookie-parser": "^1.4.7",
45+
"core-js": "^3.39.0",
4646
"csvtojson": "^2.0.10",
4747
"decimal.js": "^10.4.3",
48-
"dotenv": "^16.4.5",
49-
"express": "^4.18.3",
50-
"express-fileupload": "^1.5.0",
51-
"github-buttons": "^2.27.0",
52-
"googleapis": "^134.0.0",
53-
"html-tag-js": "^1.4.3",
48+
"dotenv": "^16.4.7",
49+
"express": "^4.21.2",
50+
"express-fileupload": "^1.5.1",
51+
"github-buttons": "^2.29.1",
52+
"googleapis": "^144.0.0",
53+
"html-tag-js": "^1.8.2",
5454
"jszip": "^3.10.1",
55-
"marked": "^12.0.1",
55+
"marked": "^15.0.4",
5656
"moment": "^2.30.1",
57-
"nodemailer": "^6.9.12",
57+
"nodemailer": "^6.9.16",
5858
"sqlite3": "^5.1.7"
5959
},
6060
"scripts": {
6161
"config-build": "node ./tools/config",
6262
"build-release": "yarn config-build p && webpack --mode production",
6363
"start-dev": "node ./tools/start-dev",
6464
"upgrade-meta": "node ./server/upgradeMeta",
65+
"download": "node ./server/reportsCli",
6566
"start": "node ./server/main"
6667
},
6768
"browserslist": [
6869
"> 0.25%, not dead"
69-
],
70-
"resolutions": {
71-
"braces": ">=2.3.1",
72-
"glob-parent": ">=5.1.2"
73-
}
70+
]
7471
}

server/downloadSalesCsv.js

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,33 @@ const downloadReport = require('./downloadGr');
99
* @param {number} year Year to download
1010
* @param {number} month Month of the year to download, 1-12
1111
*/
12-
async function downloadSalesReportCsv(year, month) {
13-
const json = await downloadReport(year, month, 'sales');
12+
async function downloadSalesReportCsv(year, month, type = 'sales') {
13+
const json = await downloadReport(year, month, type);
1414
const orders = {};
1515

1616
json.forEach((row) => {
17-
const id = row['Order Number'];
18-
const date = row['Order Charged Date'];
19-
const product = row['Product Title'];
20-
const productId = row['SKU ID'];
21-
const cityOfBuyer = row['City of Buyer'];
22-
const stateOfBuyer = row['State of Buyer'];
23-
const countryOfBuyer = row['Country of Buyer'];
24-
const chargedAmount = row['Charged Amount'].replace(',', '');
25-
26-
if (orders[id]) {
27-
const order = orders[id];
28-
order.chargedAmount = new Decimal(order.chargedAmount).add(chargedAmount).toString();
29-
return;
17+
if (type === 'sales') {
18+
sales(row, orders);
19+
} else {
20+
earnings(row, orders);
3021
}
31-
32-
orders[id] = {
33-
id,
34-
date: date.replace(/,/g, ''),
35-
product,
36-
productId,
37-
cityOfBuyer,
38-
stateOfBuyer,
39-
countryOfBuyer,
40-
chargedAmount,
41-
};
4222
});
4323

44-
let csv = 'Order Id,Date,Product,Product Id,Country of Buyer,State of Buyer,City of Buyer,Amount in Buyer Currency\n';
45-
Object.values(orders).forEach((order) => {
46-
csv += `${order.id},${order.date},${order.product},${order.productId},${order.countryOfBuyer},${order.stateOfBuyer},${order.cityOfBuyer},${order.chargedAmount}\n`;
47-
});
24+
let csv;
25+
26+
if (type === 'earnings') {
27+
csv = 'ID,Date,Product,Amount\n';
28+
Object.values(orders).forEach((order) => {
29+
csv += `${order.id},${order.date},${order.product},${order.amount}\n`;
30+
});
31+
} else {
32+
csv = 'Order Id,Date,Product,Product Id,Country of Buyer,State of Buyer,City of Buyer,Amount in Buyer Currency\n'
33+
Object.values(orders).forEach((order) => {
34+
csv += `${order.id},${order.date},${order.product},${order.productId},${order.countryOfBuyer},${order.stateOfBuyer},${order.cityOfBuyer},${order.chargedAmount}\n`;
35+
});
36+
}
4837

49-
const fileName = `sales-${year}-${month}.csv`;
38+
const fileName = `${type}-${year}-${month}.csv`;
5039
const dirname = path.resolve('../reports');
5140
const filePath = path.resolve(dirname, fileName);
5241
if (!fileSystem.existsSync(dirname)) {
@@ -57,4 +46,52 @@ async function downloadSalesReportCsv(year, month) {
5746
return filePath;
5847
}
5948

49+
function sales(row, orders) {
50+
const id = row['Order Number'];
51+
const date = row['Order Charged Date'];
52+
const product = row['Product Title'];
53+
const productId = row['SKU ID'];
54+
const cityOfBuyer = row['City of Buyer'];
55+
const stateOfBuyer = row['State of Buyer'];
56+
const countryOfBuyer = row['Country of Buyer'];
57+
const chargedAmount = row['Charged Amount'].replace(',', '');
58+
59+
if (orders[id]) {
60+
const order = orders[id];
61+
order.chargedAmount = new Decimal(order.chargedAmount).add(chargedAmount).toString();
62+
return;
63+
}
64+
65+
orders[id] = {
66+
id,
67+
date: date.replace(/,/g, ''),
68+
product,
69+
productId,
70+
cityOfBuyer,
71+
stateOfBuyer,
72+
countryOfBuyer,
73+
chargedAmount,
74+
};
75+
}
76+
77+
function earnings(row, orders) {
78+
const id = row['Description'];
79+
const date = row['Transaction Date'];
80+
const product = row['Product Title'];
81+
const amount = row['Amount (Merchant Currency)'];
82+
83+
if (orders[id]) {
84+
const order = orders[id];
85+
order.amount = new Decimal(order.amount).add(amount).toString();
86+
return;
87+
}
88+
89+
orders[id] = {
90+
id,
91+
date: date.replace(/,/g, ''),
92+
product,
93+
amount,
94+
};
95+
}
96+
6097
module.exports = downloadSalesReportCsv;

server/entities/user.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
const path = require('path');
2+
const { config } = require('dotenv');
13
const { encryptPassword } = require('../password');
24
const Entity = require('./entity');
35

6+
config({ path: path.resolve(__dirname, '../../.env') });
7+
48
const table = `create table if not exists user (
59
id integer primary key,
610
name text not null,

server/reportsCli.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ const downloadGrCsv = require('./downloadSalesCsv');
33

44
const month = process.argv[2];
55
const year = process.argv[3];
6+
const type = process.argv[4] || 'sales';
67

78
if (!month || !year) {
8-
console.error('Usage: node reportsCli.js <month> <year>');
9+
console.error('Usage: node reportsCli.js <mm> <yyyy> <sales|earnings>');
910
process.exit(1);
1011
}
1112

12-
downloadGrCsv(Number(year), Number(month))
13+
downloadGrCsv(Number(year), Number(month), type)
1314
.then((filePath) => {
1415
console.log(`Report downloaded to ${filePath}`);
1516
process.exit(0);

server/updateEarnings.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const moment = require('moment');
2-
const downloadReport = require('./downloadGr');
3-
const UserEarnings = require('./entities/userEarnings');
4-
const Payment = require('./entities/payment');
52
const Plugin = require('./entities/plugin');
6-
const { sendNotification } = require('./helpers');
3+
const Payment = require('./entities/payment');
4+
const downloadReport = require('./downloadGr');
75
const calcEarnings = require('./calcEarnings');
6+
const { sendNotification } = require('./helpers');
7+
const UserEarnings = require('./entities/userEarnings');
88
const PaymentMethod = require('./entities/paymentMethod');
99

1010
const now = moment();

src/components/docs/style.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
@import '../../mixins.scss';
1+
@use '../../mixins.scss' as *;
22

33
.docs-container {
44
padding: 0;
55
margin: 0;
6-
display: flex;
76
width: 100%;
7+
display: flex;
88
max-width: unset;
99

1010
#doc-nav:checked ~ .side-nav {

0 commit comments

Comments
 (0)