fix: prevent empty page content
This commit is contained in:
parent
518602b0d4
commit
1d8f1f50e1
@ -125,6 +125,10 @@ module.exports = {
|
|||||||
message: 'Cannot create this page because an entry already exists at the same path.',
|
message: 'Cannot create this page because an entry already exists at the same path.',
|
||||||
code: 6002
|
code: 6002
|
||||||
}),
|
}),
|
||||||
|
PageEmptyContent: CustomError('PageEmptyContent', {
|
||||||
|
message: 'Page content cannot be empty.',
|
||||||
|
code: 6004
|
||||||
|
}),
|
||||||
PageNotFound: CustomError('PageNotFound', {
|
PageNotFound: CustomError('PageNotFound', {
|
||||||
message: 'This page does not exist.',
|
message: 'This page does not exist.',
|
||||||
code: 6003
|
code: 6003
|
||||||
|
@ -182,6 +182,10 @@ module.exports = class Page extends Model {
|
|||||||
throw new WIKI.Error.PageDuplicateCreate()
|
throw new WIKI.Error.PageDuplicateCreate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!opts.content || _.trim(opts.content).length < 1) {
|
||||||
|
throw new WIKI.Error.PageEmptyContent()
|
||||||
|
}
|
||||||
|
|
||||||
await WIKI.models.pages.query().insert({
|
await WIKI.models.pages.query().insert({
|
||||||
authorId: opts.authorId,
|
authorId: opts.authorId,
|
||||||
content: opts.content,
|
content: opts.content,
|
||||||
@ -230,6 +234,11 @@ module.exports = class Page extends Model {
|
|||||||
if (!ogPage) {
|
if (!ogPage) {
|
||||||
throw new Error('Invalid Page Id')
|
throw new Error('Invalid Page Id')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!opts.content || _.trim(opts.content).length < 1) {
|
||||||
|
throw new WIKI.Error.PageEmptyContent()
|
||||||
|
}
|
||||||
|
|
||||||
await WIKI.models.pageHistory.addVersion({
|
await WIKI.models.pageHistory.addVersion({
|
||||||
...ogPage,
|
...ogPage,
|
||||||
isPublished: ogPage.isPublished === true || ogPage.isPublished === 1,
|
isPublished: ogPage.isPublished === true || ogPage.isPublished === 1,
|
||||||
|
Loading…
Reference in New Issue
Block a user