Skip to content

Instantly share code, notes, and snippets.

View HussainArif12's full-sized avatar
🏠
Working from home

Hussain Arif HussainArif12

🏠
Working from home
View GitHub Profile
//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");
});
//GET to root
router.get('/logout', function(req, res, next) {
req.logout(function(err) {
if (err) { return next(err); }
res.redirect('/');
});
});
//file: index.js
if (argv.a && argv.c) {
addEntry([argv.c, argv.a]);
console.log("Added expense: ", argv.c, argv.a);
}
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());
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);
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 };
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]);
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);
//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;
const sharp = require("sharp");
function createImage(color) {
sharp({
create: {
width: 100,
height: 200,
channels: 4,
background: `#${color}`,
},