@wepublish/api
Version:
API core for we.publish.
125 lines • 6.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GraphQLInvoiceInput = exports.GraphQLInvoiceItemInput = exports.GraphQLInvoiceConnection = exports.GraphQLInvoiceSort = exports.GraphQLinvoiceFilter = exports.GraphQLPublicInvoice = exports.GraphQLInvoice = exports.GraphQLInvoiceItem = void 0;
const graphql_1 = require("graphql");
const graphql_scalars_1 = require("graphql-scalars");
const invoice_1 = require("../db/invoice");
const utility_1 = require("../utility");
const common_1 = require("./common");
const subscription_public_1 = require("./subscription-public");
exports.GraphQLInvoiceItem = new graphql_1.GraphQLObjectType({
name: 'InvoiceItem',
fields: {
createdAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) },
modifiedAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) },
name: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) },
description: { type: graphql_1.GraphQLString },
quantity: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) },
amount: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) },
total: {
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt),
resolve: (0, utility_1.createProxyingResolver)(({ amount, quantity }) => {
return amount * quantity;
})
}
}
});
exports.GraphQLInvoice = new graphql_1.GraphQLObjectType({
name: 'Invoice',
fields: {
id: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID) },
createdAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) },
modifiedAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) },
mail: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) },
description: { type: graphql_1.GraphQLString },
paidAt: { type: graphql_scalars_1.GraphQLDateTime },
manuallySetAsPaidByUserId: { type: graphql_1.GraphQLID },
items: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLInvoiceItem))) },
canceledAt: { type: graphql_scalars_1.GraphQLDateTime },
total: {
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt),
resolve: (0, utility_1.createProxyingResolver)(({ items }) => {
return (items || []).reduce((previousValue, currentValue) => {
return previousValue + currentValue.quantity * currentValue.amount;
}, 0);
})
}
}
});
exports.GraphQLPublicInvoice = new graphql_1.GraphQLObjectType({
name: 'Invoice',
fields: {
id: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID) },
createdAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) },
modifiedAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) },
mail: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) },
description: { type: graphql_1.GraphQLString },
paidAt: { type: graphql_scalars_1.GraphQLDateTime },
dueAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) },
canceledAt: { type: graphql_scalars_1.GraphQLDateTime },
items: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLInvoiceItem))) },
subscriptionID: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID) },
subscription: {
type: subscription_public_1.GraphQLPublicSubscription,
resolve({ subscriptionID }, args, { loaders }) {
return loaders.subscriptionsById.load(subscriptionID);
}
},
total: {
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt),
resolve: (0, utility_1.createProxyingResolver)(({ items }) => {
return (items || []).reduce((previousValue, currentValue) => {
return previousValue + currentValue.quantity * currentValue.amount;
}, 0);
})
}
}
});
exports.GraphQLinvoiceFilter = new graphql_1.GraphQLInputObjectType({
name: 'InvoiceFilter',
fields: {
mail: { type: graphql_1.GraphQLString },
paidAt: { type: graphql_scalars_1.GraphQLDate },
canceledAt: { type: graphql_scalars_1.GraphQLDate },
userID: { type: graphql_1.GraphQLID },
subscriptionID: { type: graphql_1.GraphQLID }
}
});
exports.GraphQLInvoiceSort = new graphql_1.GraphQLEnumType({
name: 'InvoiceSort',
values: {
CREATED_AT: { value: invoice_1.InvoiceSort.CreatedAt },
MODIFIED_AT: { value: invoice_1.InvoiceSort.ModifiedAt },
PAID_AT: { value: invoice_1.InvoiceSort.PaidAt }
}
});
exports.GraphQLInvoiceConnection = new graphql_1.GraphQLObjectType({
name: 'InvoiceConnection',
fields: {
nodes: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLInvoice))) },
pageInfo: { type: new graphql_1.GraphQLNonNull(common_1.GraphQLPageInfo) },
totalCount: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) }
}
});
exports.GraphQLInvoiceItemInput = new graphql_1.GraphQLInputObjectType({
name: 'InvoiceItemInput',
fields: {
name: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) },
description: { type: graphql_1.GraphQLString },
quantity: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) },
amount: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) },
createdAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) },
modifiedAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) }
}
});
exports.GraphQLInvoiceInput = new graphql_1.GraphQLInputObjectType({
name: 'InvoiceInput',
fields: {
mail: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) },
description: { type: graphql_1.GraphQLString },
subscriptionID: { type: graphql_1.GraphQLID },
manuallySetAsPaidByUserId: { type: graphql_1.GraphQLID },
items: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLInvoiceItemInput))) }
}
});
//# sourceMappingURL=invoice.js.map