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
//filename: routes/index.js | |
const { ensureAuth, ensureGuest } = require("../middleware/auth"); | |
router.get("/", ensureGuest, (req, res) => { | |
res.render("login", { | |
layout: "login", | |
}); | |
}); | |
router.get("/dashboard", ensureAuth, (req, res) => { | |
res.render("dashboard"); | |
}); |
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
//GET to root | |
router.get('/logout', function(req, res, next) { | |
req.logout(function(err) { | |
if (err) { return next(err); } | |
res.redirect('/'); | |
}); | |
}); |
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
//file: index.js | |
if (argv.a && argv.c) { | |
addEntry([argv.c, argv.a]); | |
console.log("Added expense: ", argv.c, argv.a); | |
} |
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
const yargs = require("yargs/yargs"); | |
const { addEntry, getTotal, getParsedJSON } = require("./sheetUtils"); | |
const argv = yargs(process.argv.slice(2)) | |
.alias("a", "add-amount") | |
.describe("a", "Add new expense to the table") | |
.alias("-c", "-category") | |
.describe("c", "Type of expense") | |
.command("overview", "Get list of expenses:", () => { | |
console.log(getParsedJSON()); |
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
const xlsx = require("xlsx"); | |
const path = require("path"); | |
const fileLocation = path.join(__dirname, "Expenses.xlsx"); | |
const fileContents = xlsx.readFile(fileLocation); | |
const firstSheet = fileContents.SheetNames[0]; | |
const sheetValues = fileContents.Sheets[firstSheet]; | |
const parsedJSON = xlsx.utils.sheet_to_json(sheetValues); |
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
function getTotal() { | |
const allData = getParsedJSON(); | |
const totalResult = allData | |
.map((item) => item.Amount) | |
.reduce((acc, a) => acc + a, 0); | |
return totalResult; | |
} | |
console.log("Current total ", getTotal()); | |
module.exports = { getParsedJSON, addEntry, getTotal }; |
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
function addEntry(text) { | |
xlsx.utils.sheet_add_aoa(sheetValues, [text], { origin: -1 }); //the 'origin' property tells Node to append the entry to the next available row | |
xlsx.writeFile(fileContents, fileLocation); | |
} | |
addEntry(["Cake for girlfriend's birthday", 30]); |
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
const xlsx = require("xlsx"); | |
const path = require("path"); | |
const fileLocation = path.join(__dirname, "Expenses.xlsx"); | |
const fileContents = xlsx.readFile(fileLocation); | |
const firstSheet = fileContents.SheetNames[0]; | |
const sheetValues = fileContents.Sheets[firstSheet]; | |
const parsedJSON = xlsx.utils.sheet_to_json(sheetValues); |
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
//your error is at Line 76 (getTodoByID function) | |
//........ item.ts......... // | |
class Item { | |
//remember to add field declarations: | |
//https://www.typescriptlang.org/docs/handbook/2/classes.html#fields | |
taskId: number; | |
task: String; | |
done: boolean; | |
public constructor(taskId: number, task: String, done: boolean = false) { | |
this.taskId = taskId; |
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
const sharp = require("sharp"); | |
function createImage(color) { | |
sharp({ | |
create: { | |
width: 100, | |
height: 200, | |
channels: 4, | |
background: `#${color}`, | |
}, |
NewerOlder