more refactor
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Has been cancelled
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Has been cancelled
This commit is contained in:
@@ -125,7 +125,7 @@ router.post(
|
||||
if (!req.file) return res.status(400).json({ message: 'No avatar file uploaded.' });
|
||||
const userProfile = req.user as UserProfile;
|
||||
const avatarUrl = `/uploads/avatars/${req.file.filename}`;
|
||||
const updatedProfile = await db.userRepo.updateUserProfile(userProfile.user_id, { avatar_url: avatarUrl }, req.log);
|
||||
const updatedProfile = await db.userRepo.updateUserProfile(userProfile.user.user_id, { avatar_url: avatarUrl }, req.log);
|
||||
res.json(updatedProfile);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -150,7 +150,7 @@ router.get(
|
||||
// Explicitly convert to numbers to ensure the repo receives correct types
|
||||
const limit = query.limit ? Number(query.limit) : 20;
|
||||
const offset = query.offset ? Number(query.offset) : 0;
|
||||
const notifications = await db.notificationRepo.getNotificationsForUser(userProfile.user_id, limit, offset, req.log);
|
||||
const notifications = await db.notificationRepo.getNotificationsForUser(userProfile.user.user_id, limit, offset, req.log);
|
||||
res.json(notifications);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -167,7 +167,7 @@ router.post(
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const userProfile = req.user as UserProfile;
|
||||
await db.notificationRepo.markAllNotificationsAsRead(userProfile.user_id, req.log);
|
||||
await db.notificationRepo.markAllNotificationsAsRead(userProfile.user.user_id, req.log);
|
||||
res.status(204).send(); // No Content
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -187,7 +187,7 @@ router.post(
|
||||
const userProfile = req.user as UserProfile;
|
||||
// Apply ADR-003 pattern for type safety
|
||||
const { params } = req as unknown as MarkNotificationReadRequest;
|
||||
await db.notificationRepo.markNotificationAsRead(params.notificationId, userProfile.user_id, req.log);
|
||||
await db.notificationRepo.markNotificationAsRead(params.notificationId, userProfile.user.user_id, req.log);
|
||||
res.status(204).send(); // Success, no content to return
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -202,8 +202,8 @@ router.get('/profile', validateRequest(emptySchema), async (req, res, next: Next
|
||||
logger.debug(`[ROUTE] GET /api/users/profile - ENTER`);
|
||||
const userProfile = req.user as UserProfile;
|
||||
try {
|
||||
logger.debug(`[ROUTE] Calling db.userRepo.findUserProfileById for user: ${userProfile.user_id}`);
|
||||
const fullUserProfile = await db.userRepo.findUserProfileById(userProfile.user_id, req.log);
|
||||
logger.debug(`[ROUTE] Calling db.userRepo.findUserProfileById for user: ${userProfile.user.user_id}`);
|
||||
const fullUserProfile = await db.userRepo.findUserProfileById(userProfile.user.user_id, req.log);
|
||||
res.json(fullUserProfile);
|
||||
} catch (error) {
|
||||
logger.error({ error }, `[ROUTE] GET /api/users/profile - ERROR`);
|
||||
@@ -221,7 +221,7 @@ router.put('/profile', validateRequest(updateProfileSchema), async (req, res, ne
|
||||
// Apply ADR-003 pattern for type safety
|
||||
const { body } = req as unknown as UpdateProfileRequest;
|
||||
try {
|
||||
const updatedProfile = await db.userRepo.updateUserProfile(userProfile.user_id, body, req.log);
|
||||
const updatedProfile = await db.userRepo.updateUserProfile(userProfile.user.user_id, body, req.log);
|
||||
res.json(updatedProfile);
|
||||
} catch (error) {
|
||||
logger.error({ error }, `[ROUTE] PUT /api/users/profile - ERROR`);
|
||||
@@ -242,7 +242,7 @@ router.put('/profile/password', validateRequest(updatePasswordSchema), async (re
|
||||
try {
|
||||
const saltRounds = 10;
|
||||
const hashedPassword = await bcrypt.hash(body.newPassword, saltRounds);
|
||||
await db.userRepo.updateUserPassword(userProfile.user_id, hashedPassword, req.log);
|
||||
await db.userRepo.updateUserPassword(userProfile.user.user_id, hashedPassword, req.log);
|
||||
res.status(200).json({ message: 'Password updated successfully.' });
|
||||
} catch (error) {
|
||||
logger.error({ error }, `[ROUTE] PUT /api/users/profile/password - ERROR`);
|
||||
@@ -261,7 +261,7 @@ router.delete('/account', validateRequest(deleteAccountSchema), async (req, res,
|
||||
const { body } = req as unknown as DeleteAccountRequest;
|
||||
|
||||
try {
|
||||
const userWithHash = await db.userRepo.findUserWithPasswordHashById(userProfile.user_id, req.log);
|
||||
const userWithHash = await db.userRepo.findUserWithPasswordHashById(userProfile.user.user_id, req.log);
|
||||
if (!userWithHash || !userWithHash.password_hash) {
|
||||
return res.status(404).json({ message: 'User not found or password not set.' });
|
||||
}
|
||||
@@ -271,7 +271,7 @@ router.delete('/account', validateRequest(deleteAccountSchema), async (req, res,
|
||||
return res.status(403).json({ message: 'Incorrect password.' });
|
||||
}
|
||||
|
||||
await db.userRepo.deleteUserById(userProfile.user_id, req.log);
|
||||
await db.userRepo.deleteUserById(userProfile.user.user_id, req.log);
|
||||
res.status(200).json({ message: 'Account deleted successfully.' });
|
||||
} catch (error) {
|
||||
logger.error({ error }, `[ROUTE] DELETE /api/users/account - ERROR`);
|
||||
@@ -286,7 +286,7 @@ router.get('/watched-items', validateRequest(emptySchema), async (req, res, next
|
||||
logger.debug(`[ROUTE] GET /api/users/watched-items - ENTER`);
|
||||
const userProfile = req.user as UserProfile;
|
||||
try {
|
||||
const items = await db.personalizationRepo.getWatchedItems(userProfile.user_id, req.log);
|
||||
const items = await db.personalizationRepo.getWatchedItems(userProfile.user.user_id, req.log);
|
||||
res.json(items);
|
||||
} catch (error) {
|
||||
logger.error({ error }, `[ROUTE] GET /api/users/watched-items - ERROR`);
|
||||
@@ -304,7 +304,7 @@ router.post('/watched-items', validateRequest(addWatchedItemSchema), async (req,
|
||||
// Apply ADR-003 pattern for type safety
|
||||
const { body } = req as unknown as AddWatchedItemRequest;
|
||||
try {
|
||||
const newItem = await db.personalizationRepo.addWatchedItem(userProfile.user_id, body.itemName, body.category, req.log);
|
||||
const newItem = await db.personalizationRepo.addWatchedItem(userProfile.user.user_id, body.itemName, body.category, req.log);
|
||||
res.status(201).json(newItem);
|
||||
} catch (error) {
|
||||
if (error instanceof ForeignKeyConstraintError) {
|
||||
@@ -330,7 +330,7 @@ router.delete('/watched-items/:masterItemId', validateRequest(watchedItemIdSchem
|
||||
// Apply ADR-003 pattern for type safety
|
||||
const { params } = req as unknown as DeleteWatchedItemRequest;
|
||||
try {
|
||||
await db.personalizationRepo.removeWatchedItem(userProfile.user_id, params.masterItemId, req.log);
|
||||
await db.personalizationRepo.removeWatchedItem(userProfile.user.user_id, params.masterItemId, req.log);
|
||||
res.status(204).send();
|
||||
} catch (error) {
|
||||
logger.error({ error }, `[ROUTE] DELETE /api/users/watched-items/:masterItemId - ERROR`);
|
||||
@@ -345,7 +345,7 @@ router.get('/shopping-lists', validateRequest(emptySchema), async (req, res, nex
|
||||
logger.debug(`[ROUTE] GET /api/users/shopping-lists - ENTER`);
|
||||
const userProfile = req.user as UserProfile;
|
||||
try {
|
||||
const lists = await db.shoppingRepo.getShoppingLists(userProfile.user_id, req.log);
|
||||
const lists = await db.shoppingRepo.getShoppingLists(userProfile.user.user_id, req.log);
|
||||
res.json(lists);
|
||||
} catch (error) {
|
||||
logger.error({ error }, `[ROUTE] GET /api/users/shopping-lists - ERROR`);
|
||||
@@ -363,7 +363,7 @@ router.get('/shopping-lists/:listId', validateRequest(shoppingListIdSchema), asy
|
||||
const userProfile = req.user as UserProfile;
|
||||
const { params } = req as unknown as GetShoppingListRequest;
|
||||
try {
|
||||
const list = await db.shoppingRepo.getShoppingListById(params.listId, userProfile.user_id, req.log);
|
||||
const list = await db.shoppingRepo.getShoppingListById(params.listId, userProfile.user.user_id, req.log);
|
||||
res.json(list);
|
||||
} catch (error) {
|
||||
logger.error({ error, listId: params.listId }, `[ROUTE] GET /api/users/shopping-lists/:listId - ERROR`);
|
||||
@@ -381,7 +381,7 @@ router.post('/shopping-lists', validateRequest(createShoppingListSchema), async
|
||||
// Apply ADR-003 pattern for type safety
|
||||
const { body } = req as unknown as CreateShoppingListRequest;
|
||||
try {
|
||||
const newList = await db.shoppingRepo.createShoppingList(userProfile.user_id, body.name, req.log);
|
||||
const newList = await db.shoppingRepo.createShoppingList(userProfile.user.user_id, body.name, req.log);
|
||||
res.status(201).json(newList);
|
||||
} catch (error) {
|
||||
if (error instanceof ForeignKeyConstraintError) {
|
||||
@@ -405,7 +405,7 @@ router.delete('/shopping-lists/:listId', validateRequest(shoppingListIdSchema),
|
||||
// Apply ADR-003 pattern for type safety
|
||||
const { params } = req as unknown as GetShoppingListRequest;
|
||||
try {
|
||||
await db.shoppingRepo.deleteShoppingList(params.listId, userProfile.user_id, req.log);
|
||||
await db.shoppingRepo.deleteShoppingList(params.listId, userProfile.user.user_id, req.log);
|
||||
res.status(204).send();
|
||||
} catch (error: unknown) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'An unknown error occurred';
|
||||
@@ -498,7 +498,7 @@ router.put('/profile/preferences', validateRequest(updatePreferencesSchema), asy
|
||||
// Apply ADR-003 pattern for type safety
|
||||
const { body } = req as unknown as UpdatePreferencesRequest;
|
||||
try {
|
||||
const updatedProfile = await db.userRepo.updateUserPreferences(userProfile.user_id, body, req.log);
|
||||
const updatedProfile = await db.userRepo.updateUserPreferences(userProfile.user.user_id, body, req.log);
|
||||
res.json(updatedProfile);
|
||||
} catch (error) {
|
||||
logger.error({ error }, `[ROUTE] PUT /api/users/profile/preferences - ERROR`);
|
||||
@@ -510,7 +510,7 @@ router.get('/me/dietary-restrictions', validateRequest(emptySchema), async (req,
|
||||
logger.debug(`[ROUTE] GET /api/users/me/dietary-restrictions - ENTER`);
|
||||
const userProfile = req.user as UserProfile;
|
||||
try {
|
||||
const restrictions = await db.personalizationRepo.getUserDietaryRestrictions(userProfile.user_id, req.log);
|
||||
const restrictions = await db.personalizationRepo.getUserDietaryRestrictions(userProfile.user.user_id, req.log);
|
||||
res.json(restrictions);
|
||||
} catch (error) {
|
||||
logger.error({ error }, `[ROUTE] GET /api/users/me/dietary-restrictions - ERROR`);
|
||||
@@ -528,7 +528,7 @@ router.put('/me/dietary-restrictions', validateRequest(setUserRestrictionsSchema
|
||||
// Apply ADR-003 pattern for type safety
|
||||
const { body } = req as unknown as SetUserRestrictionsRequest;
|
||||
try {
|
||||
await db.personalizationRepo.setUserDietaryRestrictions(userProfile.user_id, body.restrictionIds, req.log);
|
||||
await db.personalizationRepo.setUserDietaryRestrictions(userProfile.user.user_id, body.restrictionIds, req.log);
|
||||
res.status(204).send();
|
||||
} catch (error) {
|
||||
if (error instanceof ForeignKeyConstraintError) {
|
||||
@@ -547,7 +547,7 @@ router.get('/me/appliances', validateRequest(emptySchema), async (req, res, next
|
||||
logger.debug(`[ROUTE] GET /api/users/me/appliances - ENTER`);
|
||||
const userProfile = req.user as UserProfile;
|
||||
try {
|
||||
const appliances = await db.personalizationRepo.getUserAppliances(userProfile.user_id, req.log);
|
||||
const appliances = await db.personalizationRepo.getUserAppliances(userProfile.user.user_id, req.log);
|
||||
res.json(appliances);
|
||||
} catch (error) {
|
||||
logger.error({ error }, `[ROUTE] GET /api/users/me/appliances - ERROR`);
|
||||
@@ -565,7 +565,7 @@ router.put('/me/appliances', validateRequest(setUserAppliancesSchema), async (re
|
||||
// Apply ADR-003 pattern for type safety
|
||||
const { body } = req as unknown as SetUserAppliancesRequest;
|
||||
try {
|
||||
await db.personalizationRepo.setUserAppliances(userProfile.user_id, body.applianceIds, req.log);
|
||||
await db.personalizationRepo.setUserAppliances(userProfile.user.user_id, body.applianceIds, req.log);
|
||||
res.status(204).send();
|
||||
} catch (error) {
|
||||
if (error instanceof ForeignKeyConstraintError) {
|
||||
@@ -644,7 +644,7 @@ router.delete('/recipes/:recipeId', validateRequest(recipeIdSchema), async (req,
|
||||
// Apply ADR-003 pattern for type safety
|
||||
const { params } = req as unknown as DeleteRecipeRequest;
|
||||
try {
|
||||
await db.recipeRepo.deleteRecipe(params.recipeId, userProfile.user_id, false, req.log);
|
||||
await db.recipeRepo.deleteRecipe(params.recipeId, userProfile.user.user_id, false, req.log);
|
||||
res.status(204).send();
|
||||
} catch (error) {
|
||||
logger.error({ error, params: req.params }, `[ROUTE] DELETE /api/users/recipes/:recipeId - ERROR`);
|
||||
@@ -674,7 +674,7 @@ router.put('/recipes/:recipeId', validateRequest(updateRecipeSchema), async (req
|
||||
const { params, body } = req as unknown as UpdateRecipeRequest;
|
||||
|
||||
try {
|
||||
const updatedRecipe = await db.recipeRepo.updateRecipe(params.recipeId, userProfile.user_id, body, req.log);
|
||||
const updatedRecipe = await db.recipeRepo.updateRecipe(params.recipeId, userProfile.user.user_id, body, req.log);
|
||||
res.json(updatedRecipe);
|
||||
} catch (error) {
|
||||
logger.error({ error, params: req.params, body: req.body }, `[ROUTE] PUT /api/users/recipes/:recipeId - ERROR`);
|
||||
|
||||
Reference in New Issue
Block a user