I've repaired a few of those. You're right, it's a nightmare to do. You need to get hold of a connector from somewhere. Panda Bikes have the cable for £17.50:
https://www.pandaebikes.com/shop/extras/motor-cable-hall-effect-female-waterproof-male-waterproof-panda-pro/
Basically, you have to strip the motor right down. It's very hard to pull the rotor off the stator because of the magnets, and it's easy to damage the magnets when it goes back together. The magnet chips then grind between the two parts afterwards. When the rotor is separated from the stator, you have to carefully unsolder all the wires and pull them through the axle. Next, you have to thread the cable through, but it won't go round the corner. I shrunk some heatshrink over the end, which worked as a soft tongue to help guide it round, but it's still very difficult to pull it through. If you can get the wire through, you then strip the insulation, cut the wires to the right length and solder them. Finally, you have to put back all the insulation, which no longer fits because of your untidy soldering. Reassembly of the rest is easy apart from the chipping of the magnets, which means that you have to pull it all apart again to remove the chips.
I don't do it anymore. Bare motors are not too expensive, so you buy a new one and swap the cores. That's cheaper that buying a whole motor wheel.
When all that's sorted, it's time to think about a guard. All you need is some metal strip bent into a U shape with one end ground/filed out to a 12mm slot, so that you can slide it down behind the nut.