Skip to content
Draft
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.schema
.createTable('outgoingPaymentGrantSpentAmounts', function (table) {
table.uuid('id').notNullable().primary()
table.string('grantId').notNullable()
table.foreign('grantId').references('outgoingPaymentGrants.id')
table.uuid('outgoingPaymentId').notNullable()
table.foreign('outgoingPaymentId').references('outgoingPayments.id')
table.integer('receiveAmountScale').notNullable()
table.string('receiveAmountCode').notNullable()
table.bigInteger('paymentReceiveAmountValue').notNullable()
table.bigInteger('intervalReceiveAmountValue').nullable()
table.bigInteger('grantTotalReceiveAmountValue').notNullable()
table.integer('debitAmountScale').notNullable()
table.string('debitAmountCode').notNullable()
table.bigInteger('paymentDebitAmountValue').notNullable()
table.bigInteger('intervalDebitAmountValue').nullable()
table.bigInteger('grantTotalDebitAmountValue').notNullable()
table.string('paymentState').notNullable()
table.timestamp('intervalStart').nullable()
table.timestamp('intervalEnd').nullable()
table.timestamp('createdAt').defaultTo(knex.fn.now())
})
.then(() => {
return knex.raw(
'CREATE INDEX outgoingPaymentGrantSpentAmounts_grantId_createdAt_desc_idx ON "outgoingPaymentGrantSpentAmounts" ("grantId", "createdAt" DESC)'
)
})
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.schema.dropTableIfExists('outgoingPaymentGrantSpentAmounts')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.schema.alterTable('outgoingPaymentGrants', function (table) {
table.string('interval').nullable()
})
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.schema.alterTable('outgoingPaymentGrants', function (table) {
table.dropColumn('interval')
})
}
4 changes: 4 additions & 0 deletions packages/backend/src/open_payments/payment/outgoing/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export enum OutgoingPaymentError {
InvalidAmount = 'InvalidAmount',
NegativeReceiveAmount = 'NegativeReceiveAmount',
InvalidReceiver = 'InvalidReceiver',
InvalidInterval = 'InvalidInterval',
OnlyOneGrantAmountAllowed = 'OnlyOneGrantAmountAllowed'
}

Expand Down Expand Up @@ -52,6 +53,7 @@ export const errorToHTTPCode: {
[OutgoingPaymentError.InvalidAmount]: 400,
[OutgoingPaymentError.NegativeReceiveAmount]: 400,
[OutgoingPaymentError.InvalidReceiver]: 400,
[OutgoingPaymentError.InvalidInterval]: 500,
[OutgoingPaymentError.OnlyOneGrantAmountAllowed]: 500
}

Expand All @@ -68,6 +70,7 @@ export const errorToCode: {
[OutgoingPaymentError.InvalidAmount]: GraphQLErrorCode.BadUserInput,
[OutgoingPaymentError.NegativeReceiveAmount]: GraphQLErrorCode.BadUserInput,
[OutgoingPaymentError.InvalidReceiver]: GraphQLErrorCode.BadUserInput,
[OutgoingPaymentError.InvalidInterval]: GraphQLErrorCode.InternalServerError,
[OutgoingPaymentError.OnlyOneGrantAmountAllowed]:
GraphQLErrorCode.BadUserInput
}
Expand All @@ -85,6 +88,7 @@ export const errorToMessage: {
[OutgoingPaymentError.InvalidAmount]: 'invalid amount',
[OutgoingPaymentError.NegativeReceiveAmount]: 'negative receive amount',
[OutgoingPaymentError.InvalidReceiver]: 'invalid receiver',
[OutgoingPaymentError.InvalidInterval]: 'invalid interval',
[OutgoingPaymentError.OnlyOneGrantAmountAllowed]:
'only one of receiveAmount or debitAmount allowed'
}
Expand Down
Loading
Loading