Correct the TS interface for subtransactions
This commit is contained in:
		
							parent
							
								
									51d97d6a78
								
							
						
					
					
						commit
						1d0b0f5af9
					
				
					 8 changed files with 69 additions and 38 deletions
				
			
		|  | @ -1,11 +1,14 @@ | ||||||
| // License: LGPL-3.0-or-later
 | // License: LGPL-3.0-or-later
 | ||||||
| import type { HoudiniEvent } from "../../../common"; | import type { HoudiniEvent } from "../../../common"; | ||||||
| import type { CommonOfflineTransactionPayment } from '.'; | import type { CommonOfflineTransactionPayment } from '.'; | ||||||
|  | import type { PaymentAsId } from ".."; | ||||||
| 
 | 
 | ||||||
| export interface Charge extends CommonOfflineTransactionPayment { | export interface ChargeAsId extends PaymentAsId { | ||||||
| 	object: 'offline_transaction_charge'; | 	object: 'offline_transaction_charge'; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export type Charge = CommonOfflineTransactionPayment & ChargeAsId; | ||||||
|  | 
 | ||||||
| export type ChargeCreated = HoudiniEvent<'offline_transaction_charge.created', Charge>; | export type ChargeCreated = HoudiniEvent<'offline_transaction_charge.created', Charge>; | ||||||
| export type ChargeUpdated = HoudiniEvent<'offline_transaction_charge.updated', Charge>; | export type ChargeUpdated = HoudiniEvent<'offline_transaction_charge.updated', Charge>; | ||||||
| export type ChargeDeleted = HoudiniEvent<'offline_transaction_charge.deleted', Charge>; | export type ChargeDeleted = HoudiniEvent<'offline_transaction_charge.deleted', Charge>; | ||||||
|  |  | ||||||
|  | @ -1,10 +1,13 @@ | ||||||
| // License: LGPL-3.0-or-later
 | // License: LGPL-3.0-or-later
 | ||||||
| import type { HoudiniEvent } from "../../../common"; | import type { HoudiniEvent } from "../../../common"; | ||||||
| import type { CommonOfflineTransactionPayment } from '.'; | import type { CommonOfflineTransactionPayment } from '.'; | ||||||
|  | import type { PaymentAsId } from ".."; | ||||||
| 
 | 
 | ||||||
| export interface Dispute extends CommonOfflineTransactionPayment { | 
 | ||||||
|  | export interface DisputeAsId extends PaymentAsId { | ||||||
| 	object: 'offline_transaction_dispute'; | 	object: 'offline_transaction_dispute'; | ||||||
| } | } | ||||||
|  | export type Dispute = CommonOfflineTransactionPayment & DisputeAsId; | ||||||
| 
 | 
 | ||||||
| export type DisputeCreated = HoudiniEvent<'offline_transaction_dispute.created', Dispute>; | export type DisputeCreated = HoudiniEvent<'offline_transaction_dispute.created', Dispute>; | ||||||
| export type DisputeUpdated = HoudiniEvent<'offline_transaction_dispute.updated', Dispute>; | export type DisputeUpdated = HoudiniEvent<'offline_transaction_dispute.updated', Dispute>; | ||||||
|  |  | ||||||
|  | @ -1,11 +1,14 @@ | ||||||
| // License: LGPL-3.0-or-later
 | // License: LGPL-3.0-or-later
 | ||||||
| import type { HoudiniEvent } from "../../../common"; | import type { HoudiniEvent } from "../../../common"; | ||||||
| import type { CommonOfflineTransactionPayment } from '.'; | import type { CommonOfflineTransactionPayment } from '.'; | ||||||
|  | import type { PaymentAsId } from ".."; | ||||||
| 
 | 
 | ||||||
| export interface Refund extends CommonOfflineTransactionPayment { | export interface RefundAsId extends PaymentAsId { | ||||||
| 	object: 'offline_transaction_refund'; | 	object: 'offline_transaction_refund'; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export type Refund = CommonOfflineTransactionPayment & RefundAsId; | ||||||
|  | 
 | ||||||
| export type RefundCreated = HoudiniEvent<'offline_transaction_refund.created', Refund>; | export type RefundCreated = HoudiniEvent<'offline_transaction_refund.created', Refund>; | ||||||
| export type RefundUpdated = HoudiniEvent<'offline_transaction_refund.updated', Refund>; | export type RefundUpdated = HoudiniEvent<'offline_transaction_refund.updated', Refund>; | ||||||
| export type RefundDeleted = HoudiniEvent<'offline_transaction_refund.deleted', Refund>; | export type RefundDeleted = HoudiniEvent<'offline_transaction_refund.deleted', Refund>; | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| // License: LGPL-3.0-or-later
 | // License: LGPL-3.0-or-later
 | ||||||
| import type { HouID, HoudiniEvent } from "../../../common"; | import type { HouID, HoudiniEvent } from "../../../common"; | ||||||
| import type { Payment, Subtransaction} from ".."; | import type { Payment, Subtransaction} from ".."; | ||||||
| import type { Charge, Refund, Dispute } from '.'; | import type { Charge, Refund, Dispute, ChargeAsId, DisputeAsId, RefundAsId } from '.'; | ||||||
| 
 | 
 | ||||||
| export interface CommonOfflineTransactionPayment extends Payment { | export interface CommonOfflineTransactionPayment extends Payment { | ||||||
| 	// The kind of offline charge. Could be cash, check or something else
 | 	// The kind of offline charge. Could be cash, check or something else
 | ||||||
|  | @ -14,11 +14,9 @@ export interface CommonOfflineTransactionPayment extends Payment { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default interface OfflineTransaction extends Subtransaction { | export default interface OfflineTransaction extends Subtransaction { | ||||||
| 	charges: HouID[] | Charge[]; |  | ||||||
| 	deleted: boolean; | 	deleted: boolean; | ||||||
| 	disputes: HouID[] | Dispute[]; |  | ||||||
| 	object: 'offline_transaction'; | 	object: 'offline_transaction'; | ||||||
| 	refunds: HouID[] | Refund[]; | 	payments: (ChargeAsId|RefundAsId|DisputeAsId)[]| (Charge|Refund|Dispute)[]; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export type OfflineTransactionCreated = HoudiniEvent<'offline_transaction.created', OfflineTransaction>; | export type OfflineTransactionCreated = HoudiniEvent<'offline_transaction.created', OfflineTransaction>; | ||||||
|  |  | ||||||
|  | @ -1,11 +1,15 @@ | ||||||
| // License: LGPL-3.0-or-later
 | // License: LGPL-3.0-or-later
 | ||||||
| import type { Amount, HoudiniObject, HouID, HoudiniEvent } from "../../common"; | import type { Amount, HouID, HoudiniEvent, PolymorphicID } from "../../common"; | ||||||
| import type { Subtransaction, TrxDescendent } from "."; | import type { Subtransaction, TrxDescendent } from "."; | ||||||
| 
 | 
 | ||||||
| export interface Payment extends HoudiniObject<HouID>, TrxDescendent { | export interface PaymentAsId extends PolymorphicID<HouID> { | ||||||
|  | 	type: 'payment'; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export interface Payment extends PaymentAsId, TrxDescendent { | ||||||
| 	created: number; | 	created: number; | ||||||
| 	deleted: boolean; | 	deleted: boolean; | ||||||
| 	fees: Amount; | 	fee_total: Amount; | ||||||
| 	gross_amount: Amount; | 	gross_amount: Amount; | ||||||
| 	net_amount: Amount; | 	net_amount: Amount; | ||||||
| 	status: string; | 	status: string; | ||||||
|  |  | ||||||
|  | @ -0,0 +1,19 @@ | ||||||
|  | // License: LGPL-3.0-or-later
 | ||||||
|  | import type { Amount, HouID, HoudiniEvent, PolymorphicID } from "../../common"; | ||||||
|  | import type {  Payment, PaymentAsId, TrxDescendent } from "."; | ||||||
|  | 
 | ||||||
|  | export interface SubtransactionAsId extends PolymorphicID<HouID> { | ||||||
|  | 	type: 'subtransaction'; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export interface Subtransaction extends SubtransactionAsId, TrxDescendent { | ||||||
|  | 	created: number; | ||||||
|  | 	initial_amount: Amount; | ||||||
|  | 	net_amount: Amount; | ||||||
|  | 	payments: PaymentAsId[]|Payment[]; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export type SubtransactionCreated = HoudiniEvent<'subtransaction.created', Subtransaction>; | ||||||
|  | export type SubtransactionUpdated = HoudiniEvent<'subtransaction.updated', Subtransaction>; | ||||||
|  | export type SubtransactionDeleted = HoudiniEvent<'subtransaction.deleted', Subtransaction>; | ||||||
|  | 
 | ||||||
|  | @ -1,19 +1,9 @@ | ||||||
| // License: LGPL-3.0-or-later
 | // License: LGPL-3.0-or-later
 | ||||||
| import type { Amount, HoudiniObject, IDType, HouID, HoudiniEvent } from "../../common"; | import type { Amount, HoudiniObject, IDType, HouID, HoudiniEvent, PolymorphicID } from "../../common"; | ||||||
| import type Nonprofit from '../'; | import type Nonprofit from '../'; | ||||||
| import type Supporter from "../Supporter"; | import type Supporter from "../Supporter"; | ||||||
| import type { Payment } from "./Payment"; | import type { Payment, PaymentAsId } from "./Payment"; | ||||||
| 
 | import type { SubtransactionAsId, Subtransaction } from "./Subtransaction"; | ||||||
| export interface Subtransaction extends HoudiniObject<HouID>, TrxDescendent { |  | ||||||
| 	amount: Amount; |  | ||||||
| 	amount_disputed: Amount; |  | ||||||
| 	amount_pending: Amount; |  | ||||||
| 	amount_refunded: Amount; |  | ||||||
| 	created: number; |  | ||||||
| 	fee_total: Amount; |  | ||||||
| 	net_amount: Amount; |  | ||||||
| 	type: 'subtransaction'; |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Every descendent of a Transaction object will have the following three fields |  * Every descendent of a Transaction object will have the following three fields | ||||||
|  | @ -37,30 +27,21 @@ export interface TrxDescendent { | ||||||
|  * Every transaction assignment, including Donation, TicketPurchase, CampaignGiftPurchase |  * Every transaction assignment, including Donation, TicketPurchase, CampaignGiftPurchase | ||||||
|  * must have an amount and the type 'trx_assignment' set. |  * must have an amount and the type 'trx_assignment' set. | ||||||
|  */ |  */ | ||||||
| export interface TrxAssignment extends HoudiniObject<HouID>, TrxDescendent { | export interface TrxAssignment extends TrxAssignmentAsId, TrxDescendent { | ||||||
| 	amount: Amount; | 	amount: Amount; | ||||||
| 	type: 'trx_assignment'; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface TrxAssignmentAsId extends HoudiniObject<HouID> { | export interface TrxAssignmentAsId extends PolymorphicID<HouID> { | ||||||
| 	type: 'trx_assignment'; | 	type: 'trx_assignment'; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface SubtransactionAsId extends HoudiniObject<HouID> { |  | ||||||
| 	type: 'subtransaction'; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export default interface Transaction extends HoudiniObject<HouID> { | export default interface Transaction extends HoudiniObject<HouID> { | ||||||
|   amount: Amount; |   amount: Amount; | ||||||
| 	// amount_disputed: Amount;
 |  | ||||||
| 	// amount_refunded: Amount;
 |  | ||||||
| 	created: number; | 	created: number; | ||||||
| 	deleted: boolean; |  | ||||||
| 	// net_amount: Amount;
 |  | ||||||
| 	nonprofit: IDType | Nonprofit; | 	nonprofit: IDType | Nonprofit; | ||||||
| 	object: 'transaction'; | 	object: 'transaction'; | ||||||
|  | 	payments: PaymentAsId[] | Payment[]; | ||||||
| 	subtransaction: SubtransactionAsId | Subtransaction; | 	subtransaction: SubtransactionAsId | Subtransaction; | ||||||
| 	subtransaction_payments: IDType[] | Payment[]; |  | ||||||
| 	supporter: IDType | Supporter; | 	supporter: IDType | Supporter; | ||||||
| 	transaction_assignments: TrxAssignmentAsId[] | TrxAssignment[]; | 	transaction_assignments: TrxAssignmentAsId[] | TrxAssignment[]; | ||||||
| } | } | ||||||
|  | @ -73,5 +54,6 @@ export type TransactionDeleted = HoudiniEvent<'transaction.deleted', Transaction | ||||||
| 
 | 
 | ||||||
| export * from './Payment'; | export * from './Payment'; | ||||||
| export * from './Donation'; | export * from './Donation'; | ||||||
| export * from './OfflineTransaction'; | export * from './Subtransaction'; | ||||||
|  | export * as OfflineTransactionTypes from './OfflineTransaction'; | ||||||
| export {default as OfflineTransaction} from './OfflineTransaction'; | export {default as OfflineTransaction} from './OfflineTransaction'; | ||||||
|  |  | ||||||
|  | @ -72,7 +72,26 @@ export interface HoudiniObject<ID extends IDType|HouID=IDType> { | ||||||
| 	object: string; | 	object: string; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export type PolymorphicID<ID extends IDType|HouID=IDType> = HoudiniObject<ID>; | /** | ||||||
|  |  * Used to identify objects when the field they're assigned too isn't enough to know what type of object they are. | ||||||
|  |  * As an example on a transaction object, you'll have a field called "subtransaction". That could be any subtransaction object, for example, an | ||||||
|  |  * `offline_transaction` or a `stripe_transaction`. We don't have enough information using the field name to tell us EXACTLY what type of field this is. | ||||||
|  |  * There for we provide the following JSON object: | ||||||
|  |  * | ||||||
|  |  * { | ||||||
|  |  * 	id: <the id of the object>, | ||||||
|  |  *  object: <the object type>, | ||||||
|  |  *  type: 'subtransaction', | ||||||
|  |  * } | ||||||
|  |  * | ||||||
|  |  * | ||||||
|  |  * | ||||||
|  |  * | ||||||
|  | */ | ||||||
|  | export interface PolymorphicID<ID extends IDType | HouID = IDType> extends HoudiniObject<ID> { | ||||||
|  | 	/** the subtype of the object */ | ||||||
|  | 	type: string; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| type HoudiniObjectOfAllIDs = HoudiniObject<IDType> | HoudiniObject<HouID>; | type HoudiniObjectOfAllIDs = HoudiniObject<IDType> | HoudiniObject<HouID>; | ||||||
| /** | /** | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Eric Schultz
						Eric Schultz