async update(id, attrs) { //update data const records = awaitthis.getAll(); const record = records.find(record => record.id === id);
if (!record) { thrownewError(`Record with id ${id} not found`); } Object.assign(record, attrs); awaitthis.writeAll(records); }
async getOneBy(filters) { //filter data const records = awaitthis.getAll(); for (let record of records) { let found = true; for (let key in filters) { if (record[key] !== filters[key]) { found = false; } } if (found) { return record; } } } };
const fs = require('fs'); const crypto = require('crypto'); const util = require('util'); const Repository = require('./repository'); //require the base repo
const scrypt = util.promisify(crypto.scrypt);
classUsersRepositoryextendsRepository{ async comparePasswords(saved, supplied) { // Saved -> password saved in our database. 'hashed.salt' // Supplied -> password given to us by a user trying sign in const [hashed, salt] = saved.split('.'); const hashedSuppliedBuf = await scrypt(supplied, salt, 64);