Skip to content

Commit

Permalink
Use Promise.all and send result to controller
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejkang committed Aug 18, 2021
1 parent 3d54a36 commit 03b76b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,31 @@ export class CreateDriverLicenseVerificationUseCase implements UseCase<CreateDri
throw new Error('Serial number is required or has wrong format');
}

console.log(
await SafeDriving.retrieve({
const verification = await Promise.all([
SafeDriving.retrieve({
driverName,
driverBirthdayYear: driverBirthday.split('-')[0],
driverBirthdayMonth: driverBirthday.split('-')[1],
driverBirthdayDay: driverBirthday.split('-')[2],
licenseNumber,
serialNumber,
}),
);

console.log(
await Efine.retrieve({
Efine.retrieve({
driverName,
driverBirthdayYear: driverBirthday.split('-')[0],
driverBirthdayMonth: driverBirthday.split('-')[1],
driverBirthdayDay: driverBirthday.split('-')[2],
licenseNumber,
serialNumber,
}),
);
]).then((value) => {
return value;
});

const isValid = verification.some((request) => request);

return {
code: 'SUCCESS',
code: isValid ? 'SUCCESS' : 'FAILED',
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export class DriverLicenseVerificationController {
async useCase(
@Body() requestBody: DriverLicenseVerificationControllerRequestBody,
): Promise<DriverLicenseVerificationControllerSuccessfulResponse | DriverLicenseVerificationControllerFailedResponse> {
const result = await this.createDriverLicenseVerificationUseCase.execute({ ...requestBody });
const useCase = await this.createDriverLicenseVerificationUseCase.execute({ ...requestBody });
return {
isSuccess: true,
verificationResult: 'VALID',
verificationResult: useCase.code === 'SUCCESS' ? 'VALID' : 'INVALID',
};
}
}

0 comments on commit 03b76b2

Please sign in to comment.