61 lines
1.0 KiB
TypeScript
61 lines
1.0 KiB
TypeScript
import express from 'express';
|
|
|
|
import Article from './../models/article';
|
|
import Tag from './../models/tag';
|
|
|
|
import {authorize} from './../auth';
|
|
|
|
/* eslint-disable */
|
|
const router = express.Router();
|
|
/* eslint-enable */
|
|
|
|
router.delete('/signout', async (_req, res) => {
|
|
res.cookie('accessToken', '', {expires: new Date()});
|
|
res.sendStatus(204);
|
|
});
|
|
|
|
router.get('/articles/:page', async (req, res) => {
|
|
const articles = await Article.findAll({
|
|
attributes: [
|
|
'title',
|
|
'createdAt',
|
|
'sanitizedHtml',
|
|
],
|
|
include: [{
|
|
model: Tag,
|
|
attributes: [
|
|
'name',
|
|
],
|
|
}],
|
|
order: [
|
|
['createdAt', 'DESC'],
|
|
],
|
|
limit: 10,
|
|
offset: parseInt(req.params.page) * 10,
|
|
});
|
|
res.send(articles);
|
|
});
|
|
|
|
router.get('/articletable', authorize, async (_req, res) => {
|
|
const articles = await Article.findAll({
|
|
attributes: [
|
|
'id',
|
|
'title',
|
|
'createdAt',
|
|
'updatedAt',
|
|
],
|
|
include: [{
|
|
model: Tag,
|
|
attributes: [
|
|
'name',
|
|
],
|
|
}],
|
|
order: [
|
|
['updatedAt', 'DESC'],
|
|
],
|
|
});
|
|
res.send(articles);
|
|
});
|
|
|
|
export default router;
|