mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-08 06:55:26 +02:00
Moved alias types to model
This commit is contained in:
parent
91f78521a0
commit
83d3a4f117
5 changed files with 21 additions and 14 deletions
|
@ -1,3 +0,0 @@
|
|||
module.exports = {
|
||||
PAGE: 'page'
|
||||
};
|
|
@ -1,6 +1,5 @@
|
|||
const Model = require('../models/page');
|
||||
const Alias = require('../models/alias');
|
||||
const aliasTypes = require('../constants/aliasTypes');
|
||||
|
||||
/**
|
||||
* @class Pages
|
||||
|
@ -92,7 +91,7 @@ class Pages {
|
|||
if (insertedPage.uri) {
|
||||
const alias = new Alias({
|
||||
id: insertedPage._id,
|
||||
type: aliasTypes.PAGE
|
||||
type: Alias.types.PAGE
|
||||
}, insertedPage.uri);
|
||||
|
||||
alias.save();
|
||||
|
@ -162,7 +161,7 @@ class Pages {
|
|||
if (updatedPage.uri) {
|
||||
const alias = new Alias({
|
||||
id: updatedPage._id,
|
||||
type: aliasTypes.PAGE
|
||||
type: Alias.types.PAGE
|
||||
}, updatedPage.uri);
|
||||
|
||||
alias.save();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const {aliases: aliasesDb} = require('../utils/database/index');
|
||||
const binaryMD5 = require('../utils/crypto');
|
||||
|
||||
/**
|
||||
* @typedef {Object} AliasData
|
||||
* @property {string} _id - alias id
|
||||
|
@ -19,6 +20,17 @@ const binaryMD5 = require('../utils/crypto');
|
|||
* @property {string} id - entity title
|
||||
*/
|
||||
class Alias {
|
||||
/**
|
||||
* Return Alias types
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
static get types() {
|
||||
return {
|
||||
PAGE: 'page'
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Find and return alias with given alias
|
||||
* @param {string} aliasName - alias of entity
|
||||
|
|
|
@ -2,7 +2,7 @@ const express = require('express');
|
|||
const router = express.Router();
|
||||
const Aliases = require('../controllers/aliases');
|
||||
const Pages = require('../controllers/pages');
|
||||
const aliasTypes = require('../constants/aliasTypes');
|
||||
const Alias = require('../models/alias');
|
||||
|
||||
/**
|
||||
* GET /*
|
||||
|
@ -14,7 +14,7 @@ router.get('*', async (req, res) => {
|
|||
const alias = await Aliases.get(req.originalUrl.slice(1)); // Cuts first '/' character
|
||||
|
||||
switch (alias.type) {
|
||||
case aliasTypes.PAGE: {
|
||||
case Alias.types.PAGE: {
|
||||
let page = await Pages.get(alias.id);
|
||||
|
||||
let pageParent = await page.parent;
|
||||
|
|
|
@ -4,7 +4,6 @@ const path = require('path');
|
|||
const config = require('../../config');
|
||||
const Alias = require('../../src/models/alias');
|
||||
const binaryMD5 = require('../../src/utils/crypto');
|
||||
const aliasTypes = require('../../src/constants/aliasTypes');
|
||||
const {aliases} = require('../../src/utils/database');
|
||||
|
||||
describe('Alias model', () => {
|
||||
|
@ -41,7 +40,7 @@ describe('Alias model', () => {
|
|||
|
||||
const initialData = {
|
||||
_id: 'alias_id',
|
||||
type: aliasTypes.PAGE,
|
||||
type: Alias.types.PAGE,
|
||||
id: 'page_id'
|
||||
};
|
||||
const aliasName = 'alias name';
|
||||
|
@ -55,7 +54,7 @@ describe('Alias model', () => {
|
|||
expect(data.deprecated).to.equal(false);
|
||||
|
||||
const update = {
|
||||
type: aliasTypes.PAGE,
|
||||
type: Alias.types.PAGE,
|
||||
id: 'page_id',
|
||||
hash: binaryMD5('another test hash'),
|
||||
deprecated: true
|
||||
|
@ -73,7 +72,7 @@ describe('Alias model', () => {
|
|||
|
||||
it('Static get method', async () => {
|
||||
const initialData = {
|
||||
type: aliasTypes.PAGE,
|
||||
type: Alias.types.PAGE,
|
||||
id: 'page_id'
|
||||
};
|
||||
const aliasName = 'alias name';
|
||||
|
@ -94,7 +93,7 @@ describe('Alias model', () => {
|
|||
|
||||
it('Saving, updating and deleting model in the database', async () => {
|
||||
const initialData = {
|
||||
type: aliasTypes.PAGE,
|
||||
type: Alias.types.PAGE,
|
||||
id: 'page_id'
|
||||
};
|
||||
const aliasName = 'alias name';
|
||||
|
@ -118,7 +117,7 @@ describe('Alias model', () => {
|
|||
expect(insertedAlias.deprecated).to.equal(savedAlias.deprecated);
|
||||
|
||||
const updateData = {
|
||||
type: aliasTypes.PAGE,
|
||||
type: Alias.types.PAGE,
|
||||
id: 'page_id',
|
||||
hash: binaryMD5('another test hash'),
|
||||
deprecated: true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue