File tree Expand file tree Collapse file tree 2 files changed +19
-11
lines changed Expand file tree Collapse file tree 2 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import S3Policy from 's3-policy-v4';
3
3
import s3 from '@auth0/s3' ;
4
4
import mongoose from 'mongoose' ;
5
5
import { getProjectsForUserId } from './project.controller' ;
6
- import { findUserByUsername } from './ user.controller ' ;
6
+ import User from '../models/ user' ;
7
7
8
8
const { ObjectId } = mongoose . Types ;
9
9
@@ -237,10 +237,24 @@ export function listObjectsInS3ForUser(userId) {
237
237
238
238
export function listObjectsInS3ForUserRequestHandler ( req , res ) {
239
239
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
+ }
241
250
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
+ } ) ;
245
259
} ) ;
246
260
}
Original file line number Diff line number Diff line change @@ -29,12 +29,6 @@ const random = (done) => {
29
29
} ) ;
30
30
} ;
31
31
32
- export function findUserByUsername ( username , cb ) {
33
- User . findByUsername ( username , ( err , user ) => {
34
- cb ( user ) ;
35
- } ) ;
36
- }
37
-
38
32
export function createUser ( req , res , next ) {
39
33
const { username, email } = req . body ;
40
34
const { password } = req . body ;
You can’t perform that action at this time.
0 commit comments