api drop unused code

This commit is contained in:
tmshv committed 2020-03-03 01:33:17 +03:00
1 parent d859fdb302
commit 06745b45f4
26 files changed
+32 -788

No files matched your search

@@ -1,54 +0,0 @@
import Article from '../core/Article'
import { findArticles } from '../server/articles'
import { Request, Response } from 'express'
import { encodeArticle } from '../factory/article'
import { readQueryInt } from '../lib/url'
export async function getItem(req: Request, res: Response) {
const id = req.params.slug
const article = await Article.findById(id)
if (article) {
res.json(encodeArticle(article))
} else {
res.status(404)
res.json({
error: `Resource ${id} not found`
})
}
}
export async function getAll(req: Request, res: Response) {
const page = readQueryInt(req, 'page')
const pageSize = readQueryInt(req, 'pageSize')
const data = await findArticles(page, pageSize)
if (data) {
res.json({
...data,
items: data.items.map(encodeArticle)
})
} else {
res.status(404)
res.json({
error: `Articles not found`
})
}
}
export async function getUrls(req: Request, res: Response) {
const data = await Article.find({})
if (data) {
const items = data.map(x => `/article/${x.id}`)
res.json({
items
})
} else {
res.status(404)
res.json({
error: `Not found`
})
}
}
+4 -2
View File
@@ -10,8 +10,10 @@ function getSort(sortBy: string) {
}
if (sortBy.charAt(0) === '-') {
const key = sortBy.substr(1, sortBy.length)
return {
[sortBy.substr(1, sortBy.length)]: -1,
[key]: -1,
}
}
@@ -73,7 +75,7 @@ export async function getByTags(req: Request, res: Response) {
const options = { skip, limit, sort }
const models = await Page.find({
tags: { $in: ['event', 'album'] },
tags: { $in: tags },
}, options)
if (models) {
@@ -1,18 +0,0 @@
import { findSchedule } from '../server/schedule'
import { Request, Response } from 'express'
import { collection } from '../db'
export async function getItem(req: Request, res: Response) {
const period = req.query.period
const semester = req.query.semester
const data = await findSchedule(collection, period, semester)
if (data) {
res.json(data)
} else {
res.status(404)
res.json({
error: `Schedule ${period}:${semester} not found`
})
}
}
+3 -3
View File
@@ -1,9 +1,9 @@
import Article from '../core/Article'
import Page from '../core/Page'
import { Request, Response } from 'express'
import { unique } from '../lib/array'
export async function getAll(req: Request, res: Response) {
const data = await Article.find({})
const data = await Page.find({})
const tags = data
.flatMap(x => x.tags)
.filter(x => x.isValid())
@@ -24,7 +24,7 @@ export async function getAll(req: Request, res: Response) {
export async function findItems(req: Request, res: Response) {
const slug = req.params.slug
const data = await Article.find({
const data = await Page.find({
tags: {
}