Solved some problems with the excel of master statistical
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user