Add api for page deletion

This commit is contained in:
QiTao Weng 2022-04-10 04:58:47 -05:00
parent c61a447592
commit e81a3d3874
2 changed files with 24 additions and 0 deletions

View File

@ -68,4 +68,25 @@ export class EditorPage extends Controller {
await page.save()
return api.one(page)
}
public async delete() {
// Check if page_id is specified
const serialData = this.request.safe('serialData').string()
const pageId = String(this.request.input('pageId') ?? '')
// If so, look it up and update it
if ( pageId ) {
const page = await Page.query<Page>()
.whereKey(parseInt(pageId, 10))
.where('user_id', '=', this.security.user().getUniqueIdentifier())
.first()
if ( !page ) {
return api.error('Invalid pageId.')
}
page.serialData = serialData
await page.delete()
}
}
}

View File

@ -22,6 +22,9 @@ Route.group('/', () => {
Route.get('/pages')
.calls<EditorPage>(EditorPage, page => page.list)
Route.delete('page')
.calls<EditorPage>(EditorPage, page => page.delete)
}).pre(AuthRequiredMiddleware)
Route.group('/login', () => {