Things are taking shape.
This commit is contained in:
parent
f0c9854a94
commit
58e85cc67b
5 changed files with 306 additions and 113 deletions
assets/misuzu.js/comments
|
@ -6,7 +6,10 @@ const MszCommentsApi = (() => {
|
|||
if(name.trim() === '')
|
||||
throw 'name may not be empty';
|
||||
|
||||
const { status, body } = await $xhr.get(`/comments/categories/${name}`, { type: 'json' });
|
||||
const { status, body } = await $xhr.get(
|
||||
`/comments/categories/${name}`,
|
||||
{ type: 'json' }
|
||||
);
|
||||
if(status === 404)
|
||||
throw 'that category does not exist';
|
||||
if(status !== 200)
|
||||
|
@ -22,7 +25,11 @@ const MszCommentsApi = (() => {
|
|||
if(typeof args !== 'object' || args === null)
|
||||
throw 'args must be a non-null object';
|
||||
|
||||
const { status } = await $xhr.patch(`/comments/categories/${name}`, { csrf: true }, args);
|
||||
const { status } = await $xhr.patch(
|
||||
`/comments/categories/${name}`,
|
||||
{ csrf: true },
|
||||
args
|
||||
);
|
||||
|
||||
return status;
|
||||
},
|
||||
|
@ -32,7 +39,10 @@ const MszCommentsApi = (() => {
|
|||
if(post.trim() === '')
|
||||
throw 'post id may not be empty';
|
||||
|
||||
const { status, body } = await $xhr.get(`/comments/posts/${post}`, { type: 'json' });
|
||||
const { status, body } = await $xhr.get(
|
||||
`/comments/posts/${post}`,
|
||||
{ type: 'json' }
|
||||
);
|
||||
if(status === 404)
|
||||
throw 'that post does not exist';
|
||||
if(status !== 200)
|
||||
|
@ -46,7 +56,10 @@ const MszCommentsApi = (() => {
|
|||
if(post.trim() === '')
|
||||
throw 'post id may not be empty';
|
||||
|
||||
const { status, body } = await $xhr.get(`/comments/posts/${post}/replies`, { type: 'json' });
|
||||
const { status, body } = await $xhr.get(
|
||||
`/comments/posts/${post}/replies`,
|
||||
{ type: 'json' }
|
||||
);
|
||||
if(status === 404)
|
||||
throw 'that post does not exist';
|
||||
if(status !== 200)
|
||||
|
@ -62,7 +75,11 @@ const MszCommentsApi = (() => {
|
|||
if(typeof args !== 'object' || args === null)
|
||||
throw 'args must be a non-null object';
|
||||
|
||||
const { status, body } = await $xhr.post('/comments/posts', { csrf: true }, args);
|
||||
const { status, body } = await $xhr.post(
|
||||
'/comments/posts',
|
||||
{ csrf: true },
|
||||
args
|
||||
);
|
||||
|
||||
return status;
|
||||
},
|
||||
|
@ -72,17 +89,37 @@ const MszCommentsApi = (() => {
|
|||
deletePost: async post => {
|
||||
//
|
||||
},
|
||||
restorePost: async post => {
|
||||
if(typeof post !== 'string')
|
||||
throw 'post id must be a string';
|
||||
if(post.trim() === '')
|
||||
throw 'post id may not be empty';
|
||||
|
||||
const { status } = await $xhr.post(`/comments/posts/${post}/restore`, { csrf: true });
|
||||
if(status === 400)
|
||||
throw 'that post is not deleted';
|
||||
if(status === 403)
|
||||
throw 'you are not allowed to restore posts';
|
||||
if(status === 404)
|
||||
throw 'that post does not exist';
|
||||
if(status !== 200)
|
||||
throw 'something went wrong';
|
||||
},
|
||||
createVote: async (post, vote) => {
|
||||
if(typeof post !== 'string')
|
||||
throw 'name must be a string';
|
||||
throw 'post id must be a string';
|
||||
if(post.trim() === '')
|
||||
throw 'name may not be empty';
|
||||
throw 'post id may not be empty';
|
||||
if(typeof vote === 'string')
|
||||
vote = parseInt(vote);
|
||||
if(typeof vote !== 'number' || isNaN(vote))
|
||||
throw 'vote must be a number';
|
||||
|
||||
const { status } = await $xhr.post(`/comments/posts/${post}/vote`, { csrf: true }, { vote });
|
||||
const { status, body } = await $xhr.post(
|
||||
`/comments/posts/${post}/vote`,
|
||||
{ csrf: true, type: 'json' },
|
||||
{ vote }
|
||||
);
|
||||
if(status === 400)
|
||||
throw 'your vote is not acceptable';
|
||||
if(status === 403)
|
||||
|
@ -91,20 +128,27 @@ const MszCommentsApi = (() => {
|
|||
throw 'that post does not exist';
|
||||
if(status !== 200)
|
||||
throw 'something went wrong';
|
||||
|
||||
return body;
|
||||
},
|
||||
deleteVote: async post => {
|
||||
if(typeof post !== 'string')
|
||||
throw 'name must be a string';
|
||||
throw 'post id must be a string';
|
||||
if(post.trim() === '')
|
||||
throw 'name may not be empty';
|
||||
throw 'post id may not be empty';
|
||||
|
||||
const { status } = await $xhr.delete(`/comments/posts/${post}/vote`, { csrf: true });
|
||||
const { status, body } = await $xhr.delete(
|
||||
`/comments/posts/${post}/vote`,
|
||||
{ csrf: true, type: 'json' }
|
||||
);
|
||||
if(status === 403)
|
||||
throw 'you are not allowed to like or dislike comments';
|
||||
if(status === 404)
|
||||
throw 'that post does not exist';
|
||||
if(status !== 204)
|
||||
if(status !== 200)
|
||||
throw 'something went wrong';
|
||||
|
||||
return body;
|
||||
},
|
||||
};
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue