Squashed commit of the following:
commitfa7791e203Author: aswincosq <aswinbs@cosq.net> Date: Tue Jul 8 14:15:43 2025 +0530 Added invoice amount to /invoices endpoint commit9fb76e7277Author: aswincosq <aswinbs@cosq.net> Date: Tue May 20 13:34:32 2025 +0530 Made changes in ec2 invoice to return the appropriate usage type
This commit is contained in:
parent
4fff09443d
commit
2ee39b39bf
105
package-lock.json
generated
105
package-lock.json
generated
@ -12,8 +12,9 @@
|
||||
"@aws-sdk/client-athena": "^3.699.0",
|
||||
"@aws-sdk/client-s3": "^3.701.0",
|
||||
"@aws-sdk/credential-providers": "^3.699.0",
|
||||
"awsmetrics": "file:",
|
||||
"dotenv": "^16.4.5",
|
||||
"fastify": "^5.1.0",
|
||||
"fastify": "^5.3.0",
|
||||
"fastify-plugin": "^5.0.1",
|
||||
"sequelize": "^6.37.5",
|
||||
"sqlite3": "^5.1.7"
|
||||
@ -1053,6 +1054,12 @@
|
||||
"fast-json-stringify": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@fastify/forwarded": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@fastify/forwarded/-/forwarded-3.0.0.tgz",
|
||||
"integrity": "sha512-kJExsp4JCms7ipzg7SJ3y8DwmePaELHxKYtg+tZow+k0znUTf3cb+npgyqm8+ATZOdmfgfydIebPDWM172wfyA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@fastify/merge-json-schemas": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@fastify/merge-json-schemas/-/merge-json-schemas-0.1.1.tgz",
|
||||
@ -1061,6 +1068,16 @@
|
||||
"fast-deep-equal": "^3.1.3"
|
||||
}
|
||||
},
|
||||
"node_modules/@fastify/proxy-addr": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@fastify/proxy-addr/-/proxy-addr-5.0.0.tgz",
|
||||
"integrity": "sha512-37qVVA1qZ5sgH7KpHkkC4z9SK6StIsIcOmpjvMPXNb3vx2GQxhZocogVYbr2PbbeLCQxYIPDok307xEvRZOzGA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@fastify/forwarded": "^3.0.0",
|
||||
"ipaddr.js": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@gar/promisify": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@gar/promisify/-/promisify-1.1.3.tgz",
|
||||
@ -1896,6 +1913,10 @@
|
||||
"fastq": "^1.17.1"
|
||||
}
|
||||
},
|
||||
"node_modules/awsmetrics": {
|
||||
"resolved": "",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/balanced-match": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||
@ -2238,9 +2259,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/fastify": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/fastify/-/fastify-5.2.0.tgz",
|
||||
"integrity": "sha512-3s+Qt5S14Eq5dCpnE0FxTp3z4xKChI83ZnMv+k0FwX+VUoZrgCFoLAxpfdi/vT4y6Mk+g7aAMt9pgXDoZmkefQ==",
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/fastify/-/fastify-5.3.2.tgz",
|
||||
"integrity": "sha512-AIPqBgtqBAwkOkrnwesEE+dOyU30dQ4kh7udxeGVR05CRGwubZx+p2H8P0C4cRnQT0+EPK4VGea2DTL2RtWttg==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
@ -2251,20 +2272,21 @@
|
||||
"url": "https://opencollective.com/fastify"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@fastify/ajv-compiler": "^4.0.0",
|
||||
"@fastify/error": "^4.0.0",
|
||||
"@fastify/fast-json-stringify-compiler": "^5.0.0",
|
||||
"@fastify/proxy-addr": "^5.0.0",
|
||||
"abstract-logging": "^2.0.1",
|
||||
"avvio": "^9.0.0",
|
||||
"fast-json-stringify": "^6.0.0",
|
||||
"find-my-way": "^9.0.0",
|
||||
"light-my-request": "^6.0.0",
|
||||
"pino": "^9.0.0",
|
||||
"process-warning": "^4.0.0",
|
||||
"proxy-addr": "^2.0.7",
|
||||
"process-warning": "^5.0.0",
|
||||
"rfdc": "^1.3.1",
|
||||
"secure-json-parse": "^3.0.1",
|
||||
"secure-json-parse": "^4.0.0",
|
||||
"semver": "^7.6.0",
|
||||
"toad-cache": "^3.7.0"
|
||||
}
|
||||
@ -2274,6 +2296,22 @@
|
||||
"resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-5.0.1.tgz",
|
||||
"integrity": "sha512-HCxs+YnRaWzCl+cWRYFnHmeRFyR5GVnJTAaCJQiYzQSDwK9MgJdyAsuL3nh0EWRCYMgQ5MeziymvmAhUHYHDUQ=="
|
||||
},
|
||||
"node_modules/fastify/node_modules/process-warning": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/process-warning/-/process-warning-5.0.0.tgz",
|
||||
"integrity": "sha512-a39t9ApHNx2L4+HBnQKqxxHNs1r7KF+Intd8Q/g1bUh6q0WIp9voPXJ/x0j+ZL45KF1pJd9+q2jLIRMfvEshkA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/fastify"
|
||||
},
|
||||
{
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/fastify"
|
||||
}
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/fastq": {
|
||||
"version": "1.17.1",
|
||||
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz",
|
||||
@ -2300,14 +2338,6 @@
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/forwarded": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/fs-constants": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz",
|
||||
@ -2528,11 +2558,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/ipaddr.js": {
|
||||
"version": "1.9.1",
|
||||
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
||||
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.2.0.tgz",
|
||||
"integrity": "sha512-Ag3wB2o37wslZS19hZqorUnrnzSkpOVy+IiiDEiTqNubEYpYuHWIf6K4psgN2ZWKExS4xhVCrRVfb/wfW8fWJA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/is-fullwidth-code-point": {
|
||||
@ -3001,18 +3032,6 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-addr": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
||||
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
|
||||
"dependencies": {
|
||||
"forwarded": "0.2.0",
|
||||
"ipaddr.js": "1.9.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/pump": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.2.tgz",
|
||||
@ -3164,9 +3183,20 @@
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/secure-json-parse": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-3.0.1.tgz",
|
||||
"integrity": "sha512-9QR7G96th4QJ2+dJwvZB+JoXyt8PN+DbEjOr6kL2/JU4KH8Eb2sFdU+gt8EDdzWDWoWH0uocDdfCoFzdVSixUA=="
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-4.0.0.tgz",
|
||||
"integrity": "sha512-dxtLJO6sc35jWidmLxo7ij+Eg48PM/kleBsxpC8QJE0qJICe+KawkDQmvCMZUr9u7WKVHgMW6vy3fQ7zMiFZMA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/fastify"
|
||||
},
|
||||
{
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/fastify"
|
||||
}
|
||||
],
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/semver": {
|
||||
"version": "7.6.3",
|
||||
@ -3475,9 +3505,10 @@
|
||||
}
|
||||
},
|
||||
"node_modules/tar-fs": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz",
|
||||
"integrity": "sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==",
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.2.tgz",
|
||||
"integrity": "sha512-EsaAXwxmx8UB7FRKqeozqEPop69DXcmYwTQwXvyAPF352HJsPdkVhvTaDPYqfNgruveJIJy3TA2l+2zj8LJIJA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"chownr": "^1.1.1",
|
||||
"mkdirp-classic": "^0.5.2",
|
||||
|
||||
@ -12,8 +12,9 @@
|
||||
"@aws-sdk/client-athena": "^3.699.0",
|
||||
"@aws-sdk/client-s3": "^3.701.0",
|
||||
"@aws-sdk/credential-providers": "^3.699.0",
|
||||
"awsmetrics": "file:",
|
||||
"dotenv": "^16.4.5",
|
||||
"fastify": "^5.1.0",
|
||||
"fastify": "^5.3.0",
|
||||
"fastify-plugin": "^5.0.1",
|
||||
"sequelize": "^6.37.5",
|
||||
"sqlite3": "^5.1.7"
|
||||
|
||||
59
queries.js
59
queries.js
@ -186,8 +186,13 @@ WHERE LOWER(line_item_product_code) = LOWER('%productCode%')
|
||||
|
||||
export const invoices = `select DISTINCT
|
||||
bill_invoice_id as invoiceId,
|
||||
year, month
|
||||
FROM ${process.env.ATHENA_CU_TABLE}`;
|
||||
year, month,
|
||||
SUM(line_item_unblended_cost) AS totalUnblendedCost,
|
||||
SUM(line_item_blended_cost) AS totalBlendedCost
|
||||
FROM ${process.env.ATHENA_CU_TABLE}
|
||||
WHERE bill_invoice_id IS NOT NULL
|
||||
GROUP BY bill_invoice_id, year, month
|
||||
ORDER BY year DESC, month DESC;`
|
||||
|
||||
export const invoiceById = `select DISTINCT
|
||||
bill_invoice_id as invoiceId,
|
||||
@ -217,27 +222,35 @@ FROM ${process.env.ATHENA_CU_TABLE}
|
||||
WHERE bill_invoice_id = '%invoiceId%'
|
||||
AND LOWER(line_item_product_code) = LOWER('%productCode%');`;
|
||||
|
||||
export const invoiceByProductCodeUsage = `select DISTINCT
|
||||
bill_invoice_id as invoiceId,
|
||||
year, month,
|
||||
line_item_product_code as productCode,
|
||||
line_item_usage_account_id as accountId,
|
||||
line_item_resource_id as resourceId,
|
||||
line_item_usage_type AS usageType,
|
||||
line_item_usage_amount AS usageAmount,
|
||||
line_item_unblended_rate AS unblendedRate,
|
||||
line_item_unblended_cost AS unblendedCost,
|
||||
line_item_blended_rate AS blendedRate,
|
||||
line_item_blended_cost AS blendedCost,
|
||||
pricing_term AS pricingTerm,
|
||||
pricing_unit AS pricingUnit,
|
||||
pricing_rate_code AS pricingRateCode,
|
||||
pricing_currency AS pricingCurrency,
|
||||
line_item_usage_start_date AS startDate,
|
||||
line_item_usage_end_date AS endDate
|
||||
FROM ${process.env.ATHENA_CU_TABLE}
|
||||
WHERE bill_invoice_id = '%invoiceId%'
|
||||
AND LOWER(line_item_product_code) = LOWER('%productCode%');`;
|
||||
export const invoiceByProductCodeUsage = `
|
||||
SELECT DISTINCT
|
||||
bill_invoice_id as invoiceId,
|
||||
year, month,
|
||||
line_item_product_code as productCode,
|
||||
line_item_usage_account_id as accountId,
|
||||
line_item_resource_id as resourceId,
|
||||
line_item_usage_type AS usageType,
|
||||
line_item_usage_amount AS usageAmount,
|
||||
line_item_unblended_rate AS unblendedRate,
|
||||
line_item_unblended_cost AS unblendedCost,
|
||||
line_item_blended_rate AS blendedRate,
|
||||
line_item_blended_cost AS blendedCost,
|
||||
pricing_term AS pricingTerm,
|
||||
pricing_unit AS pricingUnit,
|
||||
pricing_rate_code AS pricingRateCode,
|
||||
pricing_currency AS pricingCurrency,
|
||||
line_item_usage_start_date AS startDate,
|
||||
line_item_usage_end_date AS endDate,
|
||||
CASE
|
||||
WHEN line_item_usage_type LIKE '%BoxUsage:%'
|
||||
THEN SUBSTRING(line_item_usage_type, POSITION('BoxUsage:' IN line_item_usage_type) + 9)
|
||||
ELSE NULL
|
||||
END AS instanceType
|
||||
FROM ${process.env.ATHENA_CU_TABLE}
|
||||
WHERE bill_invoice_id = '%invoiceId%'
|
||||
AND LOWER(line_item_product_code) = LOWER('%productCode%')
|
||||
AND line_item_usage_type LIKE '%BoxUsage%'
|
||||
`;
|
||||
|
||||
export const invoiceByIdAccounts = `select DISTINCT
|
||||
bill_invoice_id as invoiceId,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user