(data, oldusername)
| 46 | } |
| 47 | |
| 48 | export const updateProfile = async (data, oldusername) => { |
| 49 | await connectDb() |
| 50 | let ndata = Object.fromEntries(data) |
| 51 | |
| 52 | // If the username is being updated, check if username is available |
| 53 | if (oldusername !== ndata.username) { |
| 54 | let u = await User.findOne({ username: ndata.username }) |
| 55 | if (u) { |
| 56 | return { error: "Username already exists" } |
| 57 | } |
| 58 | await User.updateOne({email: ndata.email}, ndata) |
| 59 | // Now update all the usernames in the Payments table |
| 60 | await Payment.updateMany({to_user: oldusername}, {to_user: ndata.username}) |
| 61 | |
| 62 | } |
| 63 | else{ |
| 64 | |
| 65 | |
| 66 | await User.updateOne({email: ndata.email}, ndata) |
| 67 | } |
| 68 | |
| 69 | |
| 70 | } |
| 71 | |
| 72 |
no test coverage detected