app moved to next.js

This commit is contained in:
tmshv committed 2019-08-01 14:44:25 +03:00
1 parent dcca513aea
commit 43af2996bf
48 files changed
+1147 -1027

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
import { dbUri } from '../../../src/config'
import { connect } from '../../../src/core/db'
import Album from '../../../src/core/Album'
export default async (req, res) => {
await connect(dbUri)
const id = req.query.album
const album = await Album.findById(id)
if (album) {
res.json(album)
} else {
res.status(404)
res.json({
error: `Album ${id} not found`
})
}
}
+19
View File
@@ -0,0 +1,19 @@
import { dbUri } from '../../../src/config'
import { connect } from '../../../src/core/db'
import Album from '../../../src/core/Album'
export default async (req, res) => {
await connect(dbUri)
const data = await Album.find({}, { sort: { date: -1 } })
if (data) {
res.json({
items: data,
})
} else {
res.status(404)
res.json({
error: `Article not found`
})
}
}
+22
View File
@@ -0,0 +1,22 @@
import { dbUri } from '../../../src/config'
import { connect } from '../../../src/core/db'
import Article from '../../../src/core/Article'
export default async (req, res) => {
await connect(dbUri)
const {
query: { article: id }
} = req;
const article = await Article.findById(id)
if (article) {
res.json(article)
} else {
res.status(404)
res.json({
error: `Article ${id} not found`
})
}
}
+22
View File
@@ -0,0 +1,22 @@
import { dbUri } from '../../../src/config'
import { connect } from '../../../src/core/db'
import { findArticles } from '../../../src/api/articles'
export default async (req, res) => {
await connect(dbUri)
const { query } = req
const page = parseInt(query.page)
const pageSize = parseInt(query.pageSize)
const data = await findArticles(page, pageSize)
if (data) {
res.json(data)
} else {
res.status(404)
res.json({
error: `Article ${id} not found`
})
}
}
+20
View File
@@ -0,0 +1,20 @@
import { dbUri } from '../../../src/config'
import { connect } from '../../../src/core/db'
import Document from '../../../src/core/Document'
import { encodeFile } from '../../../src/api/files'
export default async (req, res) => {
await connect(dbUri)
const id = req.query.document
const document = await Document.findById(id)
if (document) {
res.json(encodeFile(document))
} else {
res.status(404)
res.json({
error: `Document ${id} not found`
})
}
}
+24
View File
@@ -0,0 +1,24 @@
import { dbUri } from '../../../src/config'
import { connect } from '../../../src/core/db'
import Document from '../../../src/core/Document'
import { encodeFile } from '../../../src/api/files'
export default async (req, res) => {
await connect(dbUri)
const documents = await Document.find({hidden: false})
if (documents) {
const items = documents
.map(encodeFile)
.filter(x => x.imageUrl) // skip documents without preview image; needs to be refactored
res.json({
items,
})
} else {
res.status(404)
res.json({
error: `Documents not found`
})
}
}
+21
View File
@@ -0,0 +1,21 @@
import { dbUri } from '../../src/config'
import { connect } from '../../src/core/db'
import Image from '../../src/core/Image'
import ImageArtifactType from '../../src/core/ImageArtifactType'
export default async (req, res) => {
await connect(dbUri)
const file = req.query.file
const image = await Image.findByFile(file)
if (image) {
const data = image.getPicture(ImageArtifactType.LARGE)
res.json(data)
} else {
res.status(404)
res.json({
error: `Image ${file} not found`
})
}
}
+26
View File
@@ -0,0 +1,26 @@
import { dbUri } from '../../src/config'
import { connect } from '../../src/core/db'
import Page from '../../src/core/Page'
import { getPathWithNoTrailingSlash } from '../../src/lib/url'
export default async (req, res) => {
await connect(dbUri)
const page = getPathWithNoTrailingSlash(req.query.page)
const resource = await Page.findByUrl(page)
if (resource) {
res.json({
id: resource.id,
title: resource.title,
url: resource.url,
data: resource.data,
preview: resource.preview,
})
} else {
res.status(404)
res.json({
error: `Image ${page} not found`
})
}
}
+21
View File
@@ -0,0 +1,21 @@
import { dbUri } from '../../../src/config'
import { connect } from '../../../src/core/db'
import Teacher from '../../../src/core/Teacher'
import { encodePerson } from '../../../src/api/persons'
export default async (req, res) => {
await connect(dbUri)
const id = req.query.person
const person = await Teacher.findById(id)
const data = encodePerson(person)
if (data) {
res.json(data)
} else {
res.status(404)
res.json({
error: `Article ${id} not found`
})
}
}
+33
View File
@@ -0,0 +1,33 @@
import { dbUri } from '../../../src/config'
import { connect } from '../../../src/core/db'
import Teacher from '../../../src/core/Teacher'
import { prioritySort } from '../../../src/lib/sort'
import { encodePerson } from '../../../src/api/persons'
export default async (req, res) => {
await connect(dbUri)
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: `Article ${id} not found`
})
}
}
+20
View File
@@ -0,0 +1,20 @@
import { dbUri } from '../../src/config'
import { connect } from '../../src/core/db'
import { findSchedule } from '../../src/core/schedule'
export default async (req, res) => {
await connect(dbUri)
const period = req.query.period
const semester = req.query.semester
const data = await findSchedule(period, semester)
if (data) {
res.json(data)
} else {
res.status(404)
res.json({
error: `Schedule ${period}:${semester} not found`
})
}
}