feat: Category store integration (#5218)
* Add more actions * Complete sidebar store integration * Complete portal list store integration * Fixed the specs * Added missing specs * Add comment * Code cleanup * Fixed all the spec issues * Add portal and article API specs * Add category name in article list * Add more locales * Code beautification * Exclude locale from codeclimate ci * feat: Category store integration * chore: Minor fixes * chore: API call fixes * chore: Minor fixes * chore: Minor fixes * chore: Adds the ability for get articles based on categories * chore: minor fixes * chore: Minor fixes * chore: fixes specs and minor improvements * chore: Review fixes * chore: Minor fixes * chore: Review fixes * chore: Review fixes * chore: Spacing fixes * Code cleanup Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -5,7 +5,7 @@ import types from '../../mutation-types';
|
||||
export const actions = {
|
||||
index: async (
|
||||
{ commit },
|
||||
{ pageNumber, portalSlug, locale, status, author_id }
|
||||
{ pageNumber, portalSlug, locale, status, author_id, category_slug }
|
||||
) => {
|
||||
try {
|
||||
commit(types.SET_UI_FLAG, { isFetching: true });
|
||||
@@ -17,6 +17,7 @@ export const actions = {
|
||||
locale,
|
||||
status,
|
||||
author_id,
|
||||
category_slug,
|
||||
});
|
||||
const articleIds = payload.map(article => article.id);
|
||||
commit(types.CLEAR_ARTICLES);
|
||||
|
||||
@@ -5,13 +5,16 @@ export const actions = {
|
||||
index: async ({ commit }, { portalSlug }) => {
|
||||
try {
|
||||
commit(types.SET_UI_FLAG, { isFetching: true });
|
||||
const {
|
||||
data: { payload },
|
||||
} = await categoriesAPI.get({ portalSlug });
|
||||
const categoryIds = payload.map(category => category.id);
|
||||
commit(types.ADD_MANY_CATEGORIES, payload);
|
||||
commit(types.ADD_MANY_CATEGORIES_ID, categoryIds);
|
||||
return categoryIds;
|
||||
if (portalSlug) {
|
||||
const {
|
||||
data: { payload },
|
||||
} = await categoriesAPI.get({ portalSlug });
|
||||
const categoryIds = payload.map(category => category.id);
|
||||
commit(types.ADD_MANY_CATEGORIES, payload);
|
||||
commit(types.ADD_MANY_CATEGORIES_ID, categoryIds);
|
||||
return categoryIds;
|
||||
}
|
||||
return '';
|
||||
} catch (error) {
|
||||
return throwErrorMessage(error);
|
||||
} finally {
|
||||
@@ -19,12 +22,14 @@ export const actions = {
|
||||
}
|
||||
},
|
||||
|
||||
create: async ({ commit }, portalSlug, categoryObj) => {
|
||||
create: async ({ commit }, { portalSlug, categoryObj }) => {
|
||||
commit(types.SET_UI_FLAG, { isCreating: true });
|
||||
try {
|
||||
const { data } = await categoriesAPI.create({ portalSlug, categoryObj });
|
||||
const { id: categoryId } = data;
|
||||
commit(types.ADD_CATEGORY, data);
|
||||
const {
|
||||
data: { payload },
|
||||
} = await categoriesAPI.create({ portalSlug, categoryObj });
|
||||
const { id: categoryId } = payload;
|
||||
commit(types.ADD_CATEGORY, payload);
|
||||
commit(types.ADD_CATEGORY_ID, categoryId);
|
||||
return categoryId;
|
||||
} catch (error) {
|
||||
|
||||
@@ -32,12 +32,13 @@ describe('#actions', () => {
|
||||
|
||||
describe('#create', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.post.mockResolvedValue({ data: categoriesPayload.payload[0] });
|
||||
await actions.create({ commit }, categoriesPayload.payload[0]);
|
||||
axios.post.mockResolvedValue({ data: categoriesPayload });
|
||||
await actions.create({ commit }, categoriesPayload);
|
||||
const { id: categoryId } = categoriesPayload;
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_UI_FLAG, { isCreating: true }],
|
||||
[types.default.ADD_CATEGORY, categoriesPayload.payload[0]],
|
||||
[types.default.ADD_CATEGORY_ID, 1],
|
||||
[types.default.ADD_CATEGORY, categoriesPayload.payload],
|
||||
[types.default.ADD_CATEGORY_ID, categoryId],
|
||||
[types.default.SET_UI_FLAG, { isCreating: false }],
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user