Currently, I am involved in a project with a VueJS application that incorporates the following helper class and method:
class BiometricMap {
static get(bioType) {
if (!bioType) {
return BiometricMap.default();
}
const bioTypes = {
40: () => this.getFace(),
41: () => this.getFace(),
42: () => this.getFace(),
43: () => this.getFace(),
60: () => this.getVoice(),
61: () => this.getVoice(),
140: () => this.getPin(),
141: () => this.getPin(),
150: () => this.getPalm(),
152: () => this.getPalm(),
};
return (bioTypes[bioType])();
}
static getFace() {
return {
friendly: 'Face',
type: 'face',
icon: 'face',
};
}
static getPalm() {
return {
friendly: 'Palm',
type: 'palm',
icon: 'pan_tool',
};
}
static getPin() {
return {
friendly: 'PIN',
type: 'pin',
icon: 'radio_button_checked',
};
}
static getVoice() {
return {
friendly: 'Voice',
type: 'voice',
icon: 'keyboard_voice',
};
}
static default() {
return {
friendly: '',
type: '',
icon: '',
};
}
}
export default BiometricMap;
My goal is to make it dynamic since the list of bioTypes
values can vary. Therefore, I made modifications to the get()
method as follows:
import BiometricService from '../services/BiometricService';
...
static async get(bioType) {
if (!bioType) {
return BiometricMap.default();
}
const bioTypes = {};
const baseBioTypes = await BiometricService.fetchAll();
baseBioTypes.data.forEach((type) => {
// Another instance where we need to change 'passphrase' to 'voice'.
const captureType = type.captureType === 'passphrase' ? 'voice' : type.captureType;
const methodName = `get${captureType.charAt(0).toUpperCase() + captureType.slice(1)}()`;
bioTypes[type.bioType] = () => this[methodName];
});
return (bioTypes[bioType])();
}
Despite successfully generating the value for methodName
and adding it to the bioTypes
object, the problem arises when reaching
return (bioTypes[bioType])();
as it does not trigger the corresponding method (e.g., getFace()
, getVoice()
, etc.). What adjustments should I make in how I populate the bioTypes
object to ensure the correct method is called?