UNPKG

@wepublish/api

Version:
279 lines 13.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GraphQLMemberRegistrationAndPayment = exports.GraphQLMemberRegistration = exports.GraphQLUserSession = exports.GraphQLPaymentProviderCustomerInput = exports.GraphQLPublicUserInput = exports.GraphQLUserInput = exports.GraphQLUserAddressInput = exports.GraphQLUserConnection = exports.GraphQLUserSort = exports.GraphQLUserFilter = exports.GraphQLPublicUser = exports.GraphQLUser = exports.GraphQLOAuth2Account = exports.GraphQLPaymentProviderCustomer = exports.GraphQLUserAddress = void 0; const graphql_1 = require("graphql"); const user_1 = require("../db/user"); const common_1 = require("./common"); const userRole_1 = require("./userRole"); const graphql_scalars_1 = require("graphql-scalars"); const payment_1 = require("./payment"); const memberPlan_1 = require("./memberPlan"); const subscriptionDeactivation_1 = require("./subscriptionDeactivation"); const subscriptionPeriods_1 = require("./subscriptionPeriods"); const invoice_1 = require("./invoice"); const utility_1 = require("../utility"); const image_1 = require("./image"); const utils_1 = require("./utils"); exports.GraphQLUserAddress = new graphql_1.GraphQLObjectType({ name: 'UserAddress', fields: { company: { type: graphql_1.GraphQLString }, streetAddress: { type: graphql_1.GraphQLString }, streetAddress2: { type: graphql_1.GraphQLString }, zipCode: { type: graphql_1.GraphQLString }, city: { type: graphql_1.GraphQLString }, country: { type: graphql_1.GraphQLString } } }); exports.GraphQLPaymentProviderCustomer = new graphql_1.GraphQLObjectType({ name: 'PaymentProviderCustomer', fields: { paymentProviderID: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, customerID: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) } } }); exports.GraphQLOAuth2Account = new graphql_1.GraphQLObjectType({ name: 'OAuth2Account', fields: { type: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, provider: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, scope: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) } } }); const GraphQLUserSubscription = new graphql_1.GraphQLObjectType({ name: 'UserSubscription', 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) }, paymentPeriodicity: { type: new graphql_1.GraphQLNonNull(memberPlan_1.GraphQLPaymentPeriodicity) }, monthlyAmount: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) }, autoRenew: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean) }, startsAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) }, paidUntil: { type: graphql_scalars_1.GraphQLDateTime }, properties: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(common_1.GraphQLMetadataProperty))) }, deactivation: { type: subscriptionDeactivation_1.GraphQLSubscriptionDeactivation }, periods: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(subscriptionPeriods_1.GraphQLSubscriptionPeriod))) }, memberPlan: { type: new graphql_1.GraphQLNonNull(memberPlan_1.GraphQLMemberPlan), resolve({ memberPlanID }, args, { prisma }) { return prisma.memberPlan.findUnique({ where: { id: memberPlanID } }); } }, invoices: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(invoice_1.GraphQLInvoice))), resolve({ id: subscriptionId }, args, { prisma }) { return prisma.invoice.findMany({ where: { subscriptionID: subscriptionId }, include: { items: true } }); } } } }); exports.GraphQLUser = new graphql_1.GraphQLObjectType({ name: 'User', fields: { id: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, 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) }, firstName: { type: graphql_1.GraphQLString }, email: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, emailVerifiedAt: { type: graphql_scalars_1.GraphQLDateTime }, preferredName: { type: graphql_1.GraphQLString }, address: { type: exports.GraphQLUserAddress }, flair: { type: graphql_1.GraphQLString }, userImage: { type: image_1.GraphQLImage, resolve: (0, utility_1.createProxyingResolver)(({ userImageID }, _, { prisma: { image } }) => userImageID ? image.findUnique({ where: { id: userImageID } }) : null) }, active: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean) }, lastLogin: { type: graphql_scalars_1.GraphQLDateTime }, properties: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(common_1.GraphQLMetadataProperty))) }, roles: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(userRole_1.GraphQLUserRole))), resolve({ roleIDs }, args, { loaders }) { return Promise.all(roleIDs.map(roleID => loaders.userRolesByID.load(roleID))); } }, paymentProviderCustomers: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLPaymentProviderCustomer))) }, oauth2Accounts: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLOAuth2Account))) }, subscriptions: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(GraphQLUserSubscription))), resolve: (0, utility_1.createProxyingResolver)(({ id: userId }, _, { prisma }) => { return prisma.subscription.findMany({ where: { userID: userId }, include: { deactivation: true, periods: true, properties: true } }); }) } } }); exports.GraphQLPublicUser = new graphql_1.GraphQLObjectType({ name: 'User', fields: { id: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, name: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, firstName: { type: graphql_1.GraphQLString }, email: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString), resolve: (0, utility_1.createProxyingResolver)(({ email, id }, _, { session }) => email && (0, utils_1.isMeBySession)(id, session) ? email : '') }, preferredName: { type: graphql_1.GraphQLString }, address: { type: exports.GraphQLUserAddress, resolve: (0, utility_1.createProxyingResolver)(({ address, id }, _, { session }) => address && (0, utils_1.isMeBySession)(id, session) ? address : '') }, flair: { type: graphql_1.GraphQLString }, paymentProviderCustomers: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLPaymentProviderCustomer))), resolve: (0, utility_1.createProxyingResolver)(({ id, paymentProviderCustomers }, _, { session }) => id && (0, utils_1.isMeBySession)(id, session) ? paymentProviderCustomers : []) }, oauth2Accounts: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLOAuth2Account))), resolve: (0, utility_1.createProxyingResolver)(({ id, oauth2Accounts }, _, { session }) => id && (0, utils_1.isMeBySession)(id, session) ? oauth2Accounts : []) }, image: { type: image_1.GraphQLImage, resolve: (0, utility_1.createProxyingResolver)(({ userImageID }, _, { prisma: { image } }) => userImageID ? image.findUnique({ where: { id: userImageID } }) : null) }, properties: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(common_1.GraphQLMetadataPropertyPublic))), resolve: ({ properties }) => properties.filter(property => property.public).map(({ key, value }) => ({ key, value })) } } }); exports.GraphQLUserFilter = new graphql_1.GraphQLInputObjectType({ name: 'UserFilter', fields: { name: { type: graphql_1.GraphQLString }, text: { type: graphql_1.GraphQLString }, userRole: { type: new graphql_1.GraphQLList(graphql_1.GraphQLString) } } }); exports.GraphQLUserSort = new graphql_1.GraphQLEnumType({ name: 'UserSort', values: { CREATED_AT: { value: user_1.UserSort.CreatedAt }, MODIFIED_AT: { value: user_1.UserSort.ModifiedAt }, NAME: { value: user_1.UserSort.Name }, FIRST_NAME: { value: user_1.UserSort.FirstName } } }); exports.GraphQLUserConnection = new graphql_1.GraphQLObjectType({ name: 'UserConnection', fields: { nodes: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(exports.GraphQLUser))) }, pageInfo: { type: new graphql_1.GraphQLNonNull(common_1.GraphQLPageInfo) }, totalCount: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt) } } }); exports.GraphQLUserAddressInput = new graphql_1.GraphQLInputObjectType({ name: 'UserAddressInput', fields: { company: { type: graphql_1.GraphQLString }, streetAddress: { type: graphql_1.GraphQLString }, streetAddress2: { type: graphql_1.GraphQLString }, zipCode: { type: graphql_1.GraphQLString }, city: { type: graphql_1.GraphQLString }, country: { type: graphql_1.GraphQLString } } }); exports.GraphQLUserInput = new graphql_1.GraphQLInputObjectType({ name: 'UserInput', fields: { name: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, firstName: { type: graphql_1.GraphQLString }, email: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, emailVerifiedAt: { type: graphql_scalars_1.GraphQLDateTime }, preferredName: { type: graphql_1.GraphQLString }, address: { type: exports.GraphQLUserAddressInput }, flair: { type: graphql_1.GraphQLString }, userImageID: { type: graphql_1.GraphQLID }, active: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean) }, properties: { type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(common_1.GraphQLMetadataPropertyInput))) }, roleIDs: { type: new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(graphql_1.GraphQLString)) } } }); exports.GraphQLPublicUserInput = new graphql_1.GraphQLInputObjectType({ name: 'UserInput', fields: { name: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, firstName: { type: graphql_1.GraphQLString }, email: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, preferredName: { type: graphql_1.GraphQLString }, address: { type: exports.GraphQLUserAddressInput }, flair: { type: graphql_1.GraphQLString }, uploadImageInput: { type: image_1.GraphQLUploadImageInput } } }); exports.GraphQLPaymentProviderCustomerInput = new graphql_1.GraphQLInputObjectType({ name: 'PaymentProviderCustomerInput', fields: { paymentProviderID: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, customerID: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) } } }); exports.GraphQLUserSession = new graphql_1.GraphQLObjectType({ name: 'UserSession', fields: { token: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) }, createdAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) }, expiresAt: { type: new graphql_1.GraphQLNonNull(graphql_scalars_1.GraphQLDateTime) } } }); exports.GraphQLMemberRegistration = new graphql_1.GraphQLObjectType({ name: 'Registration', fields: { user: { type: new graphql_1.GraphQLNonNull(exports.GraphQLPublicUser) }, session: { type: new graphql_1.GraphQLNonNull(exports.GraphQLUserSession) } } }); exports.GraphQLMemberRegistrationAndPayment = new graphql_1.GraphQLObjectType({ name: 'RegistrationAndPayment', fields: { payment: { type: new graphql_1.GraphQLNonNull(payment_1.GraphQLPublicPayment) }, user: { type: new graphql_1.GraphQLNonNull(exports.GraphQLPublicUser) }, session: { type: new graphql_1.GraphQLNonNull(exports.GraphQLUserSession) } } }); //# sourceMappingURL=user.js.map