mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-29 14:10:41 +03:00
Added undelete ways to api
This commit is contained in:
parent
79fa3d2e30
commit
14cf3b1237
5 changed files with 64 additions and 12 deletions
23
README.md
23
README.md
|
@ -31,6 +31,10 @@ And, you can learn about API in `util/APIDOCS.md`.
|
|||
|
||||
|
||||
## Roadmap
|
||||
### TO-DO:
|
||||
- If thread deleted, not show its messages in API.
|
||||
|
||||
### Frontend
|
||||
### User
|
||||
| To do | Is done? | Priority |
|
||||
| ----- | -------- | -------- |
|
||||
|
@ -66,16 +70,15 @@ And, you can learn about API in `util/APIDOCS.md`.
|
|||
| Edit | 🔴 | MEDIUM |
|
||||
|
||||
### API
|
||||
| To do | Is done? | Priority |
|
||||
| ----- | -------- | -------- |
|
||||
| RATELIMITS | 🟢 | MEDIUM |
|
||||
| Other clients for forum via API | 🟢 | LOW |
|
||||
| Get message**s** | 🟢 | MEDIUM |
|
||||
| Send message | 🟢 | MEDIUM |
|
||||
| Create thread | 🟢 | MEDIUM |
|
||||
| Get info about thread | 🟢 | MEDIUM |
|
||||
| Delete message & thread | 🟢 | HIGH |
|
||||
| Edit message & thread | 🔴 | HIGH |
|
||||
| To do | Is done?
|
||||
| ----- | --------
|
||||
| RATELIMITS | 🟢
|
||||
| Get message**s** | 🟢
|
||||
| Create message & thread & user | 🟢
|
||||
| Get message & thread & user | 🟢
|
||||
| Delete message & thread & user | 🟢
|
||||
| Undelete message & thread & user | 🟢
|
||||
| Edit message & thread & user | 🔴
|
||||
|
||||
### Other
|
||||
| To do | Is done? | Priority |
|
||||
|
|
|
@ -10,7 +10,7 @@ app.get("/:id", async (req, res) => {
|
|||
|
||||
const message = await MessageModel.get(req.params.id);
|
||||
|
||||
if (!message || (message.deleted && req.user && !req.user.admin)) return res.error(404, `We don't have any thread with id ${id}.`);
|
||||
if (!message || (message.deleted && req.user && !req.user.admin)) return res.error(404, `We don't have any message with id ${req.params.id}.`);
|
||||
|
||||
res.complate(message.toObject({ virtuals: true }));
|
||||
|
||||
|
@ -59,7 +59,8 @@ app.post("/:id/react/:type", async (req, res) => {
|
|||
|
||||
app.post("/:id/delete", async (req, res) => {
|
||||
const message = await MessageModel.get(req.params.id);
|
||||
if (!message || (message.deleted && req.user && !req.user.admin)) return res.error(404, "We have not got any message declared as this id.");
|
||||
if (!message || (message.deleted && req.user && !req.user.admin))
|
||||
return res.error(404, `We don't have any message with id ${req.params.id}.`);
|
||||
const user = req.user;
|
||||
if (user.id != message.authorID && !user.admin)
|
||||
return res.error(403, "You have not got permission for this.");
|
||||
|
@ -70,4 +71,20 @@ app.post("/:id/delete", async (req, res) => {
|
|||
|
||||
})
|
||||
|
||||
app.post("/:id/undelete", async (req, res) => {
|
||||
if (!req.user.admin) return res.error(403, "You have not got permission for this.");
|
||||
|
||||
const message = await MessageModel.get(req.params.id);
|
||||
|
||||
if (!message ) return res.error(404, `We don't have any message with id ${req.params.id}.`);
|
||||
|
||||
if (!message.deleted) return res.error(404, "This message is not deleted, first, delete it.");
|
||||
|
||||
message.deleted = false;
|
||||
await message.save();
|
||||
|
||||
res.complate(message.toObject({ virtuals: true }));
|
||||
|
||||
})
|
||||
|
||||
module.exports = app;
|
|
@ -65,5 +65,19 @@ app.post("/:id/delete", async (req, res) => {
|
|||
res.complate(thread.toObject({ virtuals: true }));
|
||||
|
||||
})
|
||||
app.post("/:id/undelete", async (req, res) => {
|
||||
if (!req.user.admin) return res.error(403, "You have not got permission for this.");
|
||||
|
||||
const thread = await ThreadModel.get(req.params.id);
|
||||
|
||||
if (!thread ) return res.error(404, `We don't have any thread with id ${req.params.id}.`);
|
||||
|
||||
if (!thread.deleted) return res.error(404, "This thread is not deleted, first, delete it.");
|
||||
|
||||
thread.deleted = false;
|
||||
await thread.save();
|
||||
|
||||
res.complate(thread.toObject({ virtuals: true }));
|
||||
|
||||
})
|
||||
module.exports = app;
|
|
@ -29,6 +29,21 @@ app.post("/:id/delete/", async (req, res) => {
|
|||
|
||||
res.complate(member);
|
||||
});
|
||||
app.post("/:id/undelete/", async (req, res) => {
|
||||
if (!req.user.admin) return res.error(403, "You have not got permission for this.");
|
||||
|
||||
const member = await UserModel.get(id);
|
||||
|
||||
if (!member ) return res.error(404, `We don't have any user with id ${req.params.id}.`);
|
||||
|
||||
if (!member.deleted) return res.error(404, "This user is not deleted, first, delete it.");
|
||||
|
||||
member.deleted = false;
|
||||
await member.save();
|
||||
|
||||
res.complate(member.toObject({ virtuals: true }));
|
||||
|
||||
})
|
||||
app.post("/:id/admin/", async (req, res) => {
|
||||
|
||||
const user = req.user;
|
||||
|
|
|
@ -19,16 +19,19 @@ You need this headers for send request to API:
|
|||
### Request types:
|
||||
- GET `/api/users/:id` for fetch user.
|
||||
- POST `/api/users/:id/delete` for delete user.
|
||||
- POST `/api/users/:id/undelete` for undelete user.
|
||||
- POST `/api/users/:id/admin` for give admin permissions for a user.
|
||||
|
||||
- GET `/api/threads/:id` for fetch thread.
|
||||
- GET `/api/threads/:id/messages/:limit` for fetch messages in thread.
|
||||
- POST `/api/threads` for create thread.
|
||||
- POST `/api/threads/:id/delete` for delete thread.
|
||||
- POST `/api/threads/:id/undelete` for undelete thread.
|
||||
|
||||
- GET `/api/messages/:id` for fetch message.
|
||||
- POST `/api/messages` for create message.
|
||||
- POST `/api/messages/:id/delete` for delete message.
|
||||
- POST `/api/messages/:id/undelete` for undelete message.
|
||||
- POST `/api/messages/:id/react/:type` for react to a message.
|
||||
|
||||
### Example request:
|
||||
|
|
Loading…
Reference in a new issue