MCPcopy Create free account
hub / github.com/CodeWithHarry/Sigma-Web-Dev-Course / updateProfile

Function updateProfile

Video 131/actions/useractions.js:48–70  ·  view source on GitHub ↗
(data, oldusername)

Source from the content-addressed store, hash-verified

46}
47
48export 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

Callers 1

handleSubmitFunction · 0.90

Calls 1

connectDbFunction · 0.85

Tested by

no test coverage detected