import { CityName, getDb, ObjectId } from "../index"; import { Collection, Filter } from "mongodb"; import { MIS_SystemInstruction, MIS_Tool } from "./instructions.types"; export const getSystemInstructionsCollection = (): Collection => { return getDb().collection("system_instructions"); }; /** * Find system instructions by filter * @param filter filter to apply * @returns array of system instructions */ export const findSystemInstructions = async ( filter: Filter = {}, ): Promise => { return await getSystemInstructionsCollection().find(filter).toArray(); }; /** * Get system instruction by id * @param id system instruction id * @returns system instruction or null if not found */ export const getSystemInstructionById = async ( id: string, ): Promise => { return await getSystemInstructionsCollection().findOne({ _id: new ObjectId(id), }); }; /** * Get all active system instructions for a city * @param cityName city name * @returns array of active system instructions */ export const getActiveSystemInstructionsByCity = async ( cityName: CityName, ): Promise => { return await getSystemInstructionsCollection() .find({ cityName, isActive: true }) .toArray(); }; /** * Get system instructions by tool and city * @param cityName city name * @param toolName tool name * @returns array of system instructions */ export const getSystemInstructionsByToolAndCity = async ( cityName: CityName, toolName: MIS_Tool, ): Promise => { return await getSystemInstructionsCollection() .find({ cityName: cityName, tool: toolName }) .toArray(); };