This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { useForm } from "react-hook-form"; | |
function onSubmitForm(formData) { | |
alert("Hi your phone number is: " + formData.phoneNumber); | |
} | |
export default function MyForm() { | |
const { register, handleSubmit } = useForm(); | |
return ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyFrom extends Component { | |
constructor(props) { | |
super(props); | |
this.state = {phoneNumber: ''}; | |
this.handleChangePhoneNumber = this.handleChangePhoneNumber.bind(this); | |
this.handleSubmit = this.handleSubmit.bind(this); | |
} | |
handleChangePhoneNumber(event) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import winston from 'winston'; | |
const logger = winston.createLogger({ | |
level: 'info', | |
format: winston.format.json(), | |
transports: [ | |
// | |
new winston.transports.File({ filename: 'stdout.log' }) | |
] | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// log setup | |
import winston from 'winston'; | |
const transports = { | |
console: new winston.transports.Console({ level: 'warn' }), | |
}; | |
const logger = winston.createLogger({ | |
transports: [transports.console, transports.file] | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logger from '../logSetup'; | |
processLoan(id: number, userId: number) { | |
try { | |
getLoanDeatilsById() | |
} catch(error) { | |
log.error(`Failed to do getLoanDetails with id ${id} hence throwing error`, error); | |
// good example: provide what failed, and how you are handling. | |
// e.g here on fail I am throwing | |
throw error; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logger from '../logSetup'; | |
processLoan(id: number, userId: number) { | |
try { | |
getLoanDeatilsById() | |
} catch(error) { | |
log.error(`Failed to do getLoanDetails with id ${id}, ignoring it and trying to getLoanDetailsByUserId`, error); | |
// good example: provide what failed, and how you are handling. | |
// e.g here on fail I am trying to call other function | |
getLoanDetailsByUserId(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logger from '../logSetup'; | |
createUser() { | |
logger.debug(">>>> Entering createUser"); | |
// ... process | |
logger.debug("Saving user loan {}", userInfoRepository.save(userInfo)) // don't do this | |
return true; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logger from '../logSetup'; | |
processLoan(...) { | |
logger.debug(">>>> Entering processLoan()"); | |
// ... process | |
logger.debug(`Processing user loan with id ${userService.getUser().getId()}`); | |
// this might throw error, when getUser returns undefined | |
logger.debug("<<<< Exiting processLoan()"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logger from '../logSetup'; | |
getInstallment(month: number, count: number ): number { | |
logger.debug(`>>>> Entering getInstallment(month = ${month}, count= ${count}`); | |
// process | |
const installment: number = 3; | |
log.debug("<<<< Exiting getIntallment()"); | |
return installment; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// REST implementation for getEmployeeById | |
router.get('/api/employees/:id', (req, res) => { | |
const employeeId = req.params.id; | |
return res.json(employeeService.getById(employeeId)); | |
}); |