import * as express from 'express' ; import User from '../models/User' ; const router = express . Router ( ) ; router . get ( '/get-user' , ( req , res ) => { console . log ( req . user ) ; res . json ( { user : req . user || null } ) ; } ) ; router . post ( '/get-user-by-slug' , async ( req , res , next ) => { console . log ( 'Express route: /get-user-by-slug' ) ; try { const { slug } = req . body ; const user = await User . getUserBySlug ( { slug } ) ; res . json ( { user } ) ; } catch ( err ) { next ( err ) ; } } ) ; router . post ( '/user/update-profile' , async ( req , res , next ) => { try { const { name , avatarUrl } = req . body ; const updatedUser = await User . updateProfile ( { userId : req . user . id , name , avatarUrl } ) ; res . json ( { updatedUser } ) ; } catch ( err ) { next ( err ) ; } } ) ; export default router ;