fix [P-263]: отправляю массивом
This commit is contained in:
1 parent
223d2e62ea
commit
b41bc76176
1 file changed
+17
-6
@@ -255,12 +255,10 @@ async function assignTest(testId, employeeIds, completionDate, startDate, news =
|
|||||||
startDate = testDetails.datestart;
|
startDate = testDetails.datestart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Преобразуем ID сотрудников в числовой формат и отправляем весь массив за один запрос
|
||||||
const userIds = Array.from(employeeIds).map(id => Number(id));
|
const userIds = Array.from(employeeIds).map(id => Number(id));
|
||||||
const promises = userIds.map(userId =>
|
await assignTestToUser(userIds, testId, completionDate, startDate, news);
|
||||||
assignTestToUser(userId, testId, completionDate, startDate, news)
|
|
||||||
);
|
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Ошибка назначения теста:', error);
|
console.error('Ошибка назначения теста:', error);
|
||||||
@@ -299,7 +297,16 @@ async function deleteTest(id) {
|
|||||||
|
|
||||||
async function assignTestToUser(userId, testId, completionDate, startDate, news = false) {
|
async function assignTestToUser(userId, testId, completionDate, startDate, news = false) {
|
||||||
try {
|
try {
|
||||||
|
if (Array.isArray(userId)) {
|
||||||
|
const response = await axiosApiInstance.post('/api/tests/testingview/', {
|
||||||
|
'user_id': userId.map(id => Number(id)),
|
||||||
|
test_id: Number(testId),
|
||||||
|
completion_date: completionDate,
|
||||||
|
datestart: startDate,
|
||||||
|
news: news
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
} else {
|
||||||
const response = await axiosApiInstance.post('/api/tests/testingview/', {
|
const response = await axiosApiInstance.post('/api/tests/testingview/', {
|
||||||
user_id: Number(userId),
|
user_id: Number(userId),
|
||||||
test_id: Number(testId),
|
test_id: Number(testId),
|
||||||
@@ -308,8 +315,12 @@ async function assignTestToUser(userId, testId, completionDate, startDate, news
|
|||||||
news: news
|
news: news
|
||||||
});
|
});
|
||||||
return response.data;
|
return response.data;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Ошибка назначения теста пользователю:", error);
|
const errorMsg = Array.isArray(userId)
|
||||||
|
? `Ошибка при назначении теста пользователям: ${error}`
|
||||||
|
: `Ошибка назначения теста пользователю ${userId}: ${error}`;
|
||||||
|
console.error(errorMsg);
|
||||||
console.error("Детали ошибки:", error.response?.data);
|
console.error("Детали ошибки:", error.response?.data);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user