import { Collection, ObjectId } from "mongodb"; import { getDb } from "../index"; import { MuniIssue } from "./muniIssues.types"; import { MUNI_ISSUES_COLLECTION } from "./muniIssues.constants"; export const getMuniIssuesCollection = (): Collection => { return getDb().collection(MUNI_ISSUES_COLLECTION); }; export const generateMuniIssueId = (): ObjectId => new ObjectId(); export const getMuniIssueById = async ( id: string, ): Promise => { // A malformed id is treated as not-found rather than throwing on `new ObjectId`. if (!ObjectId.isValid(id)) return null; return getMuniIssuesCollection().findOne({ _id: new ObjectId(id) }); }; export const getMuniIssueByJiraKey = async ( jiraKey: string, ): Promise => { return getMuniIssuesCollection().findOne({ "jira.key": jiraKey }); };