Use switch case to create instance
This commit is contained in:
parent
bbea9b2f0f
commit
2c181d49b0
1 changed files with 15 additions and 12 deletions
|
@ -2,17 +2,20 @@ export const UserServiceProvider = (function () {
|
||||||
let instance;
|
let instance;
|
||||||
|
|
||||||
async function createInstance(user) {
|
async function createInstance(user) {
|
||||||
if (user.role === 'STUDENT') {
|
switch (user.role) {
|
||||||
const service = await import('../services/student-service');
|
case 'STUDENT':
|
||||||
if (service) {
|
const studentService = await import('../services/student-service');
|
||||||
return new service.default(user);
|
if (studentService) {
|
||||||
|
return new studentService.default(user);
|
||||||
}
|
}
|
||||||
} else if (user.role === 'PROFESSOR') {
|
break;
|
||||||
const service = await import('../services/professor-service');
|
case 'PROFESSOR':
|
||||||
if (service) {
|
const professorService = await import('../services/professor-service');
|
||||||
return new service.default(user);
|
if (professorService) {
|
||||||
|
return new professorService.default(user);
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
throw new Error('Invalid Role!');
|
throw new Error('Invalid Role!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue