Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(condo): INFRA-538 add new generateServerUtils implementation wit… #5295

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const RegisterMultiPaymentForInvoicesService = new GQLCustomSchema('RegisterMult

const [acquiringIntegrationModel] = await AcquiringIntegration.getAll(context, {
id: Array.from(acquiringIntegrations)[0],
})
}, 'id hostUrl deletedAt')
if (acquiringIntegrationModel.deletedAt) {
throw new GQLError(ERRORS.ACQUIRING_INTEGRATION_IS_DELETED(acquiringIntegrationModel.id), context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const RegisterMultiPaymentForOneReceiptService = new GQLCustomSchema('RegisterMu

const acquiringIntegration = await AcquiringIntegration.getOne(context, {
id: acquiringContext.integration,
})
}, 'id supportedBillingIntegrationsGroup minimumPaymentAmount maximumPaymentAmount hostUrl deletedAt')

if (acquiringIntegration.deletedAt) {
throw new GQLError({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const RegisterMultiPaymentForVirtualReceiptService = new GQLCustomSchema('Regist

const acquiringIntegration = await AcquiringIntegration.getOne(context, {
id: acquiringContext.integration,
})
}, 'id minimumPaymentAmount maximumPaymentAmount hostUrl deletedAt')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess its better to move this to some const on the top of the file, like we do with ERRORS.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to keep it close to use. It's easier to review. Moving it to another file will decrease readability because you need to look at another file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep fields along with getOne/getAll and other server methods at the same line of code.
I believe we have to not move it to top of the same file and not move it to another file - since it more readable to see exactly fields you are selecting from a model. More over - we going to never reuse those constants in future to not mix up different queries together

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to keep it close to use. It's easier to review. Moving it to another file will decrease readability because you need to look at another file.

I meant not another file, but the top of existing one. Like we do with ERRORS. So you can avoid horizontal scroll

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave the inline style, it makes the code easier to review.
You can extract some long query into a constant, but only to improve readability


if (acquiringIntegration.deletedAt) {
throw new GQLError({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ const RegisterMultiPaymentService = new GQLCustomSchema('RegisterMultiPaymentSer
// NOTE: Here using serverSchema to get many relation
const [acquiringIntegration] = await AcquiringIntegration.getAll(context, {
id: Array.from(acquiringIntegrations)[0],
})
}, 'id canGroupReceipts supportedBillingIntegrationsGroup explicitFeeDistributionSchema minimumPaymentAmount maximumPaymentAmount hostUrl deletedAt')
if (acquiringIntegration.deletedAt) {
throw new GQLError({ ...ERRORS.ACQUIRING_INTEGRATION_IS_DELETED, messageInterpolation: { id: acquiringIntegration.id } }, context)
}
Expand Down
6 changes: 2 additions & 4 deletions apps/condo/domains/acquiring/utils/serverSchema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

const { generateServerUtils, execGqlWithoutAccess } = require('@open-condo/codegen/generate.server.utils')

const { AcquiringIntegration: AcquiringIntegrationGQL } = require('@condo/domains/acquiring/gql')
const { AcquiringIntegrationAccessRight: AcquiringIntegrationAccessRightGQL } = require('@condo/domains/acquiring/gql')
const { AcquiringIntegrationContext: AcquiringIntegrationContextGQL } = require('@condo/domains/acquiring/gql')
const { MultiPayment: MultiPaymentGQL } = require('@condo/domains/acquiring/gql')
const { Payment: PaymentGQL } = require('@condo/domains/acquiring/gql')
Expand All @@ -25,8 +23,8 @@ const { REGISTER_MULTI_PAYMENT_FOR_INVOICES_MUTATION } = require('@condo/domains
const { CALCULATE_FEE_FOR_RECEIPT_QUERY } = require('@condo/domains/acquiring/gql')
/* AUTOGENERATE MARKER <IMPORT> */

const AcquiringIntegration = generateServerUtils(AcquiringIntegrationGQL)
const AcquiringIntegrationAccessRight = generateServerUtils(AcquiringIntegrationAccessRightGQL)
const AcquiringIntegration = generateServerUtils('AcquiringIntegration')
const AcquiringIntegrationAccessRight = generateServerUtils('AcquiringIntegrationAccessRight')
const AcquiringIntegrationContext = generateServerUtils(AcquiringIntegrationContextGQL)
const MultiPayment = generateServerUtils(MultiPaymentGQL)
const Payment = generateServerUtils(PaymentGQL)
Expand Down
43 changes: 25 additions & 18 deletions packages/codegen/generate.gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function getModelForms (key) {
return [MODEL, MODELS]
}

function genGetAllGQL (key, fields, prefix = '') {
function generateGetAllGQL (key, fields, prefix = '') {
const [MODEL, MODELS] = getModelForms(key)
const capitalizedPrefix = prefix.length ? prefix.charAt(0).toUpperCase() + prefix.slice(1) : ''
const queryName = prefix ? `${prefix}All${MODELS}` : `all${MODELS}`
Expand All @@ -23,7 +23,7 @@ function genGetAllGQL (key, fields, prefix = '') {
`
}

function genGetCountGQL (key, prefix = '') {
function generateGetCountGQL (key, prefix = '') {
const [MODEL, MODELS] = getModelForms(key)
const metaQueryName = `${prefix}_all${MODELS}Meta`
const capitalizedPrefix = prefix.length ? prefix.charAt(0).toUpperCase() + prefix.slice(1) : ''
Expand All @@ -36,7 +36,7 @@ function genGetCountGQL (key, prefix = '') {
`
}

function genGetAllWithCountGQL (key, fields, prefix = '') {
function generateGetAllWithCountGQL (key, fields, prefix = '') {
const [MODEL, MODELS] = getModelForms(key)
const metaQueryName = `${prefix}_all${MODELS}Meta`
const queryName = prefix ? `${prefix}All${MODELS}` : `all${MODELS}`
Expand All @@ -52,7 +52,7 @@ function genGetAllWithCountGQL (key, fields, prefix = '') {
`
}

function genCreateGQL (key, fields, prefix = '') {
function generateCreateGQL (key, fields, prefix = '') {
const [MODEL] = getModelForms(key)
const capitalizedPrefix = prefix.length ? prefix.charAt(0).toUpperCase() + prefix.slice(1) : ''
const mutationName = prefix ? `${prefix}Create${MODEL}` : `create${MODEL}`
Expand All @@ -65,7 +65,7 @@ function genCreateGQL (key, fields, prefix = '') {
`
}

function genCreateManyGQL (key, fields, prefix = '') {
function generateCreateManyGQL (key, fields, prefix = '') {
const [, MODELS] = getModelForms(key)
const capitalizedPrefix = prefix.length ? prefix.charAt(0).toUpperCase() + prefix.slice(1) : ''
const mutationName = prefix ? `${prefix}Create${MODELS}` : `create${MODELS}`
Expand All @@ -78,7 +78,7 @@ function genCreateManyGQL (key, fields, prefix = '') {
`
}

function genUpdateGQL (key, fields, prefix = '') {
function generateUpdateGQL (key, fields, prefix = '') {
const [MODEL] = getModelForms(key)
const mutationName = prefix ? `${prefix}Update${MODEL}` : `update${MODEL}`
const capitalizedPrefix = prefix.length ? prefix.charAt(0).toUpperCase() + prefix.slice(1) : ''
Expand All @@ -91,7 +91,7 @@ function genUpdateGQL (key, fields, prefix = '') {
`
}

function genUpdateManyGQL (key, fields, prefix = '') {
function generateUpdateManyGQL (key, fields, prefix = '') {
const [, MODELS] = getModelForms(key)
const capitalizedPrefix = prefix.length ? prefix.charAt(0).toUpperCase() + prefix.slice(1) : ''
const mutationName = prefix ? `${prefix}Update${MODELS}` : `update${MODELS}`
Expand All @@ -104,7 +104,7 @@ function genUpdateManyGQL (key, fields, prefix = '') {
}

// TODO(DOMA-4411): add prefix or remove at all
function genDeleteGQL (key, fields) {
function generateDeleteGQL (key, fields) {
const [MODEL] = getModelForms(key)
return gql`
mutation delete${MODEL}($id: ID!) {
Expand All @@ -114,7 +114,7 @@ function genDeleteGQL (key, fields) {
}

// TODO(DOMA-4411): add prefix or remove at all
function genDeleteMany (key, fields) {
function generateDeleteMany (key, fields) {
const [, MODELS] = getModelForms(key)
return gql`
mutation delete${MODELS}($ids: [ID!]) {
Expand All @@ -129,15 +129,15 @@ function generateGqlQueries (key, fields, prefix = '') {
if (!fields.startsWith('{') || !fields.endsWith('}'))
throw new Error('wrong list fields format. Try "{ name1 name2 }"')

const GET_ALL_OBJS_QUERY = genGetAllGQL(singularName, fields, prefix)
const GET_COUNT_OBJS_QUERY = genGetCountGQL(singularName, prefix)
const GET_ALL_OBJS_WITH_COUNT_QUERY = genGetAllWithCountGQL(singularName, fields, prefix)
const CREATE_OBJ_MUTATION = genCreateGQL(singularName, fields, prefix)
const CREATE_OBJS_MUTATION = genCreateManyGQL(singularName, fields, prefix)
const UPDATE_OBJ_MUTATION = genUpdateGQL(singularName, fields, prefix)
const UPDATE_OBJS_MUTATION = genUpdateManyGQL(singularName, fields, prefix)
const DELETE_OBJ_MUTATION = genDeleteGQL(singularName, fields)
const DELETE_OBJS_MUTATION = genDeleteMany(singularName, fields)
const GET_ALL_OBJS_QUERY = generateGetAllGQL(singularName, fields, prefix)
const GET_COUNT_OBJS_QUERY = generateGetCountGQL(singularName, prefix)
const GET_ALL_OBJS_WITH_COUNT_QUERY = generateGetAllWithCountGQL(singularName, fields, prefix)
const CREATE_OBJ_MUTATION = generateCreateGQL(singularName, fields, prefix)
const CREATE_OBJS_MUTATION = generateCreateManyGQL(singularName, fields, prefix)
const UPDATE_OBJ_MUTATION = generateUpdateGQL(singularName, fields, prefix)
const UPDATE_OBJS_MUTATION = generateUpdateManyGQL(singularName, fields, prefix)
const DELETE_OBJ_MUTATION = generateDeleteGQL(singularName, fields)
const DELETE_OBJS_MUTATION = generateDeleteMany(singularName, fields)

return {
SINGULAR_FORM: singularName,
Expand Down Expand Up @@ -245,4 +245,11 @@ module.exports = {
generateGqlQueries,
generateQueryWhereInput,
generateQuerySortBy,
generateGetAllGQL,
generateGetCountGQL,
generateCreateGQL,
generateCreateManyGQL,
generateUpdateGQL,
generateUpdateManyGQL,
generateDeleteGQL,
}
Loading
Loading