diff --git a/modules/hudozka-api/src/controllers/person.ts b/modules/hudozka-api/src/controllers/person.ts deleted file mode 100644 index 605947df..00000000 --- a/modules/hudozka-api/src/controllers/person.ts +++ /dev/null @@ -1,60 +0,0 @@ -import Teacher from '../core/Teacher' -import { encodePerson } from '../factory/person' -import { Request, Response } from 'express' -import { prioritySort } from '../lib/sort' - -export async function getItem(req: Request, res: Response) { - const id = req.params.slug - const data = await Teacher.findById(id) - - if (data) { - res.json(encodePerson(data)) - } else { - res.status(404) - res.json({ - error: `Resource ${id} not found` - }) - } -} - -export async function getAll(req: Request, res: Response) { - const order = [ - 'mg-timasheva', - 'va-sarzhin', - 'od-gogoleva', - 'my-valkova', - 'nv-andreeva', - 'vv-voronova', - ] - const teachersSorted = prioritySort.bind(null, [...order], t => t.id) - - const teachers = await Teacher.find({ hidden: false }) - const data = teachersSorted(teachers).map(encodePerson) - - if (data) { - res.json({ - items: data, - }) - } else { - res.status(404) - res.json({ - error: `Not found` - }) - } -} - -export async function getUrls(req: Request, res: Response) { - const data = await Teacher.find({}) - - if (data) { - const items = data.map(x => `/teacher/${x.id}`) - res.json({ - items - }) - } else { - res.status(404) - res.json({ - error: `Not found` - }) - } -} diff --git a/modules/hudozka-api/src/core/Config.ts b/modules/hudozka-api/src/core/Config.ts index db3188ff..086d6c23 100644 --- a/modules/hudozka-api/src/core/Config.ts +++ b/modules/hudozka-api/src/core/Config.ts @@ -20,7 +20,6 @@ export default class Config { public file: any public server: any public articlesPerPage: any - public collectiveOrder: any public articleCardDefaultPreview: any public collectiveImage: any public redirect: any @@ -30,7 +29,6 @@ export default class Config { this.file = file this.server = data.server this.articlesPerPage = data.articlesPerPage || 5 - this.collectiveOrder = data.collectiveOrder || [] this.articleCardDefaultPreview = data.articleCardDefaultPreview this.collectiveImage = data.collectiveImage diff --git a/modules/hudozka-api/src/core/Teacher.ts b/modules/hudozka-api/src/core/Teacher.ts deleted file mode 100644 index 582ec73f..00000000 --- a/modules/hudozka-api/src/core/Teacher.ts +++ /dev/null @@ -1,87 +0,0 @@ -import Data from './Data' -import Image from './Image' -import { find, findOne } from '../lib/store' - -const store = () => Data.getStore('Teacher') - -export default class Teacher { - static async find(query, options = {}): Promise { - const items = await find(store(), query, options as any) - - return Promise.all(items.map(processProfile)) - } - - static async findById(id) { - const data = await findOne(store(), { id }) - if (!data) return null - - return processProfile(data) - } - - public id: any - public post: any - public file: any - public edu: any - public picture: any - public preview: any - public diploma: any - public position: any - public name: any - public status: any - public hash: any - public url: any - - 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}` - } - - /** - * - * "First Middle Last" -> "F. M. Last" - * - * @returns {string} - */ - shortName() { - const f = i => i.replace(/^(.).+/, '$1') - const [first, middle, last] = this.splitName() - - return `${f(first)}. ${f(middle)}. ${last}` - } - - /** - * - * "First Middle Last" -> ["First", "Middle", "Last"] - * - * @returns {Array|{index: number, input: string}} - */ - 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) - - return new Teacher({ - ...profile, - picture, - preview, - }) -} diff --git a/modules/hudozka-api/src/core/pages.js b/modules/hudozka-api/src/core/pages.js deleted file mode 100644 index b140f10f..00000000 --- a/modules/hudozka-api/src/core/pages.js +++ /dev/null @@ -1,19 +0,0 @@ -import {c} from '../core/db'; - -const PAGES = 'pages'; - -export async function getPageUrls() { - return await c(PAGES) - .find({}, {url: 1}) - .toArray(); -} - -/** - * Find a person by it's id - * - * @param {string} url - * @returns {Promise|*} - */ -export async function getPage(url) { - return await c(PAGES).findOne({url: url}); -} diff --git a/modules/hudozka-api/src/db.ts b/modules/hudozka-api/src/db.ts index 048e2813..bd3705e4 100644 --- a/modules/hudozka-api/src/db.ts +++ b/modules/hudozka-api/src/db.ts @@ -30,7 +30,6 @@ function init(db: Db) { Data.setStore('Article', db.collection('articles')) Data.setStore('Album', db.collection('albums')) Data.setStore('Image', db.collection('images')) - Data.setStore('Teacher', db.collection('collective')) Data.setStore('Document', db.collection('documents')) Data.setStore('Settings', db.collection('settings')) diff --git a/modules/hudozka-api/src/factory/person.ts b/modules/hudozka-api/src/factory/person.ts deleted file mode 100644 index 21d6f410..00000000 --- a/modules/hudozka-api/src/factory/person.ts +++ /dev/null @@ -1,13 +0,0 @@ -import ImageArtifactType from '../core/ImageArtifactType' -import { encodeImage } from './image' -const profilePicture = profile => profile.picture.getPicture(ImageArtifactType.BIG) - -export function encodePerson(person) { - return { - ...person, - shortName: person.shortName(), - name: person.splitName(), - picture: profilePicture(person), - preview: encodeImage(person.picture), - } -} \ No newline at end of file diff --git a/modules/hudozka-api/src/lib/sort.js b/modules/hudozka-api/src/lib/sort.js index 3fa95c00..e1287244 100644 --- a/modules/hudozka-api/src/lib/sort.js +++ b/modules/hudozka-api/src/lib/sort.js @@ -1,17 +1,3 @@ -function prioritySort(priority, key, list) { - priority = priority.reverse() - - let weight = i => { - const p = key(i) - const index = priority.indexOf(p) - return index > -1 - ? index + 1 - : 0 - } - - return sort(list, weight) -} - function sort(list, fn, reverse = false) { return list .map(i => [fn(i), i]) @@ -32,6 +18,5 @@ function sortBy(fn, reverse = false) { } } -exports.prioritySort = prioritySort exports.sortBy = sortBy exports.sort = sort diff --git a/modules/hudozka-api/src/server.ts b/modules/hudozka-api/src/server.ts index e6a335a7..5d6f28f6 100644 --- a/modules/hudozka-api/src/server.ts +++ b/modules/hudozka-api/src/server.ts @@ -1,7 +1,6 @@ import { config } from 'dotenv' import express from 'express' import { connect } from './db' -import * as person from './controllers/person' import * as article from './controllers/article' import * as album from './controllers/album' import * as schedule from './controllers/schedule' @@ -25,10 +24,6 @@ async function main() { } const app = express() - app.get('/persons', person.getAll) - app.get('/persons/urls', person.getUrls) - app.get('/persons/:slug', person.getItem) - app.get('/articles', article.getAll) app.get('/articles/urls', article.getUrls) app.get('/articles/:slug', article.getItem) diff --git a/modules/hudozka-api/src/server/collective.js b/modules/hudozka-api/src/server/collective.js deleted file mode 100644 index 98dfb699..00000000 --- a/modules/hudozka-api/src/server/collective.js +++ /dev/null @@ -1,18 +0,0 @@ -const { collection } = require('../db') -// import { collection } from '../core/db' - -export async function getCollective(query = {}) { - return await collection('collective') - .find(query) - .toArray(); -} - -/** - * Find a person by it's id - * - * @param id - * @returns {Promise|*} - */ -export async function getPerson(id) { - return await collection('collective').findOne({ id: id }); -} diff --git a/modules/hudozka-api/src/server/schedule.ts b/modules/hudozka-api/src/server/schedule.ts index f7b07a1b..ad4cef12 100644 --- a/modules/hudozka-api/src/server/schedule.ts +++ b/modules/hudozka-api/src/server/schedule.ts @@ -1,5 +1,4 @@ import { createMap } from '../utils/common' -import { getCollective } from './collective' import { scheduleDate, getPeriod as schedulePeriod, @@ -96,7 +95,7 @@ function migrate10to20(schedule) { async function migrate20to30(schedule) { const days = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat']//, 'sun'] - const persons = await getCollective() + const persons = [] const person = createMap(i => i.id, persons) const week = week => days