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 env file | |
require('dotenv').config(); | |
const express = require('express'); | |
const path = require('path'); | |
const fs = require('fs'); | |
const app = express(); | |
const { keepAwake } = require('./src/util/heroku_util'); | |
const { setQuoteEvent } = require('./src/controllers/quoteController'); | |
const { start } = require('./src/consumers/scrapQuoteConsumer'); |
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 rp = require('request-promise'); | |
const $ = require('cheerio'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const quotesFilePath = path.join(process.cwd(), 'public', 'quotes.json'); | |
const url = 'http://wisdomquotes.com/stoic-quotes/'; | |
// Quote Event Req | |
let quoteEventReq = []; | |
let quoteEventRes = []; |
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 twilio = require('twilio'); | |
// Twilio Client | |
let client; | |
/** | |
* Initialize Client Connection with Twilio | |
*/ | |
const initClient = () => { |
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
exports.sendQuoteViaWhatsapp = async (req, res) => { | |
console.log('sendQuoteViaWhatsapp'); | |
const { mobileNo } = req.body; | |
try { | |
const quote = await this.scrapQuoteOfTheDay(); | |
const msg = await sendWhatsappMessage({ mobileNo, quote }); | |
res.json({ msg }); | |
} catch (err) { | |
console.error('scrap quote error', err); | |
res.status(400).json({ error: err.message }); |
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 mongoose = require('mongoose'); | |
// Create a simple User's schema | |
const userSchema = new mongoose.Schema({ | |
name: { type: String, required: true}, | |
gender: { type: String, required: true}, | |
dob: Date, | |
loginUsing: String, | |
}); |
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
module.exports = { | |
preset: '@shelf/jest-mongodb', | |
}; |
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
module.exports = { | |
mongodbMemoryServerOptions: { | |
instance: { | |
dbName: 'jest' | |
}, | |
binary: { | |
version: '4.0.2', // Version of MongoDB | |
skipMD5: true | |
}, | |
autoStart: false |
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 mongoose = require('mongoose'); | |
const UserModel = require('../../src/models/user'); | |
const userData = { name: 'TekLoon', gender: 'Male', dob: new Date(), loginUsing: 'Facebook' }; | |
describe('User Model Test', () => { | |
// It's just so easy to connect to the MongoDB Memory Server | |
// By using mongoose.connect | |
beforeAll(async () => { | |
await mongoose.connect(global.__MONGO_URI__, { useNewUrlParser: true, useCreateIndex: true }, (err) => { |
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 airRouteModel = require('../models/air_routes'); | |
exports.searchFlight = async (req, res, next) => { | |
const { from, to } = req.body; | |
try { | |
// Return routes with matching origin and destination | |
const result = await airRouteModel.aggregate([ | |
// Filter air routes based on origin and destination | |
{ | |
$match: { |
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
{ | |
"data": [ | |
{ | |
"airline": { | |
"id": 2417, | |
"name": "AirAsia X", | |
"alias": "D7", | |
"iata": "XAX" | |
}, | |
"src_airport": "KUL", |