diff --git a/core/admin-dashboard/components/gallery/widget/BaseGalleryFolders.vue b/core/admin-dashboard/components/gallery/widget/BaseGalleryFolders.vue index 666cd796..2009dcdc 100644 --- a/core/admin-dashboard/components/gallery/widget/BaseGalleryFolders.vue +++ b/core/admin-dashboard/components/gallery/widget/BaseGalleryFolders.vue @@ -101,14 +101,14 @@ export default { this.is_open_update_dialog = false; const gallery_id = this.$route.params.id; - if (gallery_id) { - return await Promise.all([ - this.GET_GALLERIES_BY_PARENT({ parent_id: gallery_id }), - this.GET_GALLERY({ _id: gallery_id }), - ]); + if (!gallery_id) { + return await this.GET_GALLERIES_PAGINATED({ is_parent: true }); } - await this.GET_GALLERIES_PAGINATED({ is_parent: true }); + await Promise.all([ + this.GET_GALLERIES_BY_PARENT({ parent_id: gallery_id }), + this.GET_GALLERY({ _id: gallery_id }), + ]); } catch (error) { console.error(error); } diff --git a/core/admin-dashboard/locales/en.json b/core/admin-dashboard/locales/en.json index dc496b8d..3d258a91 100644 --- a/core/admin-dashboard/locales/en.json +++ b/core/admin-dashboard/locales/en.json @@ -26,11 +26,6 @@ "Restore": "Restore", "Delete": "Delete", "Delete Forever": "Delete Forever", - "Disable auto censorship post": "Disable auto censorship post", - "Disable auto censorship for admin ${email} successfully": "Disable auto censorship for admin ${email} successfully", - "Encountered error while disabling auto censorship": "Encountered error while disabling auto censorship", - "Enable auto censorship for admin ${email} successfully": "Enable auto censorship for admin ${email} successfully", - "Encountered error while enabling auto censorship": "Encountered error while enabling auto censorship", "Restored admin ${title} successfully": "Restored admin ${title} successfully", "Encountered error while restoring admin": "Encountered error while restoring admin", "Deleted admin ${title} successfully": "Deleted admin ${title} successfully", @@ -42,7 +37,6 @@ "Password": "Password", "Password Confirmation": "Password Confirmation", "Type": "Type", - "Enable auto censorship post": "Enable auto censorship post", "Create": "Create", "Created admin successfully": "Created admin successfully", "Encountered error while creating admin": "Encountered error while creating admin", diff --git a/core/admin-dashboard/locales/vi.json b/core/admin-dashboard/locales/vi.json index 3cbfb2e9..a38f3038 100644 --- a/core/admin-dashboard/locales/vi.json +++ b/core/admin-dashboard/locales/vi.json @@ -26,12 +26,6 @@ "Restore": "Khôi phục", "Delete": "Xóa", "Delete Forever": "Xóa vĩnh viễn", - "Disable auto censorship post": "Tắt tự động kiểm duyệt bài viết", - "Enable auto censorship post": "Bật tự động kiểm duyệt bài viết", - "Disable auto censorship for admin ${email} successfully": "Tắt tự động kiểm duyệt thành công cho quản trị viên {email}", - "Encountered error while disabling auto censorship": "Xảy ra lỗi trong khi tắt tự dộng kiểm duyệt", - "Enable auto censorship for admin ${email} successfully": "Bật tự động kiểm duyệt thành công cho quản trị viên {email}", - "Encountered error while enabling auto censorship": "Xảy ra lỗi trong khi bật tự dộng kiểm duyệt", "Restored admin ${title} successfully": "Khôi phục thành công quản trị viên {title}", "Encountered error while restoring admin": "Xảy ra lỗi trong khi khôi phục quản trị viên", "Deleted admin ${title} successfully": "Đã xóa quản trị viên {title}", diff --git a/core/admin-dashboard/mixins/admin.js b/core/admin-dashboard/mixins/admin.js index d59d59c8..a7185a8f 100644 --- a/core/admin-dashboard/mixins/admin.js +++ b/core/admin-dashboard/mixins/admin.js @@ -47,8 +47,6 @@ export default { DELETE_ADMIN: "admin/DELETE_ADMIN", RESTORE_ADMIN: "admin/RESTORE_ADMIN", HARD_DELETE_ADMIN: "admin/HARD_DELETE_ADMIN", - DISABLE_AUTO_CENSORSHIP_POST: "admin/DISABLE_AUTO_CENSORSHIP_POST", - ENABLE_AUTO_CENSORSHIP_POST: "admin/ENABLE_AUTO_CENSORSHIP_POST", UPDATE_ADMIN_PASSWORD: "admin/UPDATE_ADMIN_PASSWORD", GET_ADMIN_ANALYTICS: "admin/GET_ADMIN_ANALYTICS", RESET_ADMIN_LOGIN_FAILED_TIMES: "admin/RESET_ADMIN_LOGIN_FAILED_TIMES", diff --git a/core/admin-dashboard/mixins/comment.js b/core/admin-dashboard/mixins/comment.js index 4093cada..712b3151 100644 --- a/core/admin-dashboard/mixins/comment.js +++ b/core/admin-dashboard/mixins/comment.js @@ -10,10 +10,6 @@ export default { methods: { ...mapActions({ GET_COMMENTS: "comment/GET_COMMENTS", - GET_COMMENT: "comment/GET_COMMENT", - CREATE_COMMENT: "comment/CREATE_COMMENT", - UPDATE_COMMENT: "comment/UPDATE_COMMENT", - UPLOAD_COMMENT_THUMBNAIL: "comment/UPLOAD_COMMENT_THUMBNAIL", HARD_DELETE_COMMENT: "comment/HARD_DELETE_COMMENT", }), ...mapMutations({ diff --git a/core/admin-dashboard/mixins/gallery.js b/core/admin-dashboard/mixins/gallery.js index ceee5abd..b2414bce 100644 --- a/core/admin-dashboard/mixins/gallery.js +++ b/core/admin-dashboard/mixins/gallery.js @@ -19,7 +19,6 @@ export default { DELETE_GALLERY_ITEM: "gallery/DELETE_GALLERY_ITEM", HARD_DELETE_GALLERY: "gallery/HARD_DELETE_GALLERY", CREATE_GALLERY: "gallery/CREATE_GALLERY", - UPLOAD_GALLERY_ITEM: "gallery/UPLOAD_GALLERY_ITEM", GET_GALLERY: "gallery/GET_GALLERY", GET_GALLERIES_BY_PARENT: "gallery/GET_GALLERIES_BY_PARENT", UPDATE_GALLERY: "gallery/UPDATE_GALLERY", diff --git a/core/admin-dashboard/mixins/subscription.js b/core/admin-dashboard/mixins/subscription.js index c8ffef1f..ca4bdf53 100644 --- a/core/admin-dashboard/mixins/subscription.js +++ b/core/admin-dashboard/mixins/subscription.js @@ -11,7 +11,6 @@ export default { methods: { ...mapActions({ GET_SUBSCRIPTIONS: "subscription/GET_SUBSCRIPTIONS", - GET_SUBSCRIPTION: "subscription/GET_SUBSCRIPTION", GET_SUBSCRIPTION_ANALYTICS: "subscription/GET_SUBSCRIPTION_ANALYTICS", }), ...mapMutations({ diff --git a/core/admin-dashboard/mixins/system-configuration.js b/core/admin-dashboard/mixins/system-configuration.js index b5709da9..7784d8ac 100644 --- a/core/admin-dashboard/mixins/system-configuration.js +++ b/core/admin-dashboard/mixins/system-configuration.js @@ -8,7 +8,6 @@ export default { }, methods: { ...mapActions({ - GET_SYSTEM_CONFIGURATION: "system-configuration/GET_SYSTEM_CONFIGURATION", GET_LATEST_SYSTEM_CONFIGURATION: "system-configuration/GET_LATEST_SYSTEM_CONFIGURATION", UPDATE_SYSTEM_CONFIGURATION: diff --git a/core/admin-dashboard/store/admin/action-types.ts b/core/admin-dashboard/store/admin/action-types.ts index 9ec0a756..58569ed8 100644 --- a/core/admin-dashboard/store/admin/action-types.ts +++ b/core/admin-dashboard/store/admin/action-types.ts @@ -5,9 +5,7 @@ export enum ActionTypes { UPDATE_ADMIN = "UPDATE_ADMIN", DELETE_ADMIN = "DELETE_ADMIN", HARD_DELETE_ADMIN = "HARD_DELETE_ADMIN", - ENABLE_AUTO_CENSORSHIP_POST = "ENABLE_AUTO_CENSORSHIP_POST", RESTORE_ADMIN = "RESTORE_ADMIN", - DISABLE_AUTO_CENSORSHIP_POST = "DISABLE_AUTO_CENSORSHIP_POST", UPDATE_ADMIN_PASSWORD = "UPDATE_ADMIN_PASSWORD", UPDATE_ADMIN_PERSONAL_PASSWORD = "UPDATE_ADMIN_PERSONAL_PASSWORD", GET_ADMIN_ANALYTICS = "GET_ADMIN_ANALYTICS", diff --git a/core/admin-dashboard/store/admin/actions.ts b/core/admin-dashboard/store/admin/actions.ts index 73e7bc59..cd542f36 100644 --- a/core/admin-dashboard/store/admin/actions.ts +++ b/core/admin-dashboard/store/admin/actions.ts @@ -1,10 +1,10 @@ -import { ActionTypes } from "./action-types"; -import { MutationTypes } from "./mutation-types"; +import { ADMIN_TYPES } from "@/constants"; +import { get, join } from "lodash"; import { ActionTree } from "vuex"; import { AdminState } from "."; import { RootState } from ".."; -import { ADMIN_TYPES } from "@/constants"; -import { get, join } from "lodash"; +import { ActionTypes } from "./action-types"; +import { MutationTypes } from "./mutation-types"; const actions: ActionTree = { async [ActionTypes.GET_ADMIN_ANALYTICS]({ commit }, params = {}) { @@ -24,71 +24,42 @@ const actions: ActionTree = { const { data } = await this.$axios.$get(`/admin/analystics?${url_query}`); commit(MutationTypes.SET_ADMIN_ANALYS_DATA, { data }); - return data; }, async [ActionTypes.GET_ADMINS]({ commit }, params = {}) { const keep_in_store = get(params, "keep_in_store", true); - const { data: admins } = await this.$axios.$get("/admin"); + const { data } = await this.$axios.$get("/admin"); if (!keep_in_store) { - return admins; + return data; } - commit(MutationTypes.SET_ADMINS, { data: admins }); - return admins; - }, - - async [ActionTypes.ENABLE_AUTO_CENSORSHIP_POST]( - { commit }, - { id }: { id: string } - ) { - const { data: admin } = await this.$axios.$put( - `/admin/enable-auto-censorship/${id}` - ); - return admin; + commit(MutationTypes.SET_ADMINS, { data }); + return data; }, async [ActionTypes.UPDATE_ADMIN_PASSWORD]( { commit }, { data }: { data: any } ) { - const { data: admin } = await this.$axios.$put(`/admin/password`, data); - return admin; + await this.$axios.$put(`/admin/password`, data); }, async [ActionTypes.UPDATE_ADMIN_PERSONAL_PASSWORD]( { commit }, { data }: { data: any } ) { - const { data: admin } = await this.$axios.$put( - `/admin/personal-password`, - data - ); - return admin; + await this.$axios.$put(`/admin/personal-password`, data); }, async [ActionTypes.RESTORE_ADMIN]({ commit }, { id }: { id: string }) { - const { data: admin } = await this.$axios.$put(`/admin/restore/${id}`); - return admin; - }, - - async [ActionTypes.DISABLE_AUTO_CENSORSHIP_POST]( - { commit }, - { id }: { id: string } - ) { - const { data: admin } = await this.$axios.$put( - `/admin/disable-auto-censorship/${id}` - ); - return admin; + await this.$axios.$put(`/admin/restore/${id}`); }, async [ActionTypes.GET_ADMIN]({ commit }, { id }: { id: string }) { - const { data: admin } = await this.$axios.$get(`/admin/${id}`); - - commit(MutationTypes.SET_ADMIN, { data: admin }); - return admin; + const { data } = await this.$axios.$get(`/admin/${id}`); + commit(MutationTypes.SET_ADMIN, { data }); }, async [ActionTypes.CREATE_ADMIN]({ commit }, { data }: { data: any }) { @@ -97,31 +68,22 @@ const actions: ActionTree = { }, async [ActionTypes.UPDATE_ADMIN]({ commit }, { data }: { data: any }) { - const { data: admin } = await this.$axios.$put(`/admin`, data); - return admin; + await this.$axios.$put(`/admin`, data); }, async [ActionTypes.DELETE_ADMIN]({ commit }, { id }: { id: string }) { - const { data: admin } = await this.$axios.$delete(`/admin/${id}`); - return admin; + await this.$axios.$delete(`/admin/${id}`); }, async [ActionTypes.HARD_DELETE_ADMIN]({ commit }, { id }: { id: string }) { - const { data: admin } = await this.$axios.$delete( - `/admin/hard-delete/${id}` - ); - return admin; + await this.$axios.$delete(`/admin/hard-delete/${id}`); }, async [ActionTypes.RESET_ADMIN_LOGIN_FAILED_TIMES]( { commit }, { id }: { id: string } ) { - const { data: admin } = await this.$axios.$put( - `/admin/reset-admin-login-failed-times/${id}` - ); - - return admin; + await this.$axios.$put(`/admin/reset-admin-login-failed-times/${id}`); }, async [ActionTypes.BATCH_UPLOAD_ADMINS]({ commit }, params = {}) { @@ -130,12 +92,7 @@ const actions: ActionTree = { const form_data = new FormData(); form_data.append("file", file); - const data = await this.$axios.post( - `/v2/batch/admin/upload-admins`, - form_data - ); - - return data; + await this.$axios.post(`/v2/batch/admin/upload-admins`, form_data); }, async [ActionTypes.GET_ADMINS_PAGINATED]({ commit }, params = {}) { diff --git a/core/admin-dashboard/store/auth/actions.ts b/core/admin-dashboard/store/auth/actions.ts index 2095c331..f2d69278 100644 --- a/core/admin-dashboard/store/auth/actions.ts +++ b/core/admin-dashboard/store/auth/actions.ts @@ -1,29 +1,24 @@ -import { ActionTypes } from "./action-types"; -import { MutationTypes } from "./mutation-types"; import { ActionTree } from "vuex"; -import { AuthState } from "./"; import { RootState } from ".."; +import { AuthState } from "./"; +import { ActionTypes } from "./action-types"; +import { MutationTypes } from "./mutation-types"; const actions: ActionTree = { async [ActionTypes.SIGN_IN]({ commit }, { data }: { data: any }) { - const returned_data = await this.$axios.$post("/auth/sign-in", data); - + await this.$axios.$post("/auth/sign-in", data); commit(MutationTypes.SET_HAS_USER, { data: true }); - return returned_data; }, async [ActionTypes.SIGN_OUT]() { - const { data } = await this.$axios.$post("/auth/sign-out"); - - return data; + await this.$axios.$post("/auth/sign-out"); }, async [ActionTypes.GET_ME]({ commit }) { - const { data: user } = await this.$axios.$get("/auth/me"); + const { data } = await this.$axios.$get("/auth/me"); - commit(MutationTypes.SET_ME, { data: user }); + commit(MutationTypes.SET_ME, { data }); commit(MutationTypes.SET_HAS_USER, { data: true }); - return user; }, }; diff --git a/core/admin-dashboard/store/category/actions.ts b/core/admin-dashboard/store/category/actions.ts index 4f079c40..355b0c28 100644 --- a/core/admin-dashboard/store/category/actions.ts +++ b/core/admin-dashboard/store/category/actions.ts @@ -1,9 +1,9 @@ -import { ActionTypes } from "./action-types"; -import { MutationTypes } from "./mutation-types"; +import { get, join } from "lodash"; import { ActionTree } from "vuex"; import { CategoryState } from "."; import { RootState } from ".."; -import { get, join } from "lodash"; +import { ActionTypes } from "./action-types"; +import { MutationTypes } from "./mutation-types"; const actions: ActionTree = { async [ActionTypes.GET_CATEGORY_ANALYTICS]({ commit }, params = {}) { @@ -25,28 +25,22 @@ const actions: ActionTree = { `/category/analystics?${url_query}` ); commit(MutationTypes.SET_CATEGORY_ANALYS_DATA, { data }); - return data; }, async [ActionTypes.GET_CATEGORIES]({ commit }, params = {}) { const keep_in_store = get(params, "keep_in_store", true); - const { data: categories } = await this.$axios.$get("/category"); + const { data } = await this.$axios.$get("/category"); if (!keep_in_store) { - return categories; + return data; } - commit(MutationTypes.SET_CATEGORIES, { data: categories }); - - return categories; + commit(MutationTypes.SET_CATEGORIES, { data }); }, async [ActionTypes.GET_CATEGORY]({ commit }, { id }: { id: string }) { - const { data: category } = await this.$axios.$get(`/category/${id}`); - - commit(MutationTypes.SET_CATEGORY, { data: category }); - - return category; + const { data } = await this.$axios.$get(`/category/${id}`); + commit(MutationTypes.SET_CATEGORY, { data }); }, async [ActionTypes.CREATE_CATEGORY]({ commit }, { data }: { data: any }) { @@ -59,27 +53,18 @@ const actions: ActionTree = { const { data: category } = await this.$axios.$put(`/category/${_id}`, data); commit(MutationTypes.SET_CATEGORY, { data: category }); - - return category; }, async [ActionTypes.DELETE_CATEGORY]({ commit }, { id }: { id: string }) { - const { data: category } = await this.$axios.$delete(`/category/${id}`); - return category; + await this.$axios.$delete(`/category/${id}`); }, async [ActionTypes.RESTORE_CATEGORY]({ commit }, { id }: { id: string }) { - const { data: category } = await this.$axios.$put( - `/category/restore/${id}` - ); - return category; + await this.$axios.$put(`/category/restore/${id}`); }, async [ActionTypes.HARD_DELETE_CATEGORY]({ commit }, { id }: { id: string }) { - const { data: category } = await this.$axios.$delete( - `/category/hard-delete/${id}` - ); - return category; + await this.$axios.$delete(`/category/hard-delete/${id}`); }, }; diff --git a/core/admin-dashboard/store/comment/action-types.ts b/core/admin-dashboard/store/comment/action-types.ts index 16c4e4b8..b1ca0f6b 100644 --- a/core/admin-dashboard/store/comment/action-types.ts +++ b/core/admin-dashboard/store/comment/action-types.ts @@ -1,8 +1,4 @@ export enum ActionTypes { GET_COMMENTS = "GET_COMMENTS", - GET_COMMENT = "GET_COMMENT", - CREATE_COMMENT = "CREATE_COMMENT", - UPDATE_COMMENT = "UPDATE_COMMENT", - UPLOAD_COMMENT_THUMBNAIL = "UPLOAD_COMMENT_THUMBNAIL", HARD_DELETE_COMMENT = "HARD_DELETE_COMMENT", } diff --git a/core/admin-dashboard/store/comment/actions.ts b/core/admin-dashboard/store/comment/actions.ts index 08870278..ecfa1a5d 100644 --- a/core/admin-dashboard/store/comment/actions.ts +++ b/core/admin-dashboard/store/comment/actions.ts @@ -1,70 +1,26 @@ -import { ActionTypes } from "./action-types"; -import { MutationTypes } from "./mutation-types"; +import { get } from "lodash"; import { ActionTree } from "vuex"; import { CommentState } from "."; import { RootState } from ".."; -import { get } from "lodash"; +import { ActionTypes } from "./action-types"; +import { MutationTypes } from "./mutation-types"; const actions: ActionTree = { async [ActionTypes.GET_COMMENTS]({ commit }, params = {}) { const keep_in_store = get(params, "keep_in_store", true); - const { data: comments } = await this.$axios.$get("/comment"); + const { data } = await this.$axios.$get("/comment"); if (!keep_in_store) { - return comments; + return data; } - commit(MutationTypes.SET_COMMENTS, { data: comments }); - - return comments; - }, - - async [ActionTypes.GET_COMMENT]({ commit }, { id }: { id: string }) { - const { data: comment } = await this.$axios.$get(`/comment/${id}`); - - commit(MutationTypes.SET_COMMENT, { data: comment }); - - return comment; - }, - - async [ActionTypes.CREATE_COMMENT]({ commit }, { data }: { data: any }) { - const { data: comment } = await this.$axios.$post(`/comment`, data); - - return comment; - }, - - async [ActionTypes.UPDATE_COMMENT]({ commit }, { data }: { data: any }) { - const { data: comment } = await this.$axios.$put(`/comment`, data); - - commit(MutationTypes.SET_COMMENT, { data: comment }); - - return comment; + commit(MutationTypes.SET_COMMENTS, { data }); }, async [ActionTypes.HARD_DELETE_COMMENT]({ commit }, { id }: { id: string }) { - const { data: comment } = await this.$axios.$delete( - `/comment/hard-delete/${id}` - ); - - commit(MutationTypes.SET_COMMENT, { data: comment }); - - return comment; - }, - - async [ActionTypes.UPLOAD_COMMENT_THUMBNAIL]( - { commit }, - { file }: { file: any } - ) { - const form_data = new FormData(); - form_data.append("file", file); - - const { data: comment } = await this.$axios.$put( - `/comment/upload-avatar`, - form_data - ); - - return comment; + const { data } = await this.$axios.$delete(`/comment/hard-delete/${id}`); + commit(MutationTypes.SET_COMMENT, { data }); }, }; diff --git a/core/admin-dashboard/store/gallery/action-types.ts b/core/admin-dashboard/store/gallery/action-types.ts index 36502ae4..91940297 100644 --- a/core/admin-dashboard/store/gallery/action-types.ts +++ b/core/admin-dashboard/store/gallery/action-types.ts @@ -5,6 +5,5 @@ export enum ActionTypes { HARD_DELETE_GALLERY = "HARD_DELETE_GALLERY", CREATE_GALLERY = "CREATE_GALLERY", UPDATE_GALLERY = "UPDATE_GALLERY", - UPLOAD_GALLERY_ITEM = "UPLOAD_GALLERY_ITEM", GET_GALLERY = "GET_GALLERY", } diff --git a/core/admin-dashboard/store/gallery/actions.ts b/core/admin-dashboard/store/gallery/actions.ts index acf9d353..66c6c31a 100644 --- a/core/admin-dashboard/store/gallery/actions.ts +++ b/core/admin-dashboard/store/gallery/actions.ts @@ -1,9 +1,9 @@ -import { ActionTypes } from "./action-types"; -import { MutationTypes } from "./mutation-types"; +import { get } from "lodash"; import { ActionTree } from "vuex"; import { GalleryState } from "."; import { RootState } from ".."; -import { get } from "lodash"; +import { ActionTypes } from "./action-types"; +import { MutationTypes } from "./mutation-types"; const actions: ActionTree = { async [ActionTypes.GET_GALLERIES_PAGINATED]({ commit }, params = {}) { @@ -34,8 +34,6 @@ const actions: ActionTree = { commit(MutationTypes.SET_GALLERIES, { data, new_state }); commit(MutationTypes.SET_GALLERY_PAGINATION, { data: pagination }); - - return data; }, async [ActionTypes.GET_GALLERIES_BY_PARENT]( @@ -43,53 +41,27 @@ const actions: ActionTree = { { parent_id }: { parent_id: string } ) { const { data } = await this.$axios.$get(`/gallery/by-parent/${parent_id}`); - commit(MutationTypes.SET_GALLERIES, { data, new_state: true }); - - return data; }, async [ActionTypes.DELETE_GALLERY_ITEM]( { commit }, { _id, item_id }: { _id: string; item_id: string } ) { - const { data: updated_gallery } = await this.$axios.$put( - `/v2/gallery/delete-gallery-item/${_id}/${item_id}` - ); - - return updated_gallery; + await this.$axios.$put(`/v2/gallery/delete-gallery-item/${_id}/${item_id}`); }, async [ActionTypes.HARD_DELETE_GALLERY]({ commit }, { id }: { id: string }) { - const { data: gallery } = await this.$axios.$delete( - `/gallery/hard-delete/${id}` - ); - - return gallery; + await this.$axios.$delete(`/gallery/hard-delete/${id}`); }, async [ActionTypes.CREATE_GALLERY]({ commit }, { data }: { data: any }) { - const { data: gallery } = await this.$axios.$post(`/gallery`, data); - - return gallery; - }, - - async [ActionTypes.UPLOAD_GALLERY_ITEM]( - { commit }, - { _id }: { _id: string } - ) { - const { data: gallery } = await this.$axios.$post( - `/upload-gallery-item/${_id}` - ); - - return gallery; + await this.$axios.$post(`/gallery`, data); }, async [ActionTypes.GET_GALLERY]({ commit }, { _id }: { _id: string }) { - const { data: gallery } = await this.$axios.$get(`/gallery/${_id}`); - - commit(MutationTypes.SET_GALLERY, { data: gallery }); - return gallery; + const { data } = await this.$axios.$get(`/gallery/${_id}`); + commit(MutationTypes.SET_GALLERY, { data }); }, async [ActionTypes.UPDATE_GALLERY]({ commit }, { data }: { data: any }) { @@ -97,7 +69,6 @@ const actions: ActionTree = { const { data: gallery } = await this.$axios.$put(`/gallery/${_id}`, data); commit(MutationTypes.SET_GALLERY, { data: gallery }); - return gallery; }, }; diff --git a/core/admin-dashboard/store/post/actions.ts b/core/admin-dashboard/store/post/actions.ts index 0795b0a4..bb58604e 100644 --- a/core/admin-dashboard/store/post/actions.ts +++ b/core/admin-dashboard/store/post/actions.ts @@ -1,9 +1,9 @@ -import { ActionTypes } from "./action-types"; -import { MutationTypes } from "./mutation-types"; +import { get, join } from "lodash"; import { ActionTree } from "vuex"; import { PostState } from "."; import { RootState } from ".."; -import { get, join } from "lodash"; +import { ActionTypes } from "./action-types"; +import { MutationTypes } from "./mutation-types"; const actions: ActionTree = { async [ActionTypes.GET_POST_ANALYTICS]({ commit }, params = {}) { @@ -20,7 +20,6 @@ const actions: ActionTree = { const { data } = await this.$axios.$get(`/post/analystics?${url_query}`); commit(MutationTypes.SET_POST_ANALYS_DATA, { data }); - return data; }, async [ActionTypes.GET_MOST_POPULAR_POSTS_ANALYTICS]( @@ -46,46 +45,35 @@ const actions: ActionTree = { ); commit(MutationTypes.SET_MOST_POPULAR_POSTS_ANALYS_DATA, { data }); - return data; }, async [ActionTypes.GET_POSTS]({ commit }, params = {}) { const keep_in_store = get(params, "keep_in_store", true); - const { data: posts } = await this.$axios.$get("/post"); + const { data } = await this.$axios.$get("/post"); if (!keep_in_store) { - return posts; + return data; } - commit(MutationTypes.SET_POSTS, { data: posts }); - - return posts; + commit(MutationTypes.SET_POSTS, { data }); }, async [ActionTypes.GET_POST]({ commit }, { id }: { id: string }) { - const { data: post } = await this.$axios.$get(`/post/${id}`); - - commit(MutationTypes.SET_POST, { data: post }); - - return post; + const { data } = await this.$axios.$get(`/post/${id}`); + commit(MutationTypes.SET_POST, { data }); }, async [ActionTypes.BLOCK_POST_COMMENT]({ commit }, { id }: { id: string }) { - const { data: post } = await this.$axios.$put(`/post/block-comment/${id}`); - return post; + await this.$axios.$put(`/post/block-comment/${id}`); }, async [ActionTypes.UNBLOCK_POST_COMMENT]({ commit }, { id }: { id: string }) { - const { data: post } = await this.$axios.$put( - `/post/un-block-comment/${id}` - ); - return post; + await this.$axios.$put(`/post/un-block-comment/${id}`); }, async [ActionTypes.RESTORE_POST]({ commit }, { id }: { id: string }) { - const { data: post } = await this.$axios.$put(`/post/restore/${id}`); - return post; + await this.$axios.$put(`/post/restore/${id}`); }, async [ActionTypes.CREATE_POST]({ commit }, { data }: { data: any }) { @@ -98,19 +86,15 @@ const actions: ActionTree = { const { data: post } = await this.$axios.$put(`/post/${_id}`, data); commit(MutationTypes.SET_POST, { data: post }); - return post; }, async [ActionTypes.DELETE_POST]({ commit }, { id }: { id: string }) { const { data: post } = await this.$axios.$delete(`/post/${id}`); - commit(MutationTypes.SET_POST, { data: post }); - return post; }, async [ActionTypes.HARD_DELETE_POST]({ commit }, { id }: { id: string }) { - const { data: post } = await this.$axios.$delete(`/post/hard-delete/${id}`); - return post; + await this.$axios.$delete(`/post/hard-delete/${id}`); }, }; diff --git a/core/admin-dashboard/store/subscription/action-types.ts b/core/admin-dashboard/store/subscription/action-types.ts index 928ce081..30827641 100644 --- a/core/admin-dashboard/store/subscription/action-types.ts +++ b/core/admin-dashboard/store/subscription/action-types.ts @@ -1,5 +1,4 @@ export enum ActionTypes { GET_SUBSCRIPTIONS = "GET_SUBSCRIPTIONS", - GET_SUBSCRIPTION = "GET_SUBSCRIPTION", GET_SUBSCRIPTION_ANALYTICS = "GET_SUBSCRIPTION_ANALYTICS", } diff --git a/core/admin-dashboard/store/subscription/actions.ts b/core/admin-dashboard/store/subscription/actions.ts index 1c15357a..791f0096 100644 --- a/core/admin-dashboard/store/subscription/actions.ts +++ b/core/admin-dashboard/store/subscription/actions.ts @@ -1,9 +1,9 @@ -import { ActionTypes } from "./action-types"; -import { MutationTypes } from "./mutation-types"; +import { get, join } from "lodash"; import { ActionTree } from "vuex"; import { SubscriptionState } from "."; import { RootState } from ".."; -import { get, join } from "lodash"; +import { ActionTypes } from "./action-types"; +import { MutationTypes } from "./mutation-types"; const actions: ActionTree = { async [ActionTypes.GET_SUBSCRIPTION_ANALYTICS]({ commit }, params = {}) { @@ -22,29 +22,18 @@ const actions: ActionTree = { `/subscription/analystics?${url_query}` ); commit(MutationTypes.SET_SUBSCRIPTION_ANALYS_DATA, { data }); - return data; }, async [ActionTypes.GET_SUBSCRIPTIONS]({ commit }, params = {}) { const keep_in_store = get(params, "keep_in_store", true); - const { data: subscriptions } = await this.$axios.$get("/subscription"); + const { data } = await this.$axios.$get("/subscription"); if (!keep_in_store) { - return subscriptions; + return data; } - commit(MutationTypes.SET_SUBSCRIPTIONS, { data: subscriptions }); - return subscriptions; - }, - - async [ActionTypes.GET_SUBSCRIPTION]({ commit }, { id }: { id: string }) { - const { data: subscription } = await this.$axios.$get( - `/subscription/${id}` - ); - - commit(MutationTypes.SET_SUBSCRIPTION, { data: subscription }); - return subscription; + commit(MutationTypes.SET_SUBSCRIPTIONS, { data }); }, }; diff --git a/core/admin-dashboard/store/system-configuration/action-types.ts b/core/admin-dashboard/store/system-configuration/action-types.ts index b9037fdb..553dd0ac 100644 --- a/core/admin-dashboard/store/system-configuration/action-types.ts +++ b/core/admin-dashboard/store/system-configuration/action-types.ts @@ -1,5 +1,4 @@ export enum ActionTypes { - GET_SYSTEM_CONFIGURATION = "GET_SYSTEM_CONFIGURATION", GET_LATEST_SYSTEM_CONFIGURATION = "GET_LATEST_SYSTEM_CONFIGURATION", UPDATE_SYSTEM_CONFIGURATION = "UPDATE_SYSTEM_CONFIGURATION", } diff --git a/core/admin-dashboard/store/system-configuration/actions.ts b/core/admin-dashboard/store/system-configuration/actions.ts index 4b2ccd5c..f52a1d8d 100644 --- a/core/admin-dashboard/store/system-configuration/actions.ts +++ b/core/admin-dashboard/store/system-configuration/actions.ts @@ -1,35 +1,15 @@ -import { ActionTypes } from "./action-types"; -import { MutationTypes } from "./mutation-types"; import { ActionTree } from "vuex"; import { SystemConfigurationState } from "."; import { RootState } from ".."; +import { ActionTypes } from "./action-types"; +import { MutationTypes } from "./mutation-types"; const actions: ActionTree = { - async [ActionTypes.GET_SYSTEM_CONFIGURATION]( - { commit }, - { id }: { id: string } - ) { - const { data: system_configuration } = await this.$axios.$get( - `/system-configuration/${id}` - ); - - commit(MutationTypes.SET_SYSTEM_CONFIGURATION, { - data: system_configuration, - }); - - return system_configuration; - }, - async [ActionTypes.GET_LATEST_SYSTEM_CONFIGURATION]({ commit }) { - const { data: system_configuration } = await this.$axios.$get( - `/system-configuration` - ); - + const { data } = await this.$axios.$get(`/system-configuration`); commit(MutationTypes.SET_SYSTEM_CONFIGURATION, { - data: system_configuration, + data, }); - - return system_configuration; }, async [ActionTypes.UPDATE_SYSTEM_CONFIGURATION]( @@ -41,12 +21,9 @@ const actions: ActionTree = { `/system-configuration/${_id}`, data ); - commit(MutationTypes.SET_SYSTEM_CONFIGURATION, { data: system_configuration, }); - - return system_configuration; }, }; diff --git a/core/admin-dashboard/store/user/actions.ts b/core/admin-dashboard/store/user/actions.ts index 3a40a4b4..0e465c52 100644 --- a/core/admin-dashboard/store/user/actions.ts +++ b/core/admin-dashboard/store/user/actions.ts @@ -20,15 +20,13 @@ const actions: ActionTree = { const { data } = await this.$axios.$get(`/user/analystics?${url_query}`); commit(MutationTypes.SET_USER_ANALYS_DATA, { data }); - return data; }, async [ActionTypes.UPDATE_USER_PASSWORD]( { commit }, { data }: { data: any } ) { - const { data: user } = await this.$axios.$put(`/user/password`, data); - return user; + await this.$axios.$put(`/user/password`, data); }, async [ActionTypes.GET_USERS]({ commit }, params = {}) { @@ -41,24 +39,19 @@ const actions: ActionTree = { } commit(MutationTypes.SET_USERS, { data }); - return data; }, async [ActionTypes.BLOCK_USER_COMMENT]({ commit }, { id }: { id: string }) { - const { data } = await this.$axios.$put(`/user/block-comment/${id}`); - return data; + await this.$axios.$put(`/user/block-comment/${id}`); }, async [ActionTypes.UNBLOCK_USER_COMMENT]({ commit }, { id }: { id: string }) { - const { data } = await this.$axios.$put(`/user/un-block-comment/${id}`); - return data; + await this.$axios.$put(`/user/un-block-comment/${id}`); }, async [ActionTypes.GET_USER]({ commit }, { id }: { id: string }) { const { data } = await this.$axios.$get(`/user/${id}`); - commit(MutationTypes.SET_USER, { data }); - return data; }, async [ActionTypes.CREATE_USER]({ commit }, { data }: { data: any }) { @@ -68,35 +61,26 @@ const actions: ActionTree = { async [ActionTypes.UPDATE_USER]({ commit }, { data }: { data: any }) { const { data: user } = await this.$axios.$put(`/user`, data); - commit(MutationTypes.SET_USER, { data: user }); - return user; }, async [ActionTypes.DELETE_USER]({ commit }, { id }: { id: string }) { - const { data } = await this.$axios.$delete(`/user/${id}`); - return data; + await this.$axios.$delete(`/user/${id}`); }, async [ActionTypes.HARD_DELETE_USER]({ commit }, { id }: { id: string }) { - const { data } = await this.$axios.$delete(`/user/hard-delete/${id}`); - return data; + await this.$axios.$delete(`/user/hard-delete/${id}`); }, async [ActionTypes.RESTORE_USER]({ commit }, { id }: { id: string }) { - const { data } = await this.$axios.$put(`/user/restore/${id}`); - return data; + await this.$axios.$put(`/user/restore/${id}`); }, async [ActionTypes.RESET_USER_LOGIN_FAILED_TIMES]( { commit }, { id }: { id: string } ) { - const { data } = await this.$axios.$put( - `/user/reset-user-login-failed-times/${id}` - ); - - return data; + await this.$axios.$put(`/user/reset-user-login-failed-times/${id}`); }, async [ActionTypes.BATCH_UPLOAD_USERS]({ commit }, params = {}) { @@ -105,12 +89,7 @@ const actions: ActionTree = { const form_data = new FormData(); form_data.append("file", file); - const data = await this.$axios.post( - `/v2/batch/user/upload-users`, - form_data - ); - - return data; + await this.$axios.post(`/v2/batch/user/upload-users`, form_data); }, async [ActionTypes.GET_USERS_PAGINATED]({ commit }, params = {}) { @@ -130,8 +109,6 @@ const actions: ActionTree = { commit(MutationTypes.SET_USERS, { data }); commit(MutationTypes.SET_USER_PAGINATION, { data: pagination }); - - return data; }, }; diff --git a/core/server/src/data-access/controllers/admin/comment/create-comment.spec.ts b/core/server/src/data-access/controllers/admin/comment/create-comment.spec.ts deleted file mode 100644 index 657c1fd3..00000000 --- a/core/server/src/data-access/controllers/admin/comment/create-comment.spec.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { fakeComment } from "../../../../../__tests__/__mock__"; -import { ExpectSingleResult } from "../../../../../__tests__/__types__/expect-types"; -import { - clearDatabase, - connectDatabase, -} from "../../../../../__tests__/jest-mongo"; -import { redis } from "../../../../../__tests__/jest-redis"; -import { HttpStatusCode } from "../../../../constants/http-status-code"; -import IComment from "../../../../database/interfaces/comment"; -import makeCreateComment from "../../../../use-cases/comment/create-comment"; -import makeCommentDb from "../../../make-comment-db"; -import { CommentModel } from "../../../models"; -import makeCreateCommentController from "./create-comment"; - -describe("createComment", () => { - beforeAll(async () => await connectDatabase()); - - afterAll( - async () => await Promise.all([clearDatabase(), redis.disconnect()]) - ); - - it("should return a body that contains an comment entity", async () => { - const headers = { - "Content-Type": "application/json", - }; - - const commentDb = makeCommentDb({ - commentDbModel: CommentModel, - }); - - const createComment = makeCreateComment({ commentDb }); - - const mock_comment_data = fakeComment(); - - const createCommentController = makeCreateCommentController({ - createComment, - }); - - const request = { - context: { - validated: mock_comment_data, - }, - }; - - const result = await createCommentController(request as any); - - const expected: ExpectSingleResult = { - headers, - statusCode: HttpStatusCode.CREATED, - body: result?.body, - }; - - expect(result).toEqual(expected); - }); -}); diff --git a/core/server/src/data-access/controllers/admin/comment/create-comment.ts b/core/server/src/data-access/controllers/admin/comment/create-comment.ts deleted file mode 100644 index 0d118237..00000000 --- a/core/server/src/data-access/controllers/admin/comment/create-comment.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Request } from "express"; -import { get } from "lodash"; -import { HttpStatusCode } from "../../../../constants/http-status-code"; -import { - CreateComment, - ICreateCommentPayload, -} from "../../../../use-cases/comment/create-comment"; - -export default function makeCreateCommentController({ - createComment, -}: { - createComment: CreateComment; -}) { - return async function createCommentController( - httpRequest: Request & { context: {} } - ) { - const headers = { - "Content-Type": "application/json", - }; - - try { - const comment_details = ( - get(httpRequest, "context.validated", {}) - ); - - const created_comment = await createComment(comment_details); - - return { - headers, - statusCode: HttpStatusCode.CREATED, - body: { - data: created_comment, - }, - }; - } catch (error) { - throw { - headers, - statusCode: HttpStatusCode.INTERNAL_SERVER_ERROR, - body: { - data: error.message, - }, - }; - } - }; -} diff --git a/core/server/src/data-access/controllers/admin/comment/get-comment.spec.ts b/core/server/src/data-access/controllers/admin/comment/get-comment.spec.ts deleted file mode 100644 index 8d2aebb9..00000000 --- a/core/server/src/data-access/controllers/admin/comment/get-comment.spec.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { fakeComment } from "../../../../../__tests__/__mock__"; -import { ExpectSingleResult } from "../../../../../__tests__/__types__/expect-types"; -import { - clearDatabase, - connectDatabase, -} from "../../../../../__tests__/jest-mongo"; -import { redis } from "../../../../../__tests__/jest-redis"; -import { HttpStatusCode } from "../../../../constants/http-status-code"; -import IComment from "../../../../database/interfaces/comment"; -import makeCreateComment from "../../../../use-cases/comment/create-comment"; -import makeGetComment from "../../../../use-cases/comment/get-comment"; -import makeCommentDb from "../../../make-comment-db"; -import { CommentModel } from "../../../models"; -import makeGetCommentController from "./get-comment"; - -describe("getComment", () => { - beforeAll(async () => await connectDatabase()); - - afterAll( - async () => await Promise.all([clearDatabase(), redis.disconnect()]) - ); - - it("should return a body that contains an comment entity", async () => { - const headers = { - "Content-Type": "application/json", - }; - - const commentDb = makeCommentDb({ - commentDbModel: CommentModel, - }); - - const createComment = makeCreateComment({ commentDb }); - const getComment = makeGetComment({ commentDb }); - - const mock_comment_data = fakeComment(); - - const getCommentController = makeGetCommentController({ - getComment, - }); - - const created_comment = await createComment(mock_comment_data); - - const request = { - context: { - validated: { _id: created_comment._id }, - }, - }; - - const result = await getCommentController(request as any); - - const expected: ExpectSingleResult = { - headers, - statusCode: HttpStatusCode.OK, - body: result?.body, - }; - - expect(result).toEqual(expected); - }); -}); diff --git a/core/server/src/data-access/controllers/admin/comment/get-comment.ts b/core/server/src/data-access/controllers/admin/comment/get-comment.ts deleted file mode 100644 index 357026d9..00000000 --- a/core/server/src/data-access/controllers/admin/comment/get-comment.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { Request } from "express"; -import { get } from "lodash"; -import { HttpStatusCode } from "../../../../constants/http-status-code"; -import { - GetComment, - IGetCommentPayload, -} from "../../../../use-cases/comment/get-comment"; -import { isEmpty } from "../../../../utils/is-empty"; - -export default function makeGetCommentController({ - getComment, -}: { - getComment: GetComment; -}) { - return async function getCommentController( - httpRequest: Request & { context: {} } - ) { - const headers = { - "Content-Type": "application/json", - }; - - try { - const { _id } = ( - get(httpRequest, "context.validated", {}) - ); - - const exists = await getComment({ _id }); - if (isEmpty(exists)) { - throw new Error(`Comment ${_id} does not exists`); - } - - return { - headers, - statusCode: HttpStatusCode.OK, - body: { - data: exists, - }, - }; - } catch (error) { - throw { - headers, - statusCode: HttpStatusCode.INTERNAL_SERVER_ERROR, - body: { - data: error.message, - }, - }; - } - }; -} diff --git a/core/server/src/data-access/controllers/admin/comment/index.ts b/core/server/src/data-access/controllers/admin/comment/index.ts index 9d4e6c35..17c1f09c 100644 --- a/core/server/src/data-access/controllers/admin/comment/index.ts +++ b/core/server/src/data-access/controllers/admin/comment/index.ts @@ -1,50 +1,23 @@ import { - createComment, getComment, getComments, hardDeleteComment, - updateComment, } from "../../../../use-cases/comment"; -import makeCreateCommentController from "./create-comment"; -import makeGetCommentController from "./get-comment"; import makeGetCommentsController from "./get-comments"; import makeHardDeleteCommentController from "./hard-delete-comment"; -import makeUpdateCommentController from "./update-comment"; const getCommentsController = makeGetCommentsController({ getComments, }); -const createCommentController = makeCreateCommentController({ - createComment, -}); - -const getCommentController = makeGetCommentController({ - getComment, -}); - const hardDeleteCommentController = makeHardDeleteCommentController({ getComment, hardDeleteComment, }); -const updateCommentController = makeUpdateCommentController({ - getComment, - updateComment, -}); - export default Object.freeze({ - getCommentController, hardDeleteCommentController, - updateCommentController, - createCommentController, getCommentsController, }); -export { - createCommentController, - getCommentController, - getCommentsController, - hardDeleteCommentController, - updateCommentController, -}; +export { getCommentsController, hardDeleteCommentController }; diff --git a/core/server/src/data-access/controllers/admin/comment/update-comment.spec.ts b/core/server/src/data-access/controllers/admin/comment/update-comment.spec.ts deleted file mode 100644 index aa77c7b1..00000000 --- a/core/server/src/data-access/controllers/admin/comment/update-comment.spec.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { fakeComment } from "../../../../../__tests__/__mock__"; -import { ExpectSingleResult } from "../../../../../__tests__/__types__/expect-types"; -import { - clearDatabase, - connectDatabase, -} from "../../../../../__tests__/jest-mongo"; -import { redis } from "../../../../../__tests__/jest-redis"; -import { HttpStatusCode } from "../../../../constants/http-status-code"; -import IComment from "../../../../database/interfaces/comment"; -import makeCreateComment from "../../../../use-cases/comment/create-comment"; -import makeGetComment from "../../../../use-cases/comment/get-comment"; -import makeUpdateComment from "../../../../use-cases/comment/update-comment"; -import makeCommentDb from "../../../make-comment-db"; -import { CommentModel } from "../../../models"; -import makeUpdateCommentController from "./update-comment"; - -describe("updateComment", () => { - beforeAll(async () => await connectDatabase()); - - afterAll( - async () => await Promise.all([clearDatabase(), redis.disconnect()]) - ); - - it("should return a body that contains an comment entity", async () => { - const headers = { - "Content-Type": "application/json", - }; - - const commentDb = makeCommentDb({ - commentDbModel: CommentModel, - }); - - const createComment = makeCreateComment({ commentDb }); - const getComment = makeGetComment({ commentDb }); - const updateComment = makeUpdateComment({ commentDb }); - - const mock_comment_data = fakeComment(); - - const updateCommentController = makeUpdateCommentController({ - getComment, - updateComment, - }); - - const created_comment = await createComment(mock_comment_data); - - const request = { - context: { - validated: created_comment, - }, - }; - - const result = await updateCommentController(request as any); - - const expected: ExpectSingleResult = { - headers, - statusCode: HttpStatusCode.OK, - body: result?.body, - }; - - expect(result).toEqual(expected); - }); -}); diff --git a/core/server/src/data-access/controllers/admin/comment/update-comment.ts b/core/server/src/data-access/controllers/admin/comment/update-comment.ts deleted file mode 100644 index 6340d3f3..00000000 --- a/core/server/src/data-access/controllers/admin/comment/update-comment.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { Request } from "express"; -import { get } from "lodash"; -import { HttpStatusCode } from "../../../../constants/http-status-code"; -import { GetComment } from "../../../../use-cases/comment/get-comment"; -import { - IUpdateCommentData, - UpdateComment, -} from "../../../../use-cases/comment/update-comment"; -import { isEmpty } from "../../../../utils/is-empty"; - -export default function makeUpdateCommentController({ - getComment, - updateComment, -}: { - getComment: GetComment; - updateComment: UpdateComment; -}) { - return async function updateCommentController( - httpRequest: Request & { context: {} } - ) { - const headers = { - "Content-Type": "application/json", - }; - - try { - const comment_details = ( - get(httpRequest, "context.validated", {}) - ); - const { _id } = comment_details; - - const exists = await getComment({ _id }); - if (isEmpty(exists)) { - throw new Error(`Comment by ${_id} does not exist`); - } - - const updated_comment = await updateComment(comment_details); - - return { - headers, - statusCode: HttpStatusCode.OK, - body: { - data: updated_comment, - }, - }; - } catch (error) { - throw { - headers, - statusCode: HttpStatusCode.INTERNAL_SERVER_ERROR, - body: { - data: error.message, - }, - }; - } - }; -} diff --git a/core/server/src/data-access/controllers/admin/comment/validators/get-comment.ts b/core/server/src/data-access/controllers/admin/comment/validators/get-comment.ts deleted file mode 100644 index 210ddcb8..00000000 --- a/core/server/src/data-access/controllers/admin/comment/validators/get-comment.ts +++ /dev/null @@ -1,5 +0,0 @@ -const getCommentRules = { - _id: ["required", "regex:/^[0-9a-fA-F]{24}$/i"], -}; - -export default getCommentRules; diff --git a/core/server/src/data-access/controllers/admin/comment/validators/index.ts b/core/server/src/data-access/controllers/admin/comment/validators/index.ts index 20c230da..e2e3ea6e 100644 --- a/core/server/src/data-access/controllers/admin/comment/validators/index.ts +++ b/core/server/src/data-access/controllers/admin/comment/validators/index.ts @@ -1,11 +1,7 @@ -import getCommentRules from "./get-comment"; import hardDeleteCommentRules from "./hard-delete-comment"; -import updateCommentRules from "./update-comment"; export default Object.freeze({ - getCommentRules, hardDeleteCommentRules, - updateCommentRules, }); -export { getCommentRules, hardDeleteCommentRules, updateCommentRules }; +export { hardDeleteCommentRules }; diff --git a/core/server/src/data-access/controllers/admin/comment/validators/update-comment.ts b/core/server/src/data-access/controllers/admin/comment/validators/update-comment.ts deleted file mode 100644 index 67ebf33e..00000000 --- a/core/server/src/data-access/controllers/admin/comment/validators/update-comment.ts +++ /dev/null @@ -1,5 +0,0 @@ -const updateCommentRules = { - _id: ["required", "regex:/^[0-9a-fA-F]{24}$/i"], -}; - -export default updateCommentRules; diff --git a/core/server/src/data-access/controllers/admin/subscription/get-subscription.spec.ts b/core/server/src/data-access/controllers/admin/subscription/get-subscription.spec.ts deleted file mode 100644 index a4b63932..00000000 --- a/core/server/src/data-access/controllers/admin/subscription/get-subscription.spec.ts +++ /dev/null @@ -1,65 +0,0 @@ -import moment from "moment"; -import { fakeSubscription } from "../../../../../__tests__/__mock__"; -import { ExpectSingleResult } from "../../../../../__tests__/__types__/expect-types"; -import { - clearDatabase, - connectDatabase, -} from "../../../../../__tests__/jest-mongo"; -import { redis } from "../../../../../__tests__/jest-redis"; -import { HttpStatusCode } from "../../../../constants/http-status-code"; -import ISubscription from "../../../../database/interfaces/subscription"; -import makeCreateSubscription from "../../../../use-cases/subscription/create-subscription"; -import makeGetSubscription from "../../../../use-cases/subscription/get-subscription"; -import makeSubscriptionDb from "../../../make-subscription-db"; -import { SubscriptionModel } from "../../../models"; -import makeGetSubscriptionController from "./get-subscription"; - -describe("getSubscription", () => { - beforeAll(async () => await connectDatabase()); - - afterAll( - async () => await Promise.all([clearDatabase(), redis.disconnect()]) - ); - - it("should return a body that contains an subscription entity", async () => { - const headers = { - "Content-Type": "application/json", - }; - - const subscriptionDb = makeSubscriptionDb({ - subscriptionDbModel: SubscriptionModel, - moment, - }); - - const createSubscription = makeCreateSubscription({ - subscriptionDb, - }); - const getSubscription = makeGetSubscription({ subscriptionDb }); - - const mock_subscription_data = fakeSubscription(); - - const created_subscription = await createSubscription( - mock_subscription_data - ); - - const getSubscriptionController = makeGetSubscriptionController({ - getSubscription, - }); - - const request = { - context: { - validated: { _id: created_subscription._id }, - }, - }; - - const result = await getSubscriptionController(request as any); - - const expected: ExpectSingleResult = { - headers, - statusCode: HttpStatusCode.OK, - body: result?.body, - }; - - expect(result).toEqual(expected); - }); -}); diff --git a/core/server/src/data-access/controllers/admin/subscription/get-subscription.ts b/core/server/src/data-access/controllers/admin/subscription/get-subscription.ts deleted file mode 100644 index 9345afeb..00000000 --- a/core/server/src/data-access/controllers/admin/subscription/get-subscription.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { Request } from "express"; -import { get } from "lodash"; -import { HttpStatusCode } from "../../../../constants/http-status-code"; -import { - GetSubscription, - IGetSubscriptionPayload, -} from "../../../../use-cases/subscription/get-subscription"; -import { isEmpty } from "../../../../utils/is-empty"; - -export default function makeGetSubscriptionController({ - getSubscription, -}: { - getSubscription: GetSubscription; -}) { - return async function getSubscriptionController( - httpRequest: Request & { context: {} } - ) { - const headers = { - "Content-Type": "application/json", - }; - - try { - const { _id } = ( - get(httpRequest, "context.validated", {}) - ); - - const exists = await getSubscription({ _id }); - - if (isEmpty(exists)) { - throw new Error(`Subscription ${_id} does not exists`); - } - - return { - headers, - statusCode: HttpStatusCode.OK, - body: { - data: exists, - }, - }; - } catch (error) { - throw { - headers, - statusCode: HttpStatusCode.INTERNAL_SERVER_ERROR, - body: { - data: error.message, - }, - }; - } - }; -} diff --git a/core/server/src/data-access/controllers/admin/subscription/index.ts b/core/server/src/data-access/controllers/admin/subscription/index.ts index ed3bdecd..2e297cc2 100644 --- a/core/server/src/data-access/controllers/admin/subscription/index.ts +++ b/core/server/src/data-access/controllers/admin/subscription/index.ts @@ -1,9 +1,7 @@ import { - getSubscription, getSubscriptionAnalystics, getSubscriptions, } from "../../../../use-cases/subscription"; -import makeGetSubscriptionController from "./get-subscription"; import makeGetSubscriptionAnalysticsController from "./get-subscription-analystics"; import makeGetSubscriptionsController from "./get-subscriptions"; @@ -16,18 +14,9 @@ const getSubscriptionsController = makeGetSubscriptionsController({ getSubscriptions, }); -const getSubscriptionController = makeGetSubscriptionController({ - getSubscription, -}); - export default Object.freeze({ - getSubscriptionController, getSubscriptionsController, getSubscriptionAnalysticsController, }); -export { - getSubscriptionAnalysticsController, - getSubscriptionController, - getSubscriptionsController, -}; +export { getSubscriptionAnalysticsController, getSubscriptionsController }; diff --git a/core/server/src/data-access/controllers/admin/subscription/validators/get-subscription.ts b/core/server/src/data-access/controllers/admin/subscription/validators/get-subscription.ts deleted file mode 100644 index 613427a9..00000000 --- a/core/server/src/data-access/controllers/admin/subscription/validators/get-subscription.ts +++ /dev/null @@ -1,5 +0,0 @@ -const getSubscriptionRules = { - _id: ["required", "regex:/^[0-9a-fA-F]{24}$/i"], -}; - -export default getSubscriptionRules; diff --git a/core/server/src/data-access/controllers/admin/subscription/validators/index.ts b/core/server/src/data-access/controllers/admin/subscription/validators/index.ts index ae5f6cc7..28cca7f3 100644 --- a/core/server/src/data-access/controllers/admin/subscription/validators/index.ts +++ b/core/server/src/data-access/controllers/admin/subscription/validators/index.ts @@ -1,9 +1,7 @@ -import getSubscriptionRules from "./get-subscription"; import getSubscriptionAnalysticsRules from "./get-subscription-analystics"; export default Object.freeze({ - getSubscriptionRules, getSubscriptionAnalysticsRules, }); -export { getSubscriptionRules, getSubscriptionAnalysticsRules }; +export { getSubscriptionAnalysticsRules }; diff --git a/core/server/src/data-access/controllers/admin/system-configuration/get-system-configuration.spec.ts b/core/server/src/data-access/controllers/admin/system-configuration/get-system-configuration.spec.ts deleted file mode 100644 index b05a90bd..00000000 --- a/core/server/src/data-access/controllers/admin/system-configuration/get-system-configuration.spec.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { fakeSystemConfiguration } from "../../../../../__tests__/__mock__"; -import { ExpectSingleResult } from "../../../../../__tests__/__types__/expect-types"; -import { - clearDatabase, - connectDatabase, -} from "../../../../../__tests__/jest-mongo"; -import { redis } from "../../../../../__tests__/jest-redis"; -import { HttpStatusCode } from "../../../../constants/http-status-code"; -import ISystemConfiguration from "../../../../database/interfaces/system-configuration"; -import makeCreateSystemConfiguration from "../../../../use-cases/system-configuration/create-system-configuration"; -import makeGetSystemConfiguration from "../../../../use-cases/system-configuration/get-system-configuraion"; -import makeSystemConfigurationDb from "../../../make-system-configuration-db"; -import { SystemConfigurationModel } from "../../../models"; -import makeGetSystemConfigurationController from "./get-system-configuration"; - -describe("getSystemConfiguration", () => { - beforeAll(async () => await connectDatabase()); - - afterAll( - async () => await Promise.all([clearDatabase(), redis.disconnect()]) - ); - - it("should return a body that contains an system configuration entity", async () => { - const headers = { - "Content-Type": "application/json", - }; - - const systemConfigurationDb = makeSystemConfigurationDb({ - systemConfigurationDbModel: SystemConfigurationModel, - }); - - const createSystemConfiguration = makeCreateSystemConfiguration({ - systemConfigurationDb, - }); - const getSystemConfiguration = makeGetSystemConfiguration({ - systemConfigurationDb, - }); - - const mock_system_configuration_data = fakeSystemConfiguration(); - - const created_system_configuration = await createSystemConfiguration( - mock_system_configuration_data - ); - - const getSystemConfigurationController = - makeGetSystemConfigurationController({ - getSystemConfiguration, - }); - - const request = { - context: { - validated: created_system_configuration, - }, - }; - - const result = await getSystemConfigurationController(request as any); - - const expected: ExpectSingleResult = { - headers, - statusCode: HttpStatusCode.OK, - body: result?.body, - }; - - expect(result).toEqual(expected); - }); -}); diff --git a/core/server/src/data-access/controllers/admin/system-configuration/get-system-configuration.ts b/core/server/src/data-access/controllers/admin/system-configuration/get-system-configuration.ts deleted file mode 100644 index 8a60a8c9..00000000 --- a/core/server/src/data-access/controllers/admin/system-configuration/get-system-configuration.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { Request } from "express"; -import { get } from "lodash"; -import { HttpStatusCode } from "../../../../constants/http-status-code"; -import { - GetSystemConfiguration, - IGetSystemConfigurationPayload, -} from "../../../../use-cases/system-configuration/get-system-configuraion"; -import { isEmpty } from "../../../../utils/is-empty"; - -export default function makeGetSystemConfigurationController({ - getSystemConfiguration, -}: { - getSystemConfiguration: GetSystemConfiguration; -}) { - return async function getSystemConfigurationController( - httpRequest: Request & { context: {} } - ) { - const headers = { - "Content-Type": "application/json", - }; - - try { - const { _id } = ( - get(httpRequest, "context.validated", {}) - ); - - const exists = await getSystemConfiguration({ _id }); - if (isEmpty(exists)) { - throw new Error(`SystemConfiguration ${_id} does not exists`); - } - - return { - headers, - statusCode: HttpStatusCode.OK, - body: { - data: exists, - }, - }; - } catch (error) { - throw { - headers, - statusCode: HttpStatusCode.INTERNAL_SERVER_ERROR, - body: { - data: error.message, - }, - }; - } - }; -} diff --git a/core/server/src/data-access/controllers/admin/system-configuration/index.ts b/core/server/src/data-access/controllers/admin/system-configuration/index.ts index 7749a7f0..e86da04d 100644 --- a/core/server/src/data-access/controllers/admin/system-configuration/index.ts +++ b/core/server/src/data-access/controllers/admin/system-configuration/index.ts @@ -5,7 +5,6 @@ import { updateSystemConfiguration, } from "../../../../use-cases/system-configuration"; import makeGetLatestSystemConfigurationController from "./get-latest-system-configuration"; -import makeGetSystemConfigurationController from "./get-system-configuration"; import makeUpdateSystemConfigurationController from "./update-system-configuration"; import makeUploadFolderIconController from "./upload-folder-icon"; import makeUploadOwnerAvatarController from "./upload-owner-avatar"; @@ -31,10 +30,6 @@ const getLatestSystemConfigurationController = getLatestSystemConfiguration, }); -const getSystemConfigurationController = makeGetSystemConfigurationController({ - getSystemConfiguration, -}); - const updateSystemConfigurationController = makeUpdateSystemConfigurationController({ getSystemConfiguration, @@ -43,7 +38,6 @@ const updateSystemConfigurationController = }); export default Object.freeze({ - getSystemConfigurationController, updateSystemConfigurationController, getLatestSystemConfigurationController, uploadClientAvatarController, @@ -53,7 +47,6 @@ export default Object.freeze({ export { getLatestSystemConfigurationController, - getSystemConfigurationController, updateSystemConfigurationController, uploadClientAvatarController, uploadFolderIconController, diff --git a/core/server/src/data-access/controllers/admin/system-configuration/validators/get-system-configuration.ts b/core/server/src/data-access/controllers/admin/system-configuration/validators/get-system-configuration.ts deleted file mode 100644 index 99ddb495..00000000 --- a/core/server/src/data-access/controllers/admin/system-configuration/validators/get-system-configuration.ts +++ /dev/null @@ -1,5 +0,0 @@ -const getSystemConfigurationRules = { - _id: ["required", "regex:/^[0-9a-fA-F]{24}$/i"], -}; - -export default getSystemConfigurationRules; diff --git a/core/server/src/data-access/controllers/admin/system-configuration/validators/index.ts b/core/server/src/data-access/controllers/admin/system-configuration/validators/index.ts index 8a360433..36fc174a 100644 --- a/core/server/src/data-access/controllers/admin/system-configuration/validators/index.ts +++ b/core/server/src/data-access/controllers/admin/system-configuration/validators/index.ts @@ -1,11 +1,9 @@ -import getSystemConfigurationRules from "./get-system-configuration"; import updateSystemConfigurationRules from "./update-system-configuration"; import uploadFolderIconRules from "./upload-folder-icon"; import uploadOwnerAvatarRules from "./upload-owner-avatar"; import uploadThumbnailRules from "./upload-thumbnail"; export default Object.freeze({ - getSystemConfigurationRules, updateSystemConfigurationRules, uploadOwnerAvatarRules, uploadFolderIconRules, @@ -13,9 +11,8 @@ export default Object.freeze({ }); export { - getSystemConfigurationRules, updateSystemConfigurationRules, - uploadOwnerAvatarRules, uploadFolderIconRules, + uploadOwnerAvatarRules, uploadThumbnailRules, }; diff --git a/core/server/src/routes/admin/comment.ts b/core/server/src/routes/admin/comment.ts index 08ae29fc..82e75a0d 100644 --- a/core/server/src/routes/admin/comment.ts +++ b/core/server/src/routes/admin/comment.ts @@ -1,14 +1,13 @@ import { Router } from "express"; -import makeValidator from "../../config/middlewares/validator"; import makeExpressCallback from "../../config/express-callback"; import makeAuthorization from "../../config/middlewares/authorization"; +import makeValidator from "../../config/middlewares/validator"; import { AuthorizationRole } from "../../constants/authorization-role"; - -import { hardDeleteCommentRules } from "../../data-access/controllers/admin/comment/validators"; import { - hardDeleteCommentController, getCommentsController, + hardDeleteCommentController, } from "../../data-access/controllers/admin/comment"; +import { hardDeleteCommentRules } from "../../data-access/controllers/admin/comment/validators"; const commentRouter = Router(); diff --git a/core/server/src/routes/api/comment.ts b/core/server/src/routes/api/comment.ts index 5086a612..3b78ae5d 100644 --- a/core/server/src/routes/api/comment.ts +++ b/core/server/src/routes/api/comment.ts @@ -1,29 +1,28 @@ import { Router } from "express"; -import makeValidator from "../../config/middlewares/validator"; import makeExpressCallback from "../../config/express-callback"; import authenticateUserJWT from "../../config/middlewares/authenticate-user-jwt"; - -import { - getCommentRules, - hardDeleteCommentRules, - updateCommentRules, - createCommentRules, - getCommentsByPostPaginatedRules, - replyCommentRules, - countCommentsByPostRules, - getCommentsByParentRules, -} from "../../data-access/controllers/user/comment/validators"; +import makeValidator from "../../config/middlewares/validator"; import { - getCommentController, - hardDeleteCommentController, - updateCommentController, + countCommentsByPostController, createCommentController, - getCommentsController, + getCommentController, + getCommentsByParentController, getCommentsByPostPaginatedController, + getCommentsController, + hardDeleteCommentController, replyCommentController, - countCommentsByPostController, - getCommentsByParentController, + updateCommentController, } from "../../data-access/controllers/user/comment"; +import { + countCommentsByPostRules, + createCommentRules, + getCommentRules, + getCommentsByParentRules, + getCommentsByPostPaginatedRules, + hardDeleteCommentRules, + replyCommentRules, + updateCommentRules, +} from "../../data-access/controllers/user/comment/validators"; const commentRouter = Router();