| 5 | const updatedRole = process.argv[3] ?? "1"; |
| 6 | |
| 7 | const updateUser = async () => { |
| 8 | await connect(); |
| 9 | const userRepository = connection!.getRepository(User); |
| 10 | userRepository.find({ id: userId }).then((user: any) => { |
| 11 | if (!user.length) { |
| 12 | console.error( "No user exists with the given id" ) |
| 13 | return; |
| 14 | } |
| 15 | const query = { id: user[0].id }; |
| 16 | const newValues = { user_role: updatedRole }; |
| 17 | userRepository |
| 18 | .update(query, newValues) |
| 19 | .then(() => console.log(`User updated successfully with role ${newValues.user_role}`) |
| 20 | ) |
| 21 | .catch((err) => console.error(`error in updating user: ${err.message}`) |
| 22 | ); |
| 23 | }) |
| 24 | .catch((err) => console.log(`error: ${err.message}`) |
| 25 | ) |
| 26 | }; |
| 27 | |
| 28 | updateUser(); |