-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
14,654 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#@name create | ||
|
||
POST {{baseURL}}{{contentPath}}/article HTTP/1.1 | ||
|
||
{ | ||
"title": "test", | ||
"allow_comment": true, | ||
"content": "", | ||
"abstract": "", | ||
"password": "", | ||
"thumbnail": "", | ||
"category": "", | ||
"tags": "", | ||
} | ||
|
||
### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#@name create | ||
|
||
POST {{baseURL}}/register HTTP/1.1 | ||
|
||
{ | ||
"user": "" | ||
} | ||
|
||
### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
const models = require('../../config/db/model') | ||
const Sequelize = require('sequelize') | ||
|
||
exports.create = { | ||
title: { | ||
in: ['body'], | ||
isString: { | ||
errorMessage: "文章标题必须是字符串" | ||
}, | ||
notEmpty: { | ||
errorMessage: "文章标题不能为空" | ||
}, | ||
}, | ||
allow_comment: { | ||
in: ['body'], | ||
custom: { | ||
options: (val, {req, location, path}) => { | ||
if (val !== '0' && val !== '1') { | ||
throw new Error('是否允许评论参数错误') | ||
} | ||
return true | ||
} | ||
} | ||
}, | ||
content: { | ||
in: ['body'], | ||
isString: { | ||
errorMessage: "文章内容必须是字符串" | ||
}, | ||
notEmpty: { | ||
errorMessage: "文章内容不能为空" | ||
}, | ||
}, | ||
abstract: { | ||
in: ['body'], | ||
isString: { | ||
errorMessage: "文章摘要必须是字符串" | ||
}, | ||
notEmpty: { | ||
errorMessage: "文章摘要不能为空" | ||
}, | ||
}, | ||
password: { | ||
|
||
}, | ||
thumbnail: { | ||
in: ['body'], | ||
isString: { | ||
errorMessage: "文章密码必须是字符串" | ||
} | ||
}, | ||
category: { | ||
custom: { | ||
options: (val, {req, location, path}) => { | ||
if (val) { | ||
return models.Category.findUserCategories(req.user.id, { | ||
id: { | ||
[Sequelize.Op.in]: val | ||
} | ||
}).then(categories => { | ||
let unExistedCategories = val.filter(el => categories.findIndex(t => t.id === el) === -1) | ||
if (unExistedCategories.length) { | ||
return Promise.reject(`分类${unExistedCategories.join(',')}不存在`) | ||
} else { | ||
return true | ||
} | ||
}) | ||
} | ||
return true | ||
} | ||
} | ||
}, | ||
'tags': { | ||
in: ['body'], | ||
isArray: { | ||
errorMessage: "文章标签必须是标签数组" | ||
}, | ||
custom: { | ||
options: (val, {req, location, path}) => { | ||
if (val.length) { | ||
return models.Tag.findUserTags(req.user.id, { | ||
id: { | ||
[Sequelize.Op.in]: val | ||
} | ||
}).then(tags => { | ||
let unExistedTags = val.filter(el => tags.findIndex(t => t.id === el) === -1) | ||
if (unExistedTags.length) { | ||
return Promise.reject(`标签${unExistedTags.join(',')}不存在`) | ||
} else { | ||
return true | ||
} | ||
}) | ||
} | ||
return true | ||
} | ||
} | ||
}, | ||
} | ||
|
||
exports.update = { | ||
...exports.create, | ||
id: { | ||
in: ['body'], | ||
custom: { | ||
options: (val, {req, location, path}) => { | ||
if (val) { | ||
return models.Article.queryUserArticle(req.user.id, val) | ||
.then(a => { | ||
if (!a) { | ||
return Promise.reject(`文章不存在`) | ||
} else { | ||
return true | ||
} | ||
}) | ||
} | ||
throw new Error('请传入文章 id') | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exports.create = { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.