import { RegisterSingleton, ServiceProvider } from "@entity-access/entity-access/dist/di/di.js"; import {ICacheContainer, ObjectCache, cacheFor } from "../../../common/cacheFor.js"; import SocialMailContext from "../../model/SocialMailContext.js"; @RegisterSingleton export default class DomainKeyService implements ICacheContainer { cache: ObjectCache; @cacheFor() getDomainKey(mailboxID: number) { using scope = ServiceProvider.createScope(this); const db = scope.resolve(SocialMailContext); const key = db.domainKeys .where({ mailboxID}, (x, p) => x.hostedDomain.domain.mailboxes.some((m) => m.mailboxID === p.mailboxID)) .include((x) => x.hostedDomain.domain) .first(); return key; } }