import EntityService from "@social-mail/social-mail-client/dist/services/EntityService.js"; import DISingleton from "@web-atoms/core/dist/di/DISingleton.js"; import { Inject } from "@web-atoms/core/dist/di/Inject.js"; import { DnsZone, IDnsZone, IDnsZoneRecord } from "../../../model/model.js"; @DISingleton() export default class DnsZoneService { @Inject private entityService: EntityService; list({ start = 0, size = 100, cancelToken = null, version = 1 }) { return this.entityService.query(DnsZone) .include((x) => x.ksk) .toPage({ start, size, cancelToken }); } async save(zone: IDnsZone) { const cloner = this.entityService .cloner(zone) .include((x) => x.records) .copy; await this.entityService.save(cloner); } async saveRecord(... records: IDnsZoneRecord[]) { const copy = records.map((x) => this.entityService.cloner(x).copy); await this.entityService.save(copy); } get(zoneID: number) { return this.entityService .query(DnsZone) .where({ zoneID }, (p) => (x) => x.zoneID === p.zoneID) .include((x) => [x.ksk, x.zsk, x.records]) .firstOrDefault(); } }