| 4 | import Utils from '../utils'; |
| 5 | |
| 6 | export default class UsersController { |
| 7 | private static instance: UsersController; |
| 8 | private constructor() {} |
| 9 | |
| 10 | public static getInstance(): UsersController { |
| 11 | if (!UsersController.instance) { |
| 12 | UsersController.instance = new UsersController(); |
| 13 | } |
| 14 | return UsersController.instance; |
| 15 | } |
| 16 | |
| 17 | public async SayHelloEveryOne(req: Request, res: Response, next: NextFunction) { |
| 18 | const body = req.body as SampleArrayRequestBody[]; |
| 19 | try { |
| 20 | const updated = body.map((data) => { |
| 21 | data.name = 'Hello ' + data.name; |
| 22 | return data; |
| 23 | }); |
| 24 | res.status(200).send({ |
| 25 | status: 'success', |
| 26 | data: updated, |
| 27 | }); |
| 28 | } catch (e) { |
| 29 | next(e); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | public async GetAll(req: Request, res: Response, next: NextFunction) { |
| 34 | try { |
| 35 | const users = await User.find(); |
| 36 | res.status(200).send({ |
| 37 | users, |
| 38 | status: 'success', |
| 39 | }); |
| 40 | } catch (e) { |
| 41 | next(e); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | public async CreateUser(req: Request, res: Response, next: NextFunction) { |
| 46 | try { |
| 47 | const userReq = req.body; |
| 48 | const user = new User(); |
| 49 | user.firstName = userReq.firstName; |
| 50 | user.lastName = userReq.lastName; |
| 51 | user.email = userReq.email; |
| 52 | user.phone = userReq.phone; |
| 53 | user.password = Utils.HashPassword(userReq.password); |
| 54 | user.gender = userReq.gender; |
| 55 | await user.save(); |
| 56 | res.sendStatus(200); |
| 57 | } catch (e) { |
| 58 | next(e); |
| 59 | } |
| 60 | } |
| 61 | } |
nothing calls this directly
no outgoing calls
no test coverage detected