Skip to content

Commit

Permalink
feat(resources): add CustomerPasswordResets, OrderCopies, OrderSubscr…
Browse files Browse the repository at this point in the history
…iptions
  • Loading branch information
reegodev committed Aug 12, 2021
1 parent 9768af5 commit a3e579a
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ export {
PaymentGateways,
PaymentGatewayInstance,
} from './resources/PaymentGateways'
export {
CustomerPasswordResets,
CustomerPasswordResetInstance,
} from './resources/CustomerPasswordResets'
export { OrderCopies, OrderCopyInstance } from './resources/OrderCopies'
export {
OrderSubscriptions,
OrderSubscriptionInstance,
} from './resources/OrderSubscriptions'
52 changes: 52 additions & 0 deletions src/resources/CustomerPasswordResets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
ResourceConfig,
ConcreteResourceInstance,
createResource,
Resource,
} from '../resource'
import { CustomerInstance } from './Customers'

export interface CustomerPasswordResetAttributes {
customer_email: string
reset_password_token: string
customer_password: string
_reset_password_token: string
reset_password_at: string
}

export interface CustomerPasswordResetRelationships {
customer: CustomerInstance
}

export type CustomerPasswordResetInstance = ConcreteResourceInstance<
CustomerPasswordResetAttributes,
CustomerPasswordResetRelationships
>

export const CustomerPasswordResetsConfig: ResourceConfig<
CustomerPasswordResetAttributes,
CustomerPasswordResetRelationships
> = {
type: 'customer_password_resets',

attributes: [
'customer_email',
'reset_password_token',
'customer_password',
'_reset_password_token',
'reset_password_at',
],

relationships: {
customer: 'customers',
},
}

export const CustomerPasswordResets: Resource<
CustomerPasswordResetAttributes,
CustomerPasswordResetRelationships,
CustomerPasswordResetInstance
> = createResource<
CustomerPasswordResetAttributes,
CustomerPasswordResetRelationships
>(CustomerPasswordResetsConfig)
62 changes: 62 additions & 0 deletions src/resources/OrderCopies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {
ResourceConfig,
ConcreteResourceInstance,
createResource,
Resource,
} from '../resource'
import { OrderInstance } from './Orders'
import { OrderSubscriptionInstance } from './OrderSubscriptions'

export interface OrderCopyAttributes {
status: string
started_at: string
completed_at: string
failed_at: string
place_target_order: boolean
cancel_source_order: boolean
errors_log: any[] // TODO: improve this type
errors_count: number
}

export interface OrderCopyRelationships {
source_order: OrderInstance
target_order: OrderInstance
order_subscription: OrderSubscriptionInstance
}

export type OrderCopyInstance = ConcreteResourceInstance<
OrderCopyAttributes,
OrderCopyRelationships
>

export const OrderCopiesConfig: ResourceConfig<
OrderCopyAttributes,
OrderCopyRelationships
> = {
type: 'order_copies',

attributes: [
'status',
'started_at',
'completed_at',
'failed_at',
'place_target_order',
'cancel_source_order',
'errors_log',
'errors_count',
],

relationships: {
source_order: 'orders',
target_order: 'orders',
order_subscription: 'order_subscriptions',
},
}

export const OrderCopies: Resource<
OrderCopyAttributes,
OrderCopyRelationships,
OrderCopyInstance
> = createResource<OrderCopyAttributes, OrderCopyRelationships>(
OrderCopiesConfig,
)
79 changes: 79 additions & 0 deletions src/resources/OrderSubscriptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {
ResourceConfig,
ConcreteResourceInstance,
createResource,
Resource,
} from '../resource'
import { MarketInstance } from './Markets'
import { OrderInstance } from './Orders'
import { OrderCopyInstance } from './OrderCopies'

export interface OrderSubscriptionAttributes {
number: string
status: string
frequency: string
activate_by_source_order: boolean
customer_email: string
starts_at: string
expires_at: string
next_run_at: string
occurrencies: number
errors_count: number
succeeded_on_last_run: boolean
options: any // TODO: improve this type
_activate: boolean
_deactivate: boolean
_cancel: boolean
}

export interface OrderSubscriptionRelationships {
market: MarketInstance
source_order: OrderInstance
order_copies: OrderCopyInstance[]
orders: OrderInstance[]
}

export type OrderSubscriptionInstance = ConcreteResourceInstance<
OrderSubscriptionAttributes,
OrderSubscriptionRelationships
>

export const OrderSubscriptionsConfig: ResourceConfig<
OrderSubscriptionAttributes,
OrderSubscriptionRelationships
> = {
type: 'order_subscriptions',

attributes: [
'number',
'status',
'frequency',
'activate_by_source_order',
'customer_email',
'starts_at',
'expires_at',
'next_run_at',
'occurrencies',
'errors_count',
'succeeded_on_last_run',
'options',
'_activate',
'_deactivate',
'_cancel',
],

relationships: {
market: 'markets',
source_order: 'orders',
order_copies: 'order_copies',
orders: 'orders',
},
}

export const OrderSubscriptions: Resource<
OrderSubscriptionAttributes,
OrderSubscriptionRelationships,
OrderSubscriptionInstance
> = createResource<OrderSubscriptionAttributes, OrderSubscriptionRelationships>(
OrderSubscriptionsConfig,
)

0 comments on commit a3e579a

Please sign in to comment.