File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change 1- import { OptionalId , Document } from 'mongodb' ;
1+ import { OptionalId , Document , ObjectId } from 'mongodb' ;
22import { toClass } from '../helper' ;
33import { User } from '../types' ;
44import { connect } from './helper' ;
@@ -55,7 +55,9 @@ export const updateUser = async (user: User): Promise<void> => {
5555 if ( user . email ) {
5656 user . email = user . email . toLowerCase ( ) ;
5757 }
58+ const { _id, ...userWithoutId } = user ;
59+ const filter = _id ? { _id : new ObjectId ( _id ) } : { username : user . username } ;
5860 const options = { upsert : true } ;
5961 const collection = await connect ( collectionName ) ;
60- await collection . updateOne ( { username : user . username } , { $set : user } , options ) ;
62+ await collection . updateOne ( filter , { $set : userWithoutId } , options ) ;
6163} ;
You can’t perform that action at this time.
0 commit comments