-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add predictoor data table structure * Better test * Add predictoorRewards table structure * Parse predictoor csvs * Add predictoor router * Add predictoor rewards into rewardsSummary * Update test
- Loading branch information
Showing
10 changed files
with
146 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const express = require("express") | ||
const { getPredictoorData, getPredictoorRewards } = require("../../services/rewards_info") | ||
const router = express.Router() | ||
|
||
router.post("/data", async (req, res) => { | ||
let data = await getPredictoorData(req.body) | ||
res.json(data) | ||
}) | ||
|
||
router.post("/rewards", async (req, res) => { | ||
let data = await getPredictoorRewards(req.body) | ||
res.json(data) | ||
}) | ||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { selectQuery } = require("../querier") | ||
|
||
const getPredictoorData = ({ query, sort, limit, offset, group, fields, join }) => { | ||
return selectQuery( | ||
query, | ||
sort, | ||
limit, | ||
offset, | ||
"predictoor_data", | ||
group, | ||
fields, | ||
join | ||
) | ||
} | ||
|
||
const getPredictoorRewards = ({ query, sort, limit, offset, group, fields, join }) => { | ||
return selectQuery( | ||
query, | ||
sort, | ||
limit, | ||
offset, | ||
"predictoor_rewards", | ||
group, | ||
fields, | ||
join | ||
) | ||
} | ||
|
||
module.exports = { | ||
getPredictoorData, | ||
getPredictoorRewards | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,26 @@ | ||
const { Parser } = require("node-sql-parser") | ||
const parser = new Parser() | ||
const { | ||
allocationsTable, | ||
nftVolsTable, | ||
vebalsTable, | ||
rewardsInfo, | ||
passiveRewardsInfo, | ||
nftinfoTable, | ||
rewardsSummary, | ||
ownersInfo | ||
} = require("../db/structure") | ||
const { Parser } = require("node-sql-parser"); | ||
const parser = new Parser(); | ||
const dbStructure = require("../db/structure"); | ||
|
||
describe("SQL Table Structures", () => { | ||
test.each([ | ||
["allocationsTable", allocationsTable], | ||
["nftVolsTable", nftVolsTable], | ||
["vebalsTable", vebalsTable], | ||
["rewardsInfo", rewardsInfo], | ||
["passiveRewardsInfo", passiveRewardsInfo], | ||
["nftinfoTable", nftinfoTable], | ||
["rewardsSummary", rewardsSummary], | ||
["ownersInfo", ownersInfo] | ||
])("validates structure of %s", (tableName, sqlQuery) => { | ||
let ast | ||
try { | ||
ast = parser.astify(sqlQuery) | ||
} catch (error) { | ||
throw new Error( | ||
`Error parsing SQL for ${tableName}: ${error.message}` | ||
) | ||
} | ||
if (sqlQuery.endsWith(";")) { | ||
// parser returns an array if the query ends with a ; | ||
ast.forEach((ast) => { | ||
expect(ast.type).toBe("create") | ||
expect(ast.keyword).toBe("table") | ||
}) | ||
} else { | ||
expect(ast.type).toBe("create") | ||
expect(ast.keyword).toBe("table") | ||
} | ||
}) | ||
}) | ||
Object.entries(dbStructure).forEach(([tableName, sqlQuery]) => { | ||
test(`validates structure of ${tableName}`, () => { | ||
let ast; | ||
try { | ||
ast = parser.astify(sqlQuery); | ||
} catch (error) { | ||
throw new Error(`Error parsing SQL for ${tableName}: ${error.message}`); | ||
} | ||
if (sqlQuery.endsWith(";")) { | ||
// parser returns an array if the query ends with a ; | ||
ast.forEach((ast) => { | ||
expect(ast.type).toBe("create"); | ||
expect(ast.keyword).toBe("table"); | ||
}); | ||
} else { | ||
expect(ast.type).toBe("create"); | ||
expect(ast.keyword).toBe("table"); | ||
} | ||
}); | ||
}); | ||
}); |