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 otpGenerator = require("otp-generator"); | |
const crypto = require("crypto"); | |
const key = "verysecretkey"; // Key for cryptograpy. Keep it secret | |
function createNewOTP(phone){ | |
// Generate a 6 digit numeric OTP | |
const otp = otpGenerator.generate(6, {alphabets: false, upperCase: false, specialChars: false}); | |
const ttl = 5 * 60 * 1000; //5 Minutes in miliseconds | |
const expires = Date.now() + ttl; //timestamp to 5 minutes in the future | |
const data = `${phone}.${otp}.${expires}`; // phone.otp.expiry_timestamp |
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
-- Import(FROM) / Export(TO) CSV file from/into a table | |
-- Ref: https://www.postgresql.org/docs/current/sql-copy.html | |
-- If processing all columns, no need column specification | |
-- If CSV file don't include header, remove 'HEADER' from below query | |
-- For Export, can also specify Query, instead of Table & Column name | |
COPY table_name (column_1, column_2, column_3, column_5) | |
[FROM/TO] 'csv_file_location' DELIMITER ',' CSV HEADER QUOTE '"' ESCAPE '"' | |
-- Dump database on remote host to file | |
-- Ref: https://www.postgresql.org/docs/current/app-pgdump.html |
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
/** | |
* Query blog posts by user -> paginated results and a total count. | |
* @param userId {ObjectId} ID of user to retrieve blog posts for | |
* @param startRow {Number} First row to return in results | |
* @param endRow {Number} Last row to return in results | |
* @param [filter] {Object} Optional extra matching query object | |
* @param [sort] {Object} Optional sort query object | |
* @returns {Object} Object -> `{ rows, count }` | |
*/ | |
function queryBlogPostsByUser (userId, startRow, endRow, filter = {}, sort = false) { |