45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
export async function getListLineByItem(listReport) {
|
|
try {
|
|
// Mảng ban đầu
|
|
const list = [];
|
|
|
|
// Hàm kiểm tra xem một đối tượng có tồn tại trong mảng dựa trên thuộc tính nào đó
|
|
function kiemTraTonTai(mang, thuocTinh, giaTri) {
|
|
return mang.some((item) => item[thuocTinh] === giaTri);
|
|
}
|
|
|
|
// Thêm đối tượng vào mảng nếu thuộc tính không trùng
|
|
function themVaoMangNeuKhongTrung(mang, thuocTinh, giaTri, doiTuong) {
|
|
if (!kiemTraTonTai(mang, thuocTinh, giaTri)) {
|
|
mang.push(doiTuong);
|
|
}
|
|
}
|
|
|
|
listReport.map((u) => {
|
|
themVaoMangNeuKhongTrung(list, "detected_content", u.detected_content, u);
|
|
});
|
|
|
|
list.map((report, index) => {
|
|
list[index].line = [list[index].line];
|
|
});
|
|
|
|
list.map((report, index) => {
|
|
listReport.map((u) => {
|
|
if (
|
|
report.detected_content === u.detected_content &&
|
|
report.id_report !== u.id_report
|
|
) {
|
|
console.log(u.detected_content);
|
|
list[index].line = list[index].line?.concat(u.line);
|
|
if(report.created_at < u.created_at){
|
|
list[index].created_at = u.created_at
|
|
}
|
|
}
|
|
});
|
|
});
|
|
return list;
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
}
|