Skip to content

Commit

Permalink
feat(mailaddress-model): add getDetailed, findDetailed and query func…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
ntdoJanneck committed Oct 10, 2024
1 parent 1a0bc6f commit 1bb302a
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions packages/models/src/mail/MailAddress/MailAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,32 @@ import {
ListQueryModel,
ReferenceModel,
} from "../../base/index.js";
import { Ingress } from "../../domain/index.js";
import {
MailAddressData,
MailAddressListItemData,
MailAddressListQueryData,
MailAddressListQueryModelData,
} from "./types.js";
import { provideReact } from "../../react/index.js";
import { AsyncResourceVariant, provideReact } from "../../react/index.js";
import { config } from "../../config/config.js";
import assertObjectFound from "../../base/assertObjectFound.js";
import { Project } from "../../project/index.js";

export class MailAddress extends ReferenceModel {
public static ofId(id: string): MailAddress {
return new Ingress(id);
return new MailAddress(id);
}

public static query = provideReact(
async (
projectId: string,
query: MailAddressListQueryData = {},
): Promise<Readonly<Array<MailAddressListItem>>> =>
new MailAddressListQuery(Project.ofId(projectId), query)
.execute()
.then((r) => r.items),
);

public static find = provideReact(
async (id: string): Promise<MailAddress | undefined> => {
const data = await config.behaviors.mailAddress.find(id);
Expand All @@ -35,6 +45,14 @@ export class MailAddress extends ReferenceModel {
assertObjectFound(mailAddress, this, id);
return mailAddress;
});

public getDetailed = provideReact(() =>
MailAddress.get(this.id),
) as AsyncResourceVariant<() => Promise<MailAddressDetailed>>;

public findDetailed = provideReact(() =>
MailAddress.find(this.id),
) as AsyncResourceVariant<() => Promise<MailAddressDetailed | undefined>>;
}

export class MailAddressCommon extends classes(
Expand Down

0 comments on commit 1bb302a

Please sign in to comment.