File tree Expand file tree Collapse file tree 2 files changed +19
-15
lines changed Expand file tree Collapse file tree 2 files changed +19
-15
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import S3Policy from 's3-policy-v4';
33import s3 from '@auth0/s3' ;
44import mongoose from 'mongoose' ;
55import { getProjectsForUserId } from './project.controller' ;
6- import { findUserByUsername } from './ user.controller ' ;
6+ import User from '../models/ user' ;
77
88const { ObjectId } = mongoose . Types ;
99
@@ -237,10 +237,24 @@ export function listObjectsInS3ForUser(userId) {
237237
238238export function listObjectsInS3ForUserRequestHandler ( req , res ) {
239239 const { username } = req . user ;
240- findUserByUsername ( username , ( user ) => {
240+ User . findByUsername ( username , ( err , user ) => {
241+ if ( err ) {
242+ console . error ( 'Error fetching user:' , err . message ) ;
243+ res . status ( 500 ) . json ( { error : 'Failed to fetch user' } ) ;
244+ return ;
245+ }
246+ if ( ! user ) {
247+ res . status ( 404 ) . json ( { error : 'User not found' } ) ;
248+ return ;
249+ }
241250 const userId = user . id ;
242- listObjectsInS3ForUser ( userId ) . then ( ( objects ) => {
243- res . json ( objects ) ;
244- } ) ;
251+ listObjectsInS3ForUser ( userId )
252+ . then ( ( objects ) => {
253+ res . json ( objects ) ;
254+ } )
255+ . catch ( ( error ) => {
256+ console . error ( 'Error listing objects in S3:' , error . message ) ;
257+ res . status ( 500 ) . json ( { error : 'Failed to list objects in S3' } ) ;
258+ } ) ;
245259 } ) ;
246260}
Original file line number Diff line number Diff line change @@ -29,16 +29,6 @@ const random = (done) => {
2929 } ) ;
3030} ;
3131
32- export async function findUserByUsername ( username ) {
33- try {
34- const user = await User . findByUsername ( username ) ;
35- return user ;
36- } catch ( error ) {
37- console . error ( 'Error finding user by username:' , error . message ) ;
38- throw new Error ( 'Failed to find user by username' ) ;
39- }
40- }
41-
4232export function createUser ( req , res , next ) {
4333 const { username, email } = req . body ;
4434 const { password } = req . body ;
You can’t perform that action at this time.
0 commit comments