Skip to content

Commit

Permalink
Add ability to delete all comments for given path
Browse files Browse the repository at this point in the history
  • Loading branch information
slavoyar committed Oct 25, 2023
1 parent 96f93f7 commit 4205d0d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/src/en/reference/server/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,17 @@ POST /api/article
| Parameter | Type | Description |
| --------- | ------ | ---------------------- |
| path | string | Article id for comment |

### Delete article comments

Delete all comment for provided article path. If path is provided with '/' at the end then all comments that contains this path will be deleted. Otherwise comments where url fully match path will be deleted.

```http
DELETE /api/article
```

**Parameters**:

| Parameter | Type | Description |
| --------- | ------ | ---------------------- |
| path | string | Article id for comment |
11 changes: 11 additions & 0 deletions packages/server/src/controller/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,15 @@ module.exports = class extends BaseRest {

return this.jsonOrSuccess(deprecated ? ret[0][type] : [ret[0][type]]);
}

async deleteAction() {
let { path } = this.get();

// if last symbol is '/' than all children articles will be deleted
// otherwise only exactly matched
const where = path[path.length - 1] === '/' ? { url: ['like', `${path}%`] } : { url: path };
await this.getModel('Comment').delete(where);

return this.success();
}
};
11 changes: 11 additions & 0 deletions packages/server/src/logic/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,15 @@ module.exports = class extends Base {
},
};
}

deleteAction() {
const { path } = this.get();

this.rules = {
path: {
string: true,
required: !path,
}
}
}
};

0 comments on commit 4205d0d

Please sign in to comment.