-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { classes } from "polytype"; | ||
import { ContractItemData } from "./types.js"; | ||
import { DataModel, ReferenceModel } from "../../base/index.js"; | ||
import { provideReact } from "../../react/index.js"; | ||
import { config } from "../../config/config.js"; | ||
import assertObjectFound from "../../base/assertObjectFound.js"; | ||
|
||
export class ContractItem extends ReferenceModel { | ||
public static ofId(contractId: string, id: string): ContractItem { | ||
return new ContractItem(contractId, id); | ||
} | ||
|
||
public static find = provideReact( | ||
async ( | ||
contractId: string, | ||
contractItemId: string, | ||
): Promise<ContractItemDetailed | undefined> => { | ||
const data = await config.behaviors.contractItem.find( | ||
contractId, | ||
contractItemId, | ||
); | ||
if (data !== undefined) { | ||
return new ContractItemDetailed(contractId, data); | ||
} | ||
}, | ||
); | ||
|
||
public static get = provideReact( | ||
async ( | ||
contractId: string, | ||
contractItemId: string, | ||
): Promise<ContractItemDetailed> => { | ||
const item = await this.find(contractId, contractItemId); | ||
assertObjectFound(item, this, contractItemId); | ||
return item; | ||
}, | ||
); | ||
|
||
public readonly contractId: string; | ||
|
||
public constructor(contractId: string, id: string) { | ||
super(id); | ||
this.contractId = contractId; | ||
} | ||
} | ||
|
||
export class ContractItemDetailed extends classes( | ||
DataModel<ContractItemData>, | ||
ContractItem, | ||
) { | ||
public constructor(contractId: string, data: ContractItemData) { | ||
super([data], [contractId, data.itemId]); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/models/src/contract/ContractItem/behaviors/api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { assertStatus, MittwaldAPIV2Client } from "@mittwald/api-client"; | ||
import { ContractItemBehaviors } from "./types.js"; | ||
|
||
export const apiContractItemBehaviors = ( | ||
client: MittwaldAPIV2Client, | ||
): ContractItemBehaviors => ({ | ||
find: async (contractId, contractItemId) => { | ||
const response = await client.contract.getDetailOfContractItem({ | ||
contractId, | ||
contractItemId, | ||
}); | ||
|
||
if (response.status === 200) { | ||
return response.data; | ||
} | ||
assertStatus(response, 404); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./api.js"; | ||
export * from "./types.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ContractItemData } from "../types.js"; | ||
|
||
export interface ContractItemBehaviors { | ||
find: ( | ||
contractId: string, | ||
contractItemId: string, | ||
) => Promise<ContractItemData | undefined>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./ContractItem.js"; | ||
export * from "./types.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { MittwaldAPIV2 } from "@mittwald/api-client"; | ||
|
||
export type ContractItemData = | ||
MittwaldAPIV2.Operations.ContractGetDetailOfContractItem.ResponseData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./Contract/index.js"; | ||
export * from "./ContractItem/index.js"; |