Skip to content

Commit

Permalink
feat(certificate-models): add query function
Browse files Browse the repository at this point in the history
  • Loading branch information
ntdoJanneck committed Oct 29, 2024
1 parent 48ac294 commit b2d3ba3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
11 changes: 11 additions & 0 deletions packages/models/src/ssl/Certificate/Certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import {
CertificateData,
CertificateListItemData,
CertificateListQueryData,
CertificateListQueryModelData,
} from "./types.js";
import { AsyncResourceVariant, provideReact } from "../../react/index.js";
Expand Down Expand Up @@ -37,6 +38,16 @@ export class Certificate extends ReferenceModel {
},
);

public static query = provideReact(
async (
projectId: string,
query: CertificateListQueryData,
): Promise<Readonly<Array<CertificateListItem>>> =>
new CertificateListQuery(Project.ofId(projectId), query)
.execute()
.then((r) => r.items),
);

public getDetailed = provideReact(() => Certificate.get(this.id));
public findDetailed = provideReact(() =>
Certificate.find(this.id),
Expand Down
11 changes: 11 additions & 0 deletions packages/models/src/ssl/CertificateRequest/CertificateRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { classes } from "polytype";
import {
CertificateRequestData,
CertificateRequestListItemData,
CertificateRequestListQueryData,
CertificateRequestListQueryModelData,
} from "./types.js";
import { CertificateListQueryModelData } from "../Certificate/types.js";
Expand Down Expand Up @@ -40,6 +41,16 @@ export class CertificateRequest extends ReferenceModel {
},
);

public static query = provideReact(
async (
projectId: string,
query: CertificateRequestListQueryData,
): Promise<Readonly<Array<CertificateRequestListItem>>> =>
new CertificateRequestListQuery(Project.ofId(projectId), query)
.execute()
.then((r) => r.items),
);

public getDetailed = provideReact(() => CertificateRequest.get(this.id));
public findDetailed = provideReact(() =>
CertificateRequest.find(this.id),
Expand Down
4 changes: 2 additions & 2 deletions packages/models/src/ssl/CertificateRequest/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { Project } from "../../project/index.js";
export type CertificateRequestData =
MittwaldAPIV2.Operations.SslGetCertificateRequest.ResponseData;

export type CertificateRequestListQuery =
export type CertificateRequestListQueryData =
MittwaldAPIV2.Paths.V2CertificateRequests.Get.Parameters.Query;

export type CertificateRequestListQueryModelData = Omit<
CertificateRequestListQuery,
CertificateRequestListQueryData,
"projectId"
> & {
project?: Project;
Expand Down

0 comments on commit b2d3ba3

Please sign in to comment.