Fix build and implement user/all correctly
This commit is contained in:
parent
a9bd803112
commit
555dacfaf5
17 changed files with 170 additions and 48 deletions
|
|
@ -3,6 +3,7 @@ import { asyncHandler } from "../utils/asyncHandler.js";
|
|||
import { RecipeRepository } from "../repositories/RecipeRepository.js";
|
||||
import { CompactRecipeHandler } from "../handlers/CompactRecipeHandler.js";
|
||||
import { CompactRecipeDtoEntityMapper } from "../mappers/CompactRecipeDtoEntityMapper.js";
|
||||
import {HttpStatusCode} from "../apiHelpers/HttpStatusCodes.js";
|
||||
|
||||
/**
|
||||
* Handles all recipe related routes
|
||||
|
|
@ -10,9 +11,7 @@ import { CompactRecipeDtoEntityMapper } from "../mappers/CompactRecipeDtoEntityM
|
|||
const router = Router();
|
||||
|
||||
// Inject repo + mapper here
|
||||
const recipeRepository = new RecipeRepository();
|
||||
const compactRecipeMapper = new CompactRecipeDtoEntityMapper();
|
||||
const compactRecipeHandler = new CompactRecipeHandler(recipeRepository, compactRecipeMapper);
|
||||
const compactRecipeHandler = new CompactRecipeHandler(new RecipeRepository(), new CompactRecipeDtoEntityMapper());
|
||||
/**
|
||||
* Load header data of all recipes
|
||||
* Responds with a list of CompactRecipeDtos
|
||||
|
|
@ -26,7 +25,7 @@ router.get(
|
|||
const searchString : string = req.query.search ? req.query.search.toString().toLowerCase() : "";
|
||||
console.log("Searching for recipes with title containing", searchString)
|
||||
const response = await compactRecipeHandler.getMatchingRecipes(searchString);
|
||||
res.status(201).json(response);
|
||||
res.status(HttpStatusCode.OK).json(response);
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { RecipeDto } from "../dtos/RecipeDto.js";
|
|||
import { RecipeIngredientDtoEntityMapper } from "../mappers/RecipeIngredientDtoEntityMapper.js";
|
||||
import { RecipeIngredientGroupDtoEntityMapper } from "../mappers/RecipeIngredientGroupDtoEntityMapper.js";
|
||||
import { RecipeInstructionStepDtoEntityMapper } from "../mappers/RecipeInstructionStepDtoEntityMapper.js";
|
||||
import {HttpStatusCode} from "../apiHelpers/HttpStatusCodes.js";
|
||||
|
||||
/**
|
||||
* Handles all recipe related routes
|
||||
|
|
@ -35,7 +36,7 @@ router.post(
|
|||
asyncHandler(async(req, res) => {
|
||||
const requestDto: RecipeDto = req.body;
|
||||
const responseDto = await recipeHandler.createOrUpdateRecipe(requestDto);
|
||||
res.status(201).json(responseDto);
|
||||
res.status(HttpStatusCode.CREATED).json(responseDto);
|
||||
})
|
||||
)
|
||||
|
||||
|
|
@ -48,7 +49,7 @@ router.get(
|
|||
asyncHandler(async(req, res) => {
|
||||
const id = req.params.id;
|
||||
const responseDto = await recipeHandler.getRecipeById(id);
|
||||
res.status(201).json(responseDto);
|
||||
res.status(HttpStatusCode.OK).json(responseDto);
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,19 @@ import { UserDtoEntityMapper } from "../mappers/UserDtoEntityMapper.js";
|
|||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
import {CreateUserResponse} from "../dtos/CreateUserResponse.js";
|
||||
import {UserDto} from "../dtos/UserDto.js";
|
||||
import {requireAdmin} from "../middleware/authorizationMiddleware.js";
|
||||
import {UserListResponse} from "../dtos/UserListResponse.js";
|
||||
import {HttpStatusCode} from "../apiHelpers/HttpStatusCodes.js";
|
||||
|
||||
export const userBasicRoute = "/user";
|
||||
/**
|
||||
* Handles all user related routes
|
||||
*/
|
||||
const router = Router();
|
||||
router.use((req, res, next) => {
|
||||
console.log(`Incoming request: ${req.method} ${req.path}`);
|
||||
next();
|
||||
});
|
||||
|
||||
// Inject repo + mapper here
|
||||
const handler
|
||||
|
|
@ -42,9 +50,9 @@ router.post(
|
|||
asyncHandler(async (req, res) => {
|
||||
const dto : UserDto = req.body;
|
||||
const response = await handler.updateUserData(dto);
|
||||
res.status(201).json(response);
|
||||
res.status(HttpStatusCode.CREATED).json(response);
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Update password of existing user
|
||||
|
|
@ -56,7 +64,22 @@ router.post(
|
|||
asyncHandler(async (req, res) => {
|
||||
throw Error("not implemented!");
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Get all users (admin only)
|
||||
* Responds with array of UserDto
|
||||
*/
|
||||
router.get(
|
||||
"/all",
|
||||
//requireAdmin,
|
||||
asyncHandler(async (req, res) => {
|
||||
const id = req.currentUser?.id;
|
||||
const users = await handler.getAllUsers();
|
||||
const response : UserListResponse = {valueList: users}
|
||||
res.status(HttpStatusCode.OK).json(response);
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* Get user data for current user
|
||||
|
|
@ -67,9 +90,8 @@ router.get("/me",
|
|||
|
||||
const id = req.currentUser?.id;
|
||||
if(id){
|
||||
// it breaks here because id is no longer a uuid
|
||||
const responseDto = await handler.getUserById(id);
|
||||
res.status(201).json(responseDto);
|
||||
res.status(HttpStatusCode.OK).json(responseDto);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue