This file contains hidden or 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 = { | |
| schema, | |
| getById(userId) { | |
| return db.models.User.findById(userId) | |
| }, | |
| async register(userData) { | |
| log.info({ email: userData.email }, 'Registering user.') |
This file contains hidden or 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 methods = { | |
| generalError: (err, res) => { | |
| const data = err.code ? undefined : err.message; | |
| const code = err.code || 500; | |
| return res.status(201).json({ | |
| status: code, | |
| message: err.msg || "An error has ocurred, try again", | |
| data | |
| }); | |
| }, |
This file contains hidden or 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 db = require('../util/mongoose'); | |
| module.exports = { | |
| create: async data => { | |
| const { name, email, role, password } = data; | |
| const item = new db.User({ name, email, role, password }); | |
| return await item.save(); | |
| }, | |
| update: async (id, data) => { | |
| const { name, email, role, password } = data; |
This file contains hidden or 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
| ะะตัะตะนะดะธัะต ะบ ะฝะฐัััะพะนะบะต ะธ ะดะพะฑะฐะฒััะต ัะฒะพะน ัะธััะตะผะฝัะน IP-ะฐะดัะตั ะฒ ัะฐะทะดะตะป ะฑะตะปะพะณะพ ัะฟะธัะบะฐ. ะ ะตัะตะฝะพ. |
This file contains hidden or 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
| // Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/ | |
| // Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch | |
| // async function | |
| async function fetchAsync () { | |
| // await response of fetch call | |
| let response = await fetch('https://api.github.com'); | |
| // only proceed once promise is resolved | |
| let data = await response.json(); | |
| // only proceed once second promise is resolved |
This file contains hidden or 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
| /* | |
| TRIES | |
| A trie (or radix tree) is a simple data structure that represents a set of values stored against a | |
| tokenizable key (usually strings). Each edge in a Trie represents a token in a key. A key is present in the trie if | |
| (1) There exists a path (e1..en) from the root such that the key = <token(e1), token(e2)...token(en)> and | |
| (2) there is some value at the path's terminal vertex vn. | |
| Let k = length(key). Then time complexity for lookup, insertion and deletion for a Trie is O(k). |
This file contains hidden or 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
| /* Class representing a Trie data structure */ | |
| export default class Trie { | |
| /** | |
| * Creates a Trie | |
| * @return {Object} Trie | |
| */ | |
| constructor() { | |
| this.words = 0; | |
| this.prefixes = 0; |
This file contains hidden or 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
| class Observer { | |
| subscribe(subscriber) { | |
| this.subscribers.push(subscriber); | |
| } | |
| publish(event, data) { | |
| let query = this.subscribers.filter(subscriber => subscriber.event === event); | |
| if (query.length) query.forEach(subscriber => subscriber.action(data)); | |
| } | |
| constructor() { | |
| this.subscribers = []; |
This file contains hidden or 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 createStore(reducer) { | |
| var state; | |
| var listeners = [] | |
| function getState() { | |
| return state | |
| } | |
| function subscribe(listener) { | |
| listeners.push(listener) |
This file contains hidden or 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 compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))) | |
| // Usage : compose functions right to left | |
| // compose(minus8, add10, multiply10)(4) === 42 | |
| // | |
| // The resulting function can accept as many arguments as the first function does | |
| // compose(add2, multiply)(4, 10) === 42 |