Skip to content

Commit

Permalink
feat: implement first steps of create category endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
riyoneri committed Nov 1, 2024
1 parent 5fbe0d9 commit 80c6f95
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
29 changes: 29 additions & 0 deletions src/controllers/admin/categories.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { NextFunction, Request, Response } from "express";

import { ServerErrorMessage, ValidationErrorMessage } from "../../constants";
import getCustomValidationResults from "../../helpers/get-validation-results";
import CustomError from "../../utils/custom-error";

export const createCategory = async (
request: Request,
response: Response,
next: NextFunction,
) => {
try {
const validationErrors = getCustomValidationResults(request);

if (validationErrors) {
const error = new CustomError(
ValidationErrorMessage,
400,
validationErrors,
);
return next(error);
}

response.status(400).json({ message: "😭💔💀" });
} catch {
const error = new CustomError(ServerErrorMessage);
next(error);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
ServerErrorMessage,
ValidationErrorMessage,
getNotFoundMessage,
} from "../constants";
import getCustomValidationResults from "../helpers/get-validation-results";
import { User } from "../models";
import { clientSocket } from "../sockets";
import CustomError from "../utils/custom-error";
} from "../../constants";
import getCustomValidationResults from "../../helpers/get-validation-results";
import { User } from "../../models";
import { clientSocket } from "../../sockets";
import CustomError from "../../utils/custom-error";

export const listCustomers = async (
request: Request,
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * as adminAuthController from "./admin-auth.controller";
export * as userAuthController from "./user-auth.controller";
export * as adminController from "./admin.controller";
export * as clientsController from "./admin/clients.controler";
export * as categoriesController from "./admin/categories.controller";

0 comments on commit 80c6f95

Please sign in to comment.