File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,8 +32,11 @@ export default class PageService {
3232 } )
3333
3434 this . db . ensureIndex ( {
35- fieldName : 'route' ,
36- unique : true
35+ fieldName : 'app'
36+ } )
37+
38+ this . db . ensureIndex ( {
39+ fieldName : 'route'
3740 } )
3841
3942 this . userInfo = {
@@ -80,6 +83,23 @@ export default class PageService {
8083 const model = params . isPage ? this . pageModel : this . folderModel
8184 const pageData = { ...model , ...params }
8285
86+ if ( ! pageData . route ) {
87+ pageData . route = pageData . name || 'Untitled'
88+ }
89+
90+ const existing = await this . db . findOneAsync ( {
91+ app : pageData . app . toString ( ) ,
92+ route : pageData . route
93+ } )
94+
95+ if ( existing ) {
96+ return getResponseData ( null , {
97+ code : 'ROUTE_CONFLICT' ,
98+ message : `Route "${ pageData . route } " already exists in app "${ pageData . app } "` ,
99+ status : 409
100+ } )
101+ }
102+
83103 if ( pageData . page_content && typeof pageData . page_content === 'object' ) {
84104 pageData . page_content = JSON . stringify ( pageData . page_content )
85105 }
@@ -112,11 +132,13 @@ export default class PageService {
112132
113133 async detail ( pageId ) {
114134 const result = await this . db . findOneAsync ( { _id : pageId } )
135+
115136 return getResponseData ( parsePageContent ( result ) )
116137 }
117138
118139 async delete ( pageId ) {
119140 const result = await this . db . findOneAsync ( { _id : pageId } )
141+
120142 await this . db . removeAsync ( { _id : pageId } )
121143 return getResponseData ( parsePageContent ( result ) )
122144 }
You can’t perform that action at this time.
0 commit comments