Solved some problems with the excel of master statistical

This commit is contained in:
Tiago Ribeiro
2024-09-10 12:00:14 +01:00
parent 33a46c227b
commit 2a10933206
8 changed files with 448 additions and 522 deletions

View File

@@ -6,6 +6,28 @@ import {Module} from "@/interfaces";
import {getCorporateUser} from "@/resources/user";
import {getUserCorporate} from "./groups.be";
import {Db, ObjectId} from "mongodb";
import client from "@/lib/mongodb";
import {MODULE_ARRAY} from "./moduleUtils";
const db = client.db(process.env.MONGODB_DB);
export async function getSpecificExams(ids: string[]) {
if (ids.length === 0) return [];
const exams: Exam[] = (
await Promise.all(
MODULE_ARRAY.flatMap(
async (module) =>
await db
.collection(module)
.find<Exam>({id: {$in: ids}})
.toArray(),
),
)
).flat();
return exams;
}
export const getExams = async (
db: Db,

View File

@@ -1,4 +1,3 @@
/*fields example = [
['id'],
['companyInformation', 'companyInformation', 'name']
@@ -13,17 +12,18 @@ const getFieldValue = (fields: string[], data: any): string => {
};
export const search = (text: string, fields: string[][], rows: any[]) => {
const searchText = text.toLowerCase();
return rows.filter((row) => {
return fields.some((fieldsKeys) => {
const value = getFieldValue(fieldsKeys, row);
if (typeof value === "string") {
return value.toLowerCase().includes(searchText);
}
const searchText = text.toLowerCase();
return rows.filter((row) => {
return fields.some((fieldsKeys) => {
const value = getFieldValue(fieldsKeys, row);
if (typeof value === "string") {
console.log(value, searchText, value.toLowerCase().includes(searchText));
return value.toLowerCase().includes(searchText);
}
if (typeof value === "number") {
return (value as Number).toString().includes(searchText);
}
});
});
}
if (typeof value === "number") {
return (value as Number).toString().includes(searchText);
}
});
});
};