Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOSIP-37899: Updated add devices integration #1050

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pmp-revamp-ui/public/i18n/ara.json
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@
"PMS_DEVICE_ERROR_005": "الهيئة الفرعية للتنفيذ غير موجودة.",
"PMS_DEVICE_ERROR_006": "الجهاز غير موجود.",
"PMS_DEVICE_ERROR_007": "الجهاز غير مرتبط بمعرف الشريك.",
"PMS_DEVICE_ERROR_008": "حدث خطأ أثناء إضافة تعيين جهاز غير نشط لـ sbi.",
"PMS_DEVICE_ERROR_008": "خطأ أثناء إضافة الجهاز إلى sbi.",
"PMS_DEVICE_ERROR_009": "نظرًا لأن SBI إما معطل أو لم تتم الموافقة عليه بعد.",
"PMS_DEVICE_ERROR_010": "تفاصيل الجهاز المحددة ليست في انتظار حالة الموافقة.",
"PMS_DEVICE_ERROR_011": "حدث خطأ أثناء الموافقة على الجهاز أو رفضه لرسم خرائط Sbi.",
Expand Down
2 changes: 1 addition & 1 deletion pmp-revamp-ui/public/i18n/eng.json
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@
"PMS_DEVICE_ERROR_005": "SBI do not exists.",
"PMS_DEVICE_ERROR_006": "Device do not exists.",
"PMS_DEVICE_ERROR_007": "Device is not associated with partner Id.",
"PMS_DEVICE_ERROR_008": "Error while adding inactive device mapping for sbi.",
"PMS_DEVICE_ERROR_008": "Error while adding device for sbi.",
"PMS_DEVICE_ERROR_009": "Given SBI is either deactivated or not approved yet.",
"PMS_DEVICE_ERROR_010": "Given device details are not in pending for approval status.",
"PMS_DEVICE_ERROR_011": "Error while approving or rejecting device for Sbi Mapping.",
Expand Down
2 changes: 1 addition & 1 deletion pmp-revamp-ui/public/i18n/fra.json
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@
"PMS_DEVICE_ERROR_005": "SBI n'existe pas.",
"PMS_DEVICE_ERROR_006": "L'appareil n'existe pas.",
"PMS_DEVICE_ERROR_007": "L'appareil n'est pas associé à l'ID du partenaire.",
"PMS_DEVICE_ERROR_008": "Erreur lors de l'ajout du mappage de périphériques inactifs pour sbi.",
"PMS_DEVICE_ERROR_008": "Erreur lors de l'ajout d'un périphérique pour sbi.",
"PMS_DEVICE_ERROR_009": "Étant donné que le SBI est soit désactivé, soit pas encore approuvé.",
"PMS_DEVICE_ERROR_010": "Les détails de l'appareil donné ne sont pas en attente d'approbation.",
"PMS_DEVICE_ERROR_011": "Erreur lors de l'approbation ou du rejet de l'appareil pour Sbi Mapping.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,93 +182,13 @@ function AddDevices() {
deviceSubTypeCode: entry.deviceSubType,
make: trimAndReplace(entry.make),
model: trimAndReplace(entry.model)
});
}, "mosip.pms.add.device.to.sbi.id.post", true);
try {
const response = await HttpService.post(getPartnerManagerUrl(`/devicedetail`, process.env.NODE_ENV), request);

if (response?.data?.response?.id) {
inactiveMappingDeviceToSbi(response.data.response.id, index, false);
} else {
const errorCode = response.data.errors[0].errorCode;
if (errorCode === "PMS_AUT_003") {
const deviceDetails = await searchDeviceDetails(entry, index);
if (deviceDetails && deviceDetails.id) {
inactiveMappingDeviceToSbi(deviceDetails.id, index, true);
} else {
newEntries[index].errorMsg = t('addDevices.errorInAddDevice');
setDeviceEntries(newEntries);
}
} else {
handleError(response.data, index, newEntries);
}
}
} catch (err) {
newEntries[index].errorMsg = t('addDevices.unableToAddDevice');
setDeviceEntries(newEntries);
console.error("Error fetching data: ", err);
}
setDataLoaded(true);
setIsSubmitClicked(false);
};

const searchDeviceDetails = async(entry, index) => {
const newEntries = [...deviceEntries];
setDataLoaded(false);
const searchRequest = createRequest({
filters: [
{"columnName": "deviceProviderId", "type": "equals", "value": selectedSbidata.partnerId},
{"columnName": "partnerOrganizationName", "type": "equals", "value": getUserProfile().orgName},
{"columnName": "deviceTypeCode", "type": "equals", "value": entry.deviceType},
{"columnName": "deviceSubTypeCode", "type": "equals", "value": entry.deviceSubType},
{"columnName": "make", "type": "equals", "value": trimAndReplace(entry.make)},
{"columnName": "model", "type": "equals", "value": trimAndReplace(entry.model)},
{"columnName": "approvalStatus", "type": "equals", "value": "pending_approval"}
],
sort: [],
pagination: {pageStart: 0, pageFetch: 100},
languageCode: "eng",
purpose: "REGISTRATION",
deviceProviderId: selectedSbidata.partnerId
});
try {
const response = await HttpService.post(getPartnerManagerUrl(`/devicedetail/search`, process.env.NODE_ENV), searchRequest);
if (response?.data?.response) {
const searchDetails = response.data.response.data;
let filteredItem = {};
if (searchDetails !== null) {
filteredItem = searchDetails.find(item => item.make === entry.make && item.model === entry.model);
}
return filteredItem;
} else {
handleError(response.data, index, newEntries);
}
} catch (err) {
newEntries[index].errorMsg = t('addDevices.unableToAddDevice');
setDeviceEntries(newEntries);
console.error("Error fetching data: ", err);
}
setDataLoaded(true);
};

const inactiveMappingDeviceToSbi = async (deviceDetailId, index, isDeviceAlreadyMapped) => {
const newEntries = [...deviceEntries];
setDataLoaded(false);
try {
const request = createRequest({
deviceDetailId: deviceDetailId,
sbiId: selectedSbidata.sbiId,
partnerId: selectedSbidata.partnerId
}, "mosip.pms.add.inactive.mapping.device.to.sbi.id.post", true);

const response = await HttpService.post(getPartnerManagerUrl(`/devicedetail/inactive-mapping-device-to-sbi`, process.env.NODE_ENV), request, {
headers: {
'Content-Type': 'application/json'
}
});
const response = await HttpService.post(getPartnerManagerUrl(`/securebiometricinterface/${selectedSbidata.sbiId}/devices`, process.env.NODE_ENV), request);

if (response?.data?.response) {
newEntries[index].isSubmitted = true;
newEntries[index].successMsg = isDeviceAlreadyMapped ? t('addDevices.successMsgForExistingDeviceMapping') : t('addDevices.successMsgForNewDeviceMapping');
newEntries[index].successMsg = t('addDevices.successMsgForNewDeviceMapping');
setDeviceEntries(newEntries);
updateButtonStates();
} else {
Expand All @@ -277,9 +197,10 @@ function AddDevices() {
} catch (err) {
newEntries[index].errorMsg = t('addDevices.unableToAddDevice');
setDeviceEntries(newEntries);
console.error('Error fetching data:', err);
console.error("Error fetching data: ", err);
}
setDataLoaded(true);
setIsSubmitClicked(false);
};

const handleError = (responseData, index, newEntries) => {
Expand Down
Loading