From 4fc424b145a4932fc30ef771cad5a78dbbec9114 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 14 Oct 2019 17:14:45 +0300 Subject: [PATCH] core/Teacher format --- src/core/Teacher.js | 86 ++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/core/Teacher.js b/src/core/Teacher.js index 08883ba1..db6c66a3 100644 --- a/src/core/Teacher.js +++ b/src/core/Teacher.js @@ -1,38 +1,38 @@ const Data = require('./Data') const Image = require('./Image') -const {find, findOne} = require('../lib/store') +const { find, findOne } = require('../lib/store') const store = () => Data.getStore(Teacher) class Teacher { - static async find(query, options = {}) { - const items = await find(store(), query, options) + static async find(query, options = {}) { + const items = await find(store(), query, options) - return Promise.all(items.map(processProfile)) - } + return Promise.all(items.map(processProfile)) + } - static async findById(id) { - const data = await findOne(store(), {id}) - if (!data) return null + static async findById(id) { + const data = await findOne(store(), { id }) + if (!data) return null - return processProfile(data) - } + return processProfile(data) + } - constructor(data) { - this.id = data.id - this.post = data.post - this.file = data.file - this.edu = data.edu - this.picture = data.picture - this.preview = data.preview - this.diploma = data.diploma - this.position = data.position - this.name = data.name - this.status = data.status - this.hash = data.hash + constructor(data) { + this.id = data.id + this.post = data.post + this.file = data.file + this.edu = data.edu + this.picture = data.picture + this.preview = data.preview + this.diploma = data.diploma + this.position = data.position + this.name = data.name + this.status = data.status + this.hash = data.hash - this.url = `/teacher/${this.id}` - } + this.url = `/teacher/${this.id}` + } /** * @@ -40,12 +40,12 @@ class Teacher { * * @returns {string} */ - shortName() { - const f = i => i.replace(/^(.).+/, '$1') - const [first, middle, last] = this.splitName() + shortName() { + const f = i => i.replace(/^(.).+/, '$1') + const [first, middle, last] = this.splitName() - return `${f(first)}. ${f(middle)}. ${last}` - } + return `${f(first)}. ${f(middle)}. ${last}` + } /** * @@ -53,24 +53,24 @@ class Teacher { * * @returns {Array|{index: number, input: string}} */ - splitName() { - const name = this.name - const m = /(.+)\s(.+)\s(.+)/.exec(name) - return m.slice(1) - } + splitName() { + const name = this.name + const m = /(.+)\s(.+)\s(.+)/.exec(name) + return m.slice(1) + } } const processProfile = async profile => { - const imageId = profile.picture - const previewId = profile.preview - const picture = await Image.findById(imageId) - const preview = await Image.findById(previewId) + const imageId = profile.picture + const previewId = profile.preview + const picture = await Image.findById(imageId) + const preview = await Image.findById(previewId) - return new Teacher({ - ...profile, - picture, - preview, - }) + return new Teacher({ + ...profile, + picture, + preview, + }) } module.exports = Teacher