Skip to content

Commit

Permalink
feat(condo): DOMA-10042 rename suggestServiceProviderService
Browse files Browse the repository at this point in the history
  • Loading branch information
YEgorLu committed Sep 2, 2024
1 parent fb7179a commit eba67bd
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { throwAuthenticationError } = require('@open-condo/keystone/apolloErrorFo

const { RESIDENT } = require('@condo/domains/user/constants/common')

async function canSuggestProviderByTin ({ authentication: { item: user } }) {
async function canSuggestProvider ({ authentication: { item: user } }) {
if (!user) return throwAuthenticationError()
if (user.deletedAt) return false
return user.isAdmin || user.isSupport || user.type === RESIDENT
Expand All @@ -16,5 +16,5 @@ async function canSuggestProviderByTin ({ authentication: { item: user } }) {
all or no items are available) or a set of filters that limit the available items.
*/
module.exports = {
canSuggestProviderByTin,
canSuggestProvider,
}
8 changes: 4 additions & 4 deletions apps/condo/domains/resident/gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ const REGISTER_RESIDENT_SERVICE_CONSUMERS_MUTATION = gql`
}
`

const SUGGEST_PROVIDER_BY_TIN_QUERY = gql`
query suggestProviderByTin ($data: SuggestProviderByTinInput!) {
result: suggestProviderByTin(data: $data) { tin, name }
const SUGGEST_PROVIDER_QUERY = gql`
query suggestProviderByTin ($data: SuggestProviderInput!) {
result: suggestProvider(data: $data) { tin, name }
}
`

Expand All @@ -93,6 +93,6 @@ module.exports = {
REGISTER_RESIDENT_SERVICE_CONSUMERS_MUTATION,
REGISTER_RESIDENT_INVOICE_MUTATION,
FIND_ORGANIZATIONS_FOR_ADDRESS_QUERY,
SUGGEST_PROVIDER_BY_TIN_QUERY,
SUGGEST_PROVIDER_QUERY,
/* AUTOGENERATE MARKER <EXPORTS> */
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { AcquiringIntegrationContext } = require('@condo/domains/acquiring/utils/
const { MeterResourceOwner } = require('@condo/domains/meter/utils/serverSchema')
const { SERVICE_PROVIDER_TYPE } = require('@condo/domains/organization/constants/common')
const { Organization } = require('@condo/domains/organization/utils/serverSchema')
const access = require('@condo/domains/resident/access/SuggestServiceProviderByTinService')
const access = require('@condo/domains/resident/access/SuggestServiceProviderService')
const { MAX_RESIDENT_SUGGEST_SERVICE_PROVIDER_BY_WINDOW_SEC, RESIDENT_SUGGEST_SERVICE_PROVIDER_WINDOW_SEC } = require('@condo/domains/resident/constants')
const { RESIDENT } = require('@condo/domains/user/constants/common')
const { RedisGuard } = require('@condo/domains/user/utils/serverSchema/guards')
Expand Down Expand Up @@ -49,22 +49,22 @@ const filterOrganizationsByAcquiringContextOrMeterResourceOwnership = async (con
}


const SuggestServiceProviderByTinService = new GQLCustomSchema('SuggestServiceProviderByTinService', {
const SuggestServiceProviderService = new GQLCustomSchema('SuggestServiceProviderByTinService', {
types: [
{
access: true,
type: 'input SuggestProviderByTinInput { tinOrName: String! }',
type: 'input SuggestProviderInput { tinOrName: String! }',
},
{
access: true,
type: 'type SuggestProviderByTinOutput { tin: String!, name: String! }',
type: 'type SuggestProviderOutput { tin: String!, name: String! }',
},
],

queries: [
{
access: access.canSuggestProviderByTin,
schema: 'suggestProviderByTin (data: SuggestProviderByTinInput!): [SuggestProviderByTinOutput]',
access: access.canSuggestProvider,
schema: 'suggestProvider (data: SuggestProviderInput!): [SuggestProviderOutput]',
resolver: async (parent, args, context = {}) => {
if (context.authedItem.type === RESIDENT) {
await checkLimits(context.authedItem.id)
Expand Down Expand Up @@ -93,5 +93,5 @@ const SuggestServiceProviderByTinService = new GQLCustomSchema('SuggestServicePr
})

module.exports = {
SuggestServiceProviderByTinService,
SuggestServiceProviderService,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Generated by `createservice organization.SuggestServiceProviderByTinService --type queries`
* Generated by `createservice organization.SuggestServiceProviderService --type queries`
*/

const { faker } = require('@faker-js/faker')
Expand All @@ -23,7 +23,7 @@ const { createTestMeterResourceOwner, updateTestMeterResourceOwner, MeterResourc
const { SERVICE_PROVIDER_TYPE } = require('@condo/domains/organization/constants/common')
const { createTestOrganization, updateTestOrganization, generateTin } = require('@condo/domains/organization/utils/testSchema')
const { createTestProperty, updateTestProperty } = require('@condo/domains/property/utils/testSchema')
const { suggestProviderByTinServiceByTestClient } = require('@condo/domains/resident/utils/testSchema')
const { suggestProviderByTestClient } = require('@condo/domains/resident/utils/testSchema')


const addMeterResourceOwner = async (utils) => {
Expand Down Expand Up @@ -52,7 +52,7 @@ const generateServiceProviders = async (client, count, extraAttrs) => {
return Promise.all(serviceProviders)
}

describe('SuggestServiceProviderByTinService', () => {
describe('SuggestServiceProviderService', () => {

let utils

Expand All @@ -65,46 +65,46 @@ describe('SuggestServiceProviderByTinService', () => {
describe('Permissions check', () => {
test('anonymous: can not execute', async () => {
await expectToThrowAuthenticationErrorToResult(async () => {
await suggestProviderByTinServiceByTestClient(utils.clients.anonymous, {
await suggestProviderByTestClient(utils.clients.anonymous, {
tinOrName: String(generateTin(RUSSIAN_COUNTRY)),
})
})
})
test('user: can not execute', async () => {
await expectToThrowAccessDeniedErrorToResult(async () => {
await suggestProviderByTinServiceByTestClient(utils.clients.user, {
await suggestProviderByTestClient(utils.clients.user, {
tinOrName: String(generateTin(RUSSIAN_COUNTRY)),
})
})
})
test('employee: can not execute', async () => {
await expectToThrowAccessDeniedErrorToResult(async () => {
await suggestProviderByTinServiceByTestClient(utils.clients.employee['billing'], {
await suggestProviderByTestClient(utils.clients.employee['billing'], {
tinOrName: String(generateTin(RUSSIAN_COUNTRY)),
})
})
})
test('service user: can not execute', async () => {
await expectToThrowAccessDeniedErrorToResult(async () => {
await suggestProviderByTinServiceByTestClient(utils.clients.service, {
await suggestProviderByTestClient(utils.clients.service, {
tinOrName: String(generateTin(RUSSIAN_COUNTRY)),
})
})
})
test('admin: can execute', async () => {
const [organizations] = await suggestProviderByTinServiceByTestClient(utils.clients.admin, {
const [organizations] = await suggestProviderByTestClient(utils.clients.admin, {
tinOrName: utils.organization.tin.substr(0, 5),
})
expect(organizations).not.toHaveLength(0)
})
test('support: can execute', async () => {
const [organizations] = await suggestProviderByTinServiceByTestClient(utils.clients.support, {
const [organizations] = await suggestProviderByTestClient(utils.clients.support, {
tinOrName: utils.organization.tin.substr(0, 5),
})
expect(organizations).not.toHaveLength(0)
})
test('resident: can execute', async () => {
const [organizations] = await suggestProviderByTinServiceByTestClient(utils.clients.resident, {
const [organizations] = await suggestProviderByTestClient(utils.clients.resident, {
tinOrName: utils.organization.tin.substr(0, 5),
})
expect(organizations).not.toHaveLength(0)
Expand All @@ -126,7 +126,7 @@ describe('SuggestServiceProviderByTinService', () => {

test('should find organization with finished acquiring context', async () => {
for (const tinOrName of getPartialTinAndName()) {
const [organizations] = await suggestProviderByTinServiceByTestClient(utils.clients.resident, {
const [organizations] = await suggestProviderByTestClient(utils.clients.resident, {
tinOrName: tinOrName,
})
expect(organizations).toContainEqual({
Expand All @@ -141,7 +141,7 @@ describe('SuggestServiceProviderByTinService', () => {
await addMeterResourceOwner(utils)

for (const tinOrName of getPartialTinAndName()) {
const [organizations] = await suggestProviderByTinServiceByTestClient(utils.clients.resident, {
const [organizations] = await suggestProviderByTestClient(utils.clients.resident, {
tinOrName: tinOrName,
})
expect(organizations).toContainEqual({
Expand All @@ -155,7 +155,7 @@ describe('SuggestServiceProviderByTinService', () => {
await addMeterResourceOwner(utils)

for (const tinOrName of getPartialTinAndName()) {
const [organizations] = await suggestProviderByTinServiceByTestClient(utils.clients.resident, {
const [organizations] = await suggestProviderByTestClient(utils.clients.resident, {
tinOrName: tinOrName,
})
expect(organizations).toContainEqual({
Expand All @@ -169,7 +169,7 @@ describe('SuggestServiceProviderByTinService', () => {
await utils.updateAcquiringContext({ status: CONTEXT_IN_PROGRESS_STATUS })

for (const tinOrName of getPartialTinAndName()) {
const [organizations] = await suggestProviderByTinServiceByTestClient(utils.clients.resident, {
const [organizations] = await suggestProviderByTestClient(utils.clients.resident, {
tinOrName: tinOrName,
})
expect(organizations).not.toContainEqual({
Expand Down Expand Up @@ -219,7 +219,7 @@ describe('SuggestServiceProviderByTinService', () => {
]

for (const searchParam of searchParams) {
const [suggestedProviders] = await suggestProviderByTinServiceByTestClient(utils.clients.resident, {
const [suggestedProviders] = await suggestProviderByTestClient(utils.clients.resident, {
tinOrName: searchParam,
})
const uniqueTins = new Set(suggestedProviders.map((provider) => provider.tin))
Expand Down
4 changes: 2 additions & 2 deletions apps/condo/domains/resident/schema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { RegisterServiceConsumerService } = require('./RegisterServiceConsumerSer
const { Resident } = require('./Resident')
const { SendMessageToResidentScopesService } = require('./SendMessageToResidentScopesService')
const { ServiceConsumer } = require('./ServiceConsumer')
const { SuggestServiceProviderByTinService } = require('./SuggestServiceProviderByTinService')
const { SuggestServiceProviderService } = require('./SuggestServiceProviderService')
/* AUTOGENERATE MARKER <REQUIRE> */

module.exports = {
Expand All @@ -25,6 +25,6 @@ module.exports = {
GetResidentExistenceByPhoneAndAddressService,
RegisterResidentInvoiceService,
FindOrganizationsForAddressService,
SuggestServiceProviderByTinService,
SuggestServiceProviderService,
/* AUTOGENERATE MARKER <EXPORTS> */
}
4 changes: 2 additions & 2 deletions apps/condo/domains/resident/utils/serverSchema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { generateServerUtils, execGqlWithoutAccess } = require('@open-condo/codeg
const { getLogger } = require('@open-condo/keystone/logging')

const { REGISTER_RESIDENT_MUTATION } = require('@condo/domains/property/gql')
const { SUGGEST_PROVIDER_BY_TIN_QUERY } = require('@condo/domains/resident/gql')
const { SUGGEST_PROVIDER_QUERY } = require('@condo/domains/resident/gql')
const { Resident: ResidentGQL, REGISTER_RESIDENT_INVOICE_MUTATION } = require('@condo/domains/resident/gql')
const { ServiceConsumer: ServiceConsumerGQL } = require('@condo/domains/resident/gql')
const { REGISTER_CONSUMER_SERVICE_MUTATION } = require('@condo/domains/resident/gql')
Expand Down Expand Up @@ -129,7 +129,7 @@ async function suggestProviderByTin (context, data) {
if (!context) throw new Error('no context')
if (!data) throw new Error('no data')
return await execGqlWithoutAccess(context, {
query: SUGGEST_PROVIDER_BY_TIN_QUERY,
query: SUGGEST_PROVIDER_QUERY,
variables: { data },
errorMessage: '[error] Unable to suggestProviderByTin',
dataPath: 'result',
Expand Down
8 changes: 4 additions & 4 deletions apps/condo/domains/resident/utils/testSchema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const {
DISCOVER_SERVICE_CONSUMERS_MUTATION,
SEND_MESSAGE_TO_RESIDENT_SCOPES_MUTATION,
REGISTER_SERVICE_CONSUMER_MUTATION,
SUGGEST_PROVIDER_BY_TIN_QUERY
SUGGEST_PROVIDER_QUERY
} = require('@condo/domains/resident/gql')
const { makeClientWithResidentUser } = require(
'@condo/domains/user/utils/testSchema')
Expand Down Expand Up @@ -258,9 +258,9 @@ async function registerResidentInvoiceByTestClient (client, resident, invoiceRow
return [data.result, attrs]
}

async function suggestProviderByTinServiceByTestClient(client, attrs = {}) {
async function suggestProviderByTestClient(client, attrs = {}) {
if (!client) throw new Error('no client')
const { data, errors } = await client.query(SUGGEST_PROVIDER_BY_TIN_QUERY, { data: attrs })
const { data, errors } = await client.query(SUGGEST_PROVIDER_QUERY, { data: attrs })
throwIfError(data, errors)
return [data.result, attrs]
}
Expand All @@ -277,6 +277,6 @@ module.exports = {
registerResidentServiceConsumersByTestClient,
registerResidentInvoiceByTestClient,
findOrganizationsForAddressByTestClient,
suggestProviderByTinServiceByTestClient
suggestProviderByTestClient,
/* AUTOGENERATE MARKER <EXPORTS> */
}
8 changes: 4 additions & 4 deletions apps/condo/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -77652,11 +77652,11 @@ type FindOrganizationForAddressOutput {
hasBillingData: Boolean!
}

input SuggestProviderByTinInput {
tin: String!
input SuggestProviderInput {
tinOrName: String!
}

type SuggestProviderByTinOutput {
type SuggestProviderOutput {
tin: String!
name: String!
}
Expand Down Expand Up @@ -82238,7 +82238,7 @@ type Query {
predictTicketClassification(data: PredictTicketClassificationInput!): TicketClassifier
getResidentExistenceByPhoneAndAddress(data: GetResidentExistenceByPhoneAndAddressInput!): GetResidentExistenceByPhoneAndAddressOutput
findOrganizationsForAddress(data: FindOrganizationsForAddressInput!): [FindOrganizationForAddressOutput]
suggestProviderByTin(data: SuggestProviderByTinInput!): [SuggestProviderByTinOutput]
suggestProvider(data: SuggestProviderInput!): [SuggestProviderOutput]
exportMeterReadings(data: ExportMeterReadingsInput!): ExportMeterReadingsOutput

"""
Expand Down
14 changes: 7 additions & 7 deletions apps/condo/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66110,7 +66110,7 @@ export type Query = {
predictTicketClassification?: Maybe<TicketClassifier>;
getResidentExistenceByPhoneAndAddress?: Maybe<GetResidentExistenceByPhoneAndAddressOutput>;
findOrganizationsForAddress?: Maybe<Array<Maybe<FindOrganizationForAddressOutput>>>;
suggestProviderByTin?: Maybe<Array<Maybe<SuggestProviderByTinOutput>>>;
suggestProvider?: Maybe<Array<Maybe<SuggestProviderOutput>>>;
exportMeterReadings?: Maybe<ExportMeterReadingsOutput>;
/**
* Export of property meters readings. A link to the file is returned
Expand Down Expand Up @@ -72813,8 +72813,8 @@ export type QueryFindOrganizationsForAddressArgs = {
};


export type QuerySuggestProviderByTinArgs = {
data: SuggestProviderByTinInput;
export type QuerySuggestProviderArgs = {
data: SuggestProviderInput;
};


Expand Down Expand Up @@ -85081,12 +85081,12 @@ export enum Status {
Error = 'error'
}

export type SuggestProviderByTinInput = {
tin: Scalars['String'];
export type SuggestProviderInput = {
tinOrName: Scalars['String'];
};

export type SuggestProviderByTinOutput = {
__typename?: 'SuggestProviderByTinOutput';
export type SuggestProviderOutput = {
__typename?: 'SuggestProviderOutput';
tin: Scalars['String'];
name: Scalars['String'];
};
Expand Down

0 comments on commit eba67bd

Please sign in to comment.