Skip to content

Commit

Permalink
cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
huytran17 committed Jun 5, 2024
1 parent 370e1dc commit a94bdae
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Request } from "express";
import { get } from "lodash";
import { GetLatestSystemConfiguration } from "../../../../use-cases/system-configuration/get-latest-system-configuration";
import { UpdateSystemConfiguration } from "../../../../use-cases/system-configuration/update-system-configuraion";
import { HttpStatusCode } from "../../../../constants/http-status-code";
import { isEmpty } from "../../../../utils/is-empty";
import {
GetSystemConfiguration,
IGetSystemConfigurationPayload,
} from "../../../../use-cases/system-configuration/get-system-configuraion";
import { UpdateSystemConfiguration } from "../../../../use-cases/system-configuration/update-system-configuraion";
import deleteS3Object from "../../../../utils/delete-s3-object";
import { isEmpty } from "../../../../utils/is-empty";

export default function makeUploadFolderIconController({
getLatestSystemConfiguration,
getSystemConfiguration,
updateSystemConfiguration,
}: {
getLatestSystemConfiguration: GetLatestSystemConfiguration;
getSystemConfiguration: GetSystemConfiguration;
updateSystemConfiguration: UpdateSystemConfiguration;
}) {
return async function uploadFolderIconController(
Expand All @@ -21,7 +24,11 @@ export default function makeUploadFolderIconController({
};

try {
const exists = await getLatestSystemConfiguration();
const { _id } = <IGetSystemConfigurationPayload>(
get(httpRequest, "context.validated", {})
);

const exists = await getSystemConfiguration({ _id });

if (isEmpty(exists)) {
throw new Error(`System configuration by ${exists._id} does not exist`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Request } from "express";
import { get } from "lodash";
import { GetLatestSystemConfiguration } from "../../../../use-cases/system-configuration/get-latest-system-configuration";
import { UpdateSystemConfiguration } from "../../../../use-cases/system-configuration/update-system-configuraion";
import { HttpStatusCode } from "../../../../constants/http-status-code";
import { isEmpty } from "../../../../utils/is-empty";
import {
GetSystemConfiguration,
IGetSystemConfigurationPayload,
} from "../../../../use-cases/system-configuration/get-system-configuraion";
import { UpdateSystemConfiguration } from "../../../../use-cases/system-configuration/update-system-configuraion";
import deleteS3Object from "../../../../utils/delete-s3-object";
import { isEmpty } from "../../../../utils/is-empty";

export default function makeUploadOwnerAvatarController({
getLatestSystemConfiguration,
getSystemConfiguration,
updateSystemConfiguration,
}: {
getLatestSystemConfiguration: GetLatestSystemConfiguration;
getSystemConfiguration: GetSystemConfiguration;
updateSystemConfiguration: UpdateSystemConfiguration;
}) {
return async function uploadClientAvatarController(
Expand All @@ -21,7 +24,11 @@ export default function makeUploadOwnerAvatarController({
};

try {
const exists = await getLatestSystemConfiguration();
const { _id } = <IGetSystemConfigurationPayload>(
get(httpRequest, "context.validated", {})
);

const exists = await getSystemConfiguration({ _id });

if (isEmpty(exists)) {
throw new Error(`System configuration by ${exists._id} does not exist`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Request } from "express";
import { get } from "lodash";
import { GetLatestSystemConfiguration } from "../../../../use-cases/system-configuration/get-latest-system-configuration";
import { UpdateSystemConfiguration } from "../../../../use-cases/system-configuration/update-system-configuraion";
import { HttpStatusCode } from "../../../../constants/http-status-code";
import { isEmpty } from "../../../../utils/is-empty";
import {
GetSystemConfiguration,
IGetSystemConfigurationPayload,
} from "../../../../use-cases/system-configuration/get-system-configuraion";
import { UpdateSystemConfiguration } from "../../../../use-cases/system-configuration/update-system-configuraion";
import deleteS3Object from "../../../../utils/delete-s3-object";
import { isEmpty } from "../../../../utils/is-empty";

export default function makeUploadThumbnaiilController({
getLatestSystemConfiguration,
getSystemConfiguration,
updateSystemConfiguration,
}: {
getLatestSystemConfiguration: GetLatestSystemConfiguration;
getSystemConfiguration: GetSystemConfiguration;
updateSystemConfiguration: UpdateSystemConfiguration;
}) {
return async function uploadThumbnaiilController(
Expand All @@ -21,7 +24,11 @@ export default function makeUploadThumbnaiilController({
};

try {
const exists = await getLatestSystemConfiguration();
const { _id } = <IGetSystemConfigurationPayload>(
get(httpRequest, "context.validated", {})
);

const exists = await getSystemConfiguration({ _id });

if (isEmpty(exists)) {
throw new Error(`System configuration by ${exists._id} does not exist`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { Request } from "express";
import { get } from "lodash";
import { HttpStatusCode } from "../../../../../constants/http-status-code";
import { GetLatestSystemConfiguration } from "../../../../../use-cases/system-configuration/get-latest-system-configuration";
import {
GetSystemConfiguration,
IGetSystemConfigurationPayload,
} from "../../../../../use-cases/system-configuration/get-system-configuraion";
import { UpdateSystemConfiguration } from "../../../../../use-cases/system-configuration/update-system-configuraion";
import deleteUploadedFile from "../../../../../utils/delete-uploaded-file";
import getFIleUploadedPath from "../../../../../utils/get-file-uploaded-path";
import { isEmpty } from "../../../../../utils/is-empty";

export default function makeUploadFolderIconController({
getLatestSystemConfiguration,
getSystemConfiguration,
updateSystemConfiguration,
}: {
getLatestSystemConfiguration: GetLatestSystemConfiguration;
getSystemConfiguration: GetSystemConfiguration;
updateSystemConfiguration: UpdateSystemConfiguration;
}) {
return async function uploadFolderIconController(
Expand All @@ -22,7 +25,11 @@ export default function makeUploadFolderIconController({
};

try {
const exists = await getLatestSystemConfiguration();
const { _id } = <IGetSystemConfigurationPayload>(
get(httpRequest, "context.validated", {})
);

const exists = await getSystemConfiguration({ _id });

if (isEmpty(exists)) {
throw new Error(`System configuration by ${exists._id} does not exist`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { Request } from "express";
import { get } from "lodash";
import { HttpStatusCode } from "../../../../../constants/http-status-code";
import { GetLatestSystemConfiguration } from "../../../../../use-cases/system-configuration/get-latest-system-configuration";
import { UpdateSystemConfiguration } from "../../../../../use-cases/system-configuration/update-system-configuraion";
import deleteUploadedFile from "../../../../../utils/delete-uploaded-file";
import getFIleUploadedPath from "../../../../../utils/get-file-uploaded-path";
import { isEmpty } from "../../../../../utils/is-empty";
import {
GetSystemConfiguration,
IGetSystemConfigurationPayload,
} from "../../../../../use-cases/system-configuration/get-system-configuraion";

export default function makeUploadOwnerAvatarController({
getLatestSystemConfiguration,
getSystemConfiguration,
updateSystemConfiguration,
}: {
getLatestSystemConfiguration: GetLatestSystemConfiguration;
getSystemConfiguration: GetSystemConfiguration;
updateSystemConfiguration: UpdateSystemConfiguration;
}) {
return async function uploadClientAvatarController(
Expand All @@ -22,7 +25,11 @@ export default function makeUploadOwnerAvatarController({
};

try {
const exists = await getLatestSystemConfiguration();
const { _id } = <IGetSystemConfigurationPayload>(
get(httpRequest, "context.validated", {})
);

const exists = await getSystemConfiguration({ _id });

if (isEmpty(exists)) {
throw new Error(`System configuration by ${exists._id} does not exist`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { Request } from "express";
import { get } from "lodash";
import { HttpStatusCode } from "../../../../../constants/http-status-code";
import { GetLatestSystemConfiguration } from "../../../../../use-cases/system-configuration/get-latest-system-configuration";
import {
GetSystemConfiguration,
IGetSystemConfigurationPayload,
} from "../../../../../use-cases/system-configuration/get-system-configuraion";
import { UpdateSystemConfiguration } from "../../../../../use-cases/system-configuration/update-system-configuraion";
import deleteUploadedFile from "../../../../../utils/delete-uploaded-file";
import getFIleUploadedPath from "../../../../../utils/get-file-uploaded-path";
import { isEmpty } from "../../../../../utils/is-empty";

export default function makeUploadThumbnaiilController({
getLatestSystemConfiguration,
getSystemConfiguration,
updateSystemConfiguration,
}: {
getLatestSystemConfiguration: GetLatestSystemConfiguration;
getSystemConfiguration: GetSystemConfiguration;
updateSystemConfiguration: UpdateSystemConfiguration;
}) {
return async function uploadThumbnaiilController(
Expand All @@ -22,7 +25,11 @@ export default function makeUploadThumbnaiilController({
};

try {
const exists = await getLatestSystemConfiguration();
const { _id } = <IGetSystemConfigurationPayload>(
get(httpRequest, "context.validated", {})
);

const exists = await getSystemConfiguration({ _id });

if (isEmpty(exists)) {
throw new Error(`System configuration by ${exists._id} does not exist`);
Expand Down
7 changes: 7 additions & 0 deletions core/server/src/routes/admin/v2/system-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ systemConfigurationRouter.post(
makeExpressCallback(uploadThumbnaiilController)
);

systemConfigurationRouter.post(
"/upload-excel-template/:type/:_id",
makeAuthorization(AuthorizationRole.ONLY_OWNER),
makeValidator(uploadThumbnailRules),
makeExpressCallback(uploadThumbnaiilController)
);

export default systemConfigurationRouter;

0 comments on commit a94bdae

Please sign in to comment.