From fc6005238c3e61132ea4eaea72ed2609a1a7aea4 Mon Sep 17 00:00:00 2001 From: portuu3 <61605646+portuu3@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:46:59 +0200 Subject: [PATCH] Rename registrations in exchange oracles (#2683) * Rename registrations in exchange oracles * update variable to registrationInExchangeOracleError * rename variable to isRegistrationInExchangeOraclePending --- .../src/modules/user/user.controller.ts | 2 +- .../human-app/frontend/src/api/api-paths.ts | 4 +- ...> get-registration-in-exchange-oracles.ts} | 10 ++--- ...ts => registration-in-exchange-oracles.ts} | 20 +++++---- .../drawer-menu-items-operator.tsx | 2 - .../drawer-menu-items-worker.tsx | 2 - .../apps/human-app/frontend/src/i18n/en.json | 4 +- .../oracles-table/oracles-table.tsx | 11 +++-- .../worker/registration/registration.page.tsx | 36 +++++++++------- .../frontend/src/router/router-paths.ts | 2 +- .../human-app/frontend/src/router/routes.tsx | 4 +- .../common/config/gateway-config.service.ts | 8 ++-- .../spec/gateway-config-service.mock.ts | 4 +- .../enums/reputation-oracle-endpoints.ts | 4 +- .../exchange-oracle.gateway.ts | 14 +++--- .../exchange-oracle.mapper.profile.ts | 8 ++-- .../spec/exchange-oracle.gateway.mock.ts | 2 +- .../spec/exchange-oracle.gateway.spec.ts | 14 +++--- .../reputation-oracle.gateway.ts | 28 ++++++------ .../reputation-oracle.mapper.profile.ts | 8 ++-- .../spec/reputation-oracle.gateway.mock.ts | 2 +- .../spec/reputation-oracle.gateway.spec.ts | 28 ++++++++---- .../model/worker-registration.model.ts | 13 +++--- .../spec/worker.controller.spec.ts | 12 +++--- .../user-worker/spec/worker.fixtures.ts | 27 ++++++------ .../user-worker/spec/worker.service.mock.ts | 2 +- .../user-worker/spec/worker.service.spec.ts | 11 +++-- .../modules/user-worker/worker.controller.ts | 42 +++++++++--------- .../user-worker/worker.mapper.profile.ts | 8 ++-- .../src/modules/user-worker/worker.service.ts | 18 ++++---- .../src/modules/user/user.controller.ts | 43 ++++++++++--------- .../server/src/modules/user/user.dto.ts | 8 +++- .../src/modules/user/user.service.spec.ts | 20 ++++----- .../server/src/modules/user/user.service.ts | 10 +++-- 34 files changed, 232 insertions(+), 199 deletions(-) rename packages/apps/human-app/frontend/src/api/services/worker/{registered-oracles.ts => get-registration-in-exchange-oracles.ts} (65%) rename packages/apps/human-app/frontend/src/api/services/worker/{user-registration.ts => registration-in-exchange-oracles.ts} (58%) diff --git a/packages/apps/fortune/exchange-oracle/server/src/modules/user/user.controller.ts b/packages/apps/fortune/exchange-oracle/server/src/modules/user/user.controller.ts index 1cc2148acf..7799b00ef8 100644 --- a/packages/apps/fortune/exchange-oracle/server/src/modules/user/user.controller.ts +++ b/packages/apps/fortune/exchange-oracle/server/src/modules/user/user.controller.ts @@ -12,7 +12,7 @@ import { JwtAuthGuard } from '../../common/guards/jwt.auth'; @UseGuards(JwtAuthGuard) @ApiBearerAuth() export class UserController { - @Post('registration') + @Post('register') @ApiOperation({ summary: 'Register a user in Exchange Oracle', description: 'Endpoint to register a user in Exchange Oracle.', diff --git a/packages/apps/human-app/frontend/src/api/api-paths.ts b/packages/apps/human-app/frontend/src/api/api-paths.ts index 6054892e6e..7b22674d62 100644 --- a/packages/apps/human-app/frontend/src/api/api-paths.ts +++ b/packages/apps/human-app/frontend/src/api/api-paths.ts @@ -65,8 +65,8 @@ export const apiPaths = { dailyHmtSpend: { path: '/labeling/h-captcha/daily-hmt-spent', }, - userRegistration: { - path: '/registration', + registrationInExchangeOracle: { + path: '/exchange-oracle-registration', }, }, operator: { diff --git a/packages/apps/human-app/frontend/src/api/services/worker/registered-oracles.ts b/packages/apps/human-app/frontend/src/api/services/worker/get-registration-in-exchange-oracles.ts similarity index 65% rename from packages/apps/human-app/frontend/src/api/services/worker/registered-oracles.ts rename to packages/apps/human-app/frontend/src/api/services/worker/get-registration-in-exchange-oracles.ts index 2c9e48291e..177c86cf21 100644 --- a/packages/apps/human-app/frontend/src/api/services/worker/registered-oracles.ts +++ b/packages/apps/human-app/frontend/src/api/services/worker/get-registration-in-exchange-oracles.ts @@ -8,18 +8,18 @@ const RegisteredOraclesSuccessResponseSchema = z.object({ oracle_addresses: z.array(z.string()), }); -export async function getRegisteredOracles() { - return apiClient(apiPaths.worker.userRegistration.path, { +export async function getRegistrationInExchangeOracles() { + return apiClient(apiPaths.worker.registrationInExchangeOracle.path, { authenticated: true, successSchema: RegisteredOraclesSuccessResponseSchema, options: { method: 'GET' }, }); } -export function useGetRegisteredOracles() { +export function useGetRegistrationInExchangeOracles() { return useQuery({ - queryFn: () => getRegisteredOracles(), - queryKey: ['getRegisteredOracles'], + queryFn: () => getRegistrationInExchangeOracles(), + queryKey: ['getRegistrationInExchangeOracles'], refetchOnMount: false, refetchOnWindowFocus: false, refetchOnReconnect: false, diff --git a/packages/apps/human-app/frontend/src/api/services/worker/user-registration.ts b/packages/apps/human-app/frontend/src/api/services/worker/registration-in-exchange-oracles.ts similarity index 58% rename from packages/apps/human-app/frontend/src/api/services/worker/user-registration.ts rename to packages/apps/human-app/frontend/src/api/services/worker/registration-in-exchange-oracles.ts index 00a99d3011..7406a2336c 100644 --- a/packages/apps/human-app/frontend/src/api/services/worker/user-registration.ts +++ b/packages/apps/human-app/frontend/src/api/services/worker/registration-in-exchange-oracles.ts @@ -6,7 +6,7 @@ import { t } from 'i18next'; import { apiClient } from '@/api/api-client'; import { apiPaths } from '@/api/api-paths'; -export const registrationDtoSchema = z.object({ +export const registrationInExchangeOracleDtoSchema = z.object({ oracle_address: z .string() .refine( @@ -16,23 +16,27 @@ export const registrationDtoSchema = z.object({ h_captcha_token: z.string().min(1, t('validation.captcha')).default('token'), }); -export type RegistrationDto = z.infer; +export type RegistrationInExchangeOracleDto = z.infer< + typeof registrationInExchangeOracleDtoSchema +>; -const UserRegistrationSuccessResponseSchema = z.unknown(); +const RegistrationInExchangeOracleSuccessResponseSchema = z.unknown(); -function userRegistrationMutationFn(data: RegistrationDto) { - return apiClient(apiPaths.worker.userRegistration.path, { +function registrationInExchangeOracleMutationFn( + data: RegistrationInExchangeOracleDto +) { + return apiClient(apiPaths.worker.registrationInExchangeOracle.path, { authenticated: true, - successSchema: UserRegistrationSuccessResponseSchema, + successSchema: RegistrationInExchangeOracleSuccessResponseSchema, options: { method: 'POST', body: JSON.stringify(data) }, }); } -export function useUserRegistrationMutation() { +export function useExchangeOracleRegistrationMutation() { const queryClient = useQueryClient(); return useMutation({ - mutationFn: userRegistrationMutationFn, + mutationFn: registrationInExchangeOracleMutationFn, onSuccess: async () => { await queryClient.invalidateQueries(); }, diff --git a/packages/apps/human-app/frontend/src/components/layout/drawer-menu-items/drawer-menu-items-operator.tsx b/packages/apps/human-app/frontend/src/components/layout/drawer-menu-items/drawer-menu-items-operator.tsx index 730ca45155..4c20366752 100644 --- a/packages/apps/human-app/frontend/src/components/layout/drawer-menu-items/drawer-menu-items-operator.tsx +++ b/packages/apps/human-app/frontend/src/components/layout/drawer-menu-items/drawer-menu-items-operator.tsx @@ -15,10 +15,8 @@ export const operatorDrawerBottomMenuItems: BottomMenuItem[] = [ icon: , onClick: () => { // @ts-expect-error -- ... - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- ... if ($zoho?.salesiq?.chat?.start) { // @ts-expect-error -- ... - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call -- ... $zoho.salesiq.chat.start(); } }, diff --git a/packages/apps/human-app/frontend/src/components/layout/drawer-menu-items/drawer-menu-items-worker.tsx b/packages/apps/human-app/frontend/src/components/layout/drawer-menu-items/drawer-menu-items-worker.tsx index 1bf264713f..e2cc69e826 100644 --- a/packages/apps/human-app/frontend/src/components/layout/drawer-menu-items/drawer-menu-items-worker.tsx +++ b/packages/apps/human-app/frontend/src/components/layout/drawer-menu-items/drawer-menu-items-worker.tsx @@ -37,10 +37,8 @@ export const workerDrawerBottomMenuItems: BottomMenuItem[] = [ icon: , onClick: () => { // @ts-expect-error -- ... - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- ... if ($zoho?.salesiq?.chat?.start) { // @ts-expect-error -- ... - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call -- ... $zoho.salesiq.chat.start(); } }, diff --git a/packages/apps/human-app/frontend/src/i18n/en.json b/packages/apps/human-app/frontend/src/i18n/en.json index ef46ea1e5f..e129df0558 100644 --- a/packages/apps/human-app/frontend/src/i18n/en.json +++ b/packages/apps/human-app/frontend/src/i18n/en.json @@ -11,7 +11,7 @@ "jobsDiscovery": "Tasks", "hcaptchaLabeling": "Labeling", "jobs": "Tasks", - "registration": "Registration" + "registrationInExchangeOracle": "Registration in Exchange Oracle" }, "web3ProtectedPagesHeaders": { "profile": "Profile" @@ -211,7 +211,7 @@ "seeJobs": "See tasks", "allJobs": "All tasks" }, - "registration": { + "registrationInExchangeOracle": { "requiredMessage": "This oracle requires a registration process. Click on the link below to see the registration tutorial:", "completeMessage": "Click on Complete once you have finished the registration process:", "completeButton": "Complete" diff --git a/packages/apps/human-app/frontend/src/pages/worker/jobs-discovery/components/oracles-table/oracles-table.tsx b/packages/apps/human-app/frontend/src/pages/worker/jobs-discovery/components/oracles-table/oracles-table.tsx index f021eb09f2..943dc2800b 100644 --- a/packages/apps/human-app/frontend/src/pages/worker/jobs-discovery/components/oracles-table/oracles-table.tsx +++ b/packages/apps/human-app/frontend/src/pages/worker/jobs-discovery/components/oracles-table/oracles-table.tsx @@ -19,7 +19,7 @@ import { createTableDarkMode } from '@/styles/create-table-dark-mode'; import { env } from '@/shared/env'; import { useAuthenticatedUser } from '@/auth/use-authenticated-user'; import { type JobType } from '@/smart-contracts/EthKVStore/config'; -import { useGetRegisteredOracles } from '@/api/services/worker/registered-oracles'; +import { useGetRegistrationInExchangeOracles } from '@/api/services/worker/get-registration-in-exchange-oracles'; const getColumns = ( selectOracle: (oracle: OracleSuccessResponse) => void @@ -88,16 +88,19 @@ export function OraclesTable({ const navigate = useNavigate(); const isMobile = useIsMobile(); const { user } = useAuthenticatedUser(); - const { data: registeredOraclesResults } = useGetRegisteredOracles(); + const { data: registrationInExchangeOraclesResult } = + useGetRegistrationInExchangeOracles(); const selectOracle = (oracle: OracleSuccessResponse) => { if ( oracle.registrationNeeded && - !registeredOraclesResults?.oracle_addresses.find( + !registrationInExchangeOraclesResult?.oracle_addresses.find( (address) => address === oracle.address ) ) { - navigate(`${routerPaths.worker.registration}/${oracle.address}`); + navigate( + `${routerPaths.worker.registrationInExchangeOracle}/${oracle.address}` + ); return; } diff --git a/packages/apps/human-app/frontend/src/pages/worker/registration/registration.page.tsx b/packages/apps/human-app/frontend/src/pages/worker/registration/registration.page.tsx index 8e4d1bda8f..221e8d1c90 100644 --- a/packages/apps/human-app/frontend/src/pages/worker/registration/registration.page.tsx +++ b/packages/apps/human-app/frontend/src/pages/worker/registration/registration.page.tsx @@ -7,10 +7,10 @@ import { zodResolver } from '@hookform/resolvers/zod'; import { FormCaptcha } from '@/components/h-captcha'; import { Button } from '@/components/ui/button'; import { - type RegistrationDto, - registrationDtoSchema, - useUserRegistrationMutation, -} from '@/api/services/worker/user-registration'; + type RegistrationInExchangeOracleDto, + registrationInExchangeOracleDtoSchema, + useExchangeOracleRegistrationMutation, +} from '@/api/services/worker/registration-in-exchange-oracles'; import { useRegisteredOracles } from '@/contexts/registered-oracles'; import { useGetOracles } from '@/api/services/worker/oracles'; import { routerPaths } from '@/router/router-paths'; @@ -27,27 +27,29 @@ export function RegistrationPage() { const { registeredOracles, setRegisteredOracles } = useRegisteredOracles(); - const methods = useForm({ + const methods = useForm({ defaultValues: { // eslint-disable-next-line camelcase oracle_address: oracleAddress, // eslint-disable-next-line camelcase h_captcha_token: '', }, - resolver: zodResolver(registrationDtoSchema), + resolver: zodResolver(registrationInExchangeOracleDtoSchema), }); const { mutate: userRegistrationMutate, - isPending: isUserRegistrationPending, - error: userRegistrationError, - } = useUserRegistrationMutation(); + isPending: isRegistrationInExchangeOraclePending, + error: registrationInExchangeOracleError, + } = useExchangeOracleRegistrationMutation(); const handleLinkClick = () => { setHasClickedRegistrationLink(true); }; - const handleRegistrationComplete = (data: RegistrationDto) => { + const handleRegistrationComplete = ( + data: RegistrationInExchangeOracleDto + ) => { userRegistrationMutate(data, { onSuccess(_data) { if (oracleAddress !== undefined) { @@ -99,7 +101,9 @@ export function RegistrationPage() { }} > - {t('worker.registration.requiredMessage')} + + {t('worker.registrationInExchangeOracle.requiredMessage')} + {oracleData?.registrationInstructions} - {t('worker.registration.completeMessage')} + + {t('worker.registrationInExchangeOracle.completeMessage')} +
@@ -118,17 +124,17 @@ export function RegistrationPage() { >
diff --git a/packages/apps/human-app/frontend/src/router/router-paths.ts b/packages/apps/human-app/frontend/src/router/router-paths.ts index 8c5c42d060..a5094292dd 100644 --- a/packages/apps/human-app/frontend/src/router/router-paths.ts +++ b/packages/apps/human-app/frontend/src/router/router-paths.ts @@ -15,7 +15,7 @@ export const routerPaths = { jobs: '/worker/jobs', HcaptchaLabeling: '/worker/hcaptcha-labeling', enableLabeler: '/worker/enable-labeler', - registration: '/worker/registration', + registrationInExchangeOracle: '/worker/registration-in-exchange-oracle', }, operator: { signIn: '/operator/sign-in', diff --git a/packages/apps/human-app/frontend/src/router/routes.tsx b/packages/apps/human-app/frontend/src/router/routes.tsx index 8a53a1cd82..56b63b247e 100644 --- a/packages/apps/human-app/frontend/src/router/routes.tsx +++ b/packages/apps/human-app/frontend/src/router/routes.tsx @@ -114,12 +114,12 @@ export const protectedRoutes: { }, { routerProps: { - path: `${routerPaths.worker.registration}/:address`, + path: `${routerPaths.worker.registrationInExchangeOracle}/:address`, element: , }, pageHeaderProps: { headerIcon: , - headerText: t('protectedPagesHeaders.registration'), + headerText: t('protectedPagesHeaders.registrationInExchangeOracle'), }, }, ] diff --git a/packages/apps/human-app/server/src/common/config/gateway-config.service.ts b/packages/apps/human-app/server/src/common/config/gateway-config.service.ts index 5354884aa6..11439c7036 100644 --- a/packages/apps/human-app/server/src/common/config/gateway-config.service.ts +++ b/packages/apps/human-app/server/src/common/config/gateway-config.service.ts @@ -41,8 +41,8 @@ export class GatewayConfigService { method: HttpMethod.POST, headers: this.JSON_HEADER, }, - [ReputationOracleEndpoints.WORKER_REGISTRATION]: { - endpoint: '/user/registration', + [ReputationOracleEndpoints.REGISTRATION_IN_EXCHANGE_ORACLE]: { + endpoint: '/user/exchange-oracle-registration', method: HttpMethod.POST, headers: this.JSON_HEADER, }, @@ -105,8 +105,8 @@ export class GatewayConfigService { method: HttpMethod.GET, headers: this.JSON_HEADER, }, - [ReputationOracleEndpoints.GET_REGISTERED_ORACLES]: { - endpoint: '/user/registration', + [ReputationOracleEndpoints.GET_REGISTRATION_IN_EXCHANGE_ORACLES]: { + endpoint: '/user/exchange-oracle-registration', method: HttpMethod.GET, headers: this.JSON_HEADER, }, diff --git a/packages/apps/human-app/server/src/common/config/spec/gateway-config-service.mock.ts b/packages/apps/human-app/server/src/common/config/spec/gateway-config-service.mock.ts index 9e7ce41c4d..77fee34664 100644 --- a/packages/apps/human-app/server/src/common/config/spec/gateway-config-service.mock.ts +++ b/packages/apps/human-app/server/src/common/config/spec/gateway-config-service.mock.ts @@ -17,8 +17,8 @@ export const gatewayConfigServiceMock = { method: 'POST', headers: { 'Content-Type': 'application/json' }, }, - WORKER_REGISTRATION: { - endpoint: '/user/registration', + REGISTRATION_IN_EXCHANGE_ORACLE: { + endpoint: '/user/exchange-oracle-registration', method: 'POST', headers: { 'Content-Type': 'application/json' }, }, diff --git a/packages/apps/human-app/server/src/common/enums/reputation-oracle-endpoints.ts b/packages/apps/human-app/server/src/common/enums/reputation-oracle-endpoints.ts index c27ecad989..1a155abd37 100644 --- a/packages/apps/human-app/server/src/common/enums/reputation-oracle-endpoints.ts +++ b/packages/apps/human-app/server/src/common/enums/reputation-oracle-endpoints.ts @@ -1,7 +1,7 @@ export enum ReputationOracleEndpoints { WORKER_SIGNUP = 'WORKER_SIGNUP', WORKER_SIGNIN = 'WORKER_SIGNIN', - WORKER_REGISTRATION = 'WORKER_REGISTRATION', + REGISTRATION_IN_EXCHANGE_ORACLE = 'REGISTRATION_IN_EXCHANGE_ORACLE', OPERATOR_SIGNUP = 'OPERATOR_SIGNUP', OPERATOR_SIGNIN = 'OPERATOR_SIGNIN', EMAIL_VERIFICATION = 'EMAIL_VERIFICATION', @@ -15,7 +15,7 @@ export enum ReputationOracleEndpoints { REGISTER_ADDRESS = 'REGISTER_ADDRESS', TOKEN_REFRESH = 'TOKEN_REFRESH', KYC_ON_CHAIN = 'KYC_ON_CHAIN', - GET_REGISTERED_ORACLES = 'GET_REGISTERED_ORACLES', + GET_REGISTRATION_IN_EXCHANGE_ORACLES = 'GET_REGISTRATION_IN_EXCHANGE_ORACLES', } export enum HCaptchaLabelingStatsEndpoints { USER_STATS = 'USER_STATS', diff --git a/packages/apps/human-app/server/src/integrations/exchange-oracle/exchange-oracle.gateway.ts b/packages/apps/human-app/server/src/integrations/exchange-oracle/exchange-oracle.gateway.ts index b25b4e6d16..912622c86c 100644 --- a/packages/apps/human-app/server/src/integrations/exchange-oracle/exchange-oracle.gateway.ts +++ b/packages/apps/human-app/server/src/integrations/exchange-oracle/exchange-oracle.gateway.ts @@ -35,8 +35,8 @@ import { toCleanObjParams } from '../../common/utils/gateway-common.utils'; import { KvStoreGateway } from '../kv-store/kv-store.gateway'; import { EscrowUtilsGateway } from '../escrow/escrow-utils-gateway.service'; import { - WorkerRegistrationCommand, - WorkerRegistrationData, + RegistrationInExchangeOracleCommand, + RegistrationInExchangeOracleData, } from '../../modules/user-worker/model/worker-registration.model'; @Injectable() @@ -176,18 +176,20 @@ export class ExchangeOracleGateway { return this.callExternalHttpUtilRequest(options); } - async workerRegistration(command: WorkerRegistrationCommand) { + async sendRegistrationInExchangeOracle( + command: RegistrationInExchangeOracleCommand, + ) { const data = this.mapper.map( command, - WorkerRegistrationCommand, - WorkerRegistrationData, + RegistrationInExchangeOracleCommand, + RegistrationInExchangeOracleData, ); const options: AxiosRequestConfig = { method: HttpMethod.POST, url: `${await this.kvStoreGateway.getExchangeOracleUrlByAddress( command.oracleAddress, - )}/registration`, + )}/register`, data: data, headers: { Authorization: command.token, diff --git a/packages/apps/human-app/server/src/integrations/exchange-oracle/exchange-oracle.mapper.profile.ts b/packages/apps/human-app/server/src/integrations/exchange-oracle/exchange-oracle.mapper.profile.ts index be74e6f5c4..9709289dd4 100644 --- a/packages/apps/human-app/server/src/integrations/exchange-oracle/exchange-oracle.mapper.profile.ts +++ b/packages/apps/human-app/server/src/integrations/exchange-oracle/exchange-oracle.mapper.profile.ts @@ -22,8 +22,8 @@ import { JobsDiscoveryParamsData, } from '../../modules/jobs-discovery/model/jobs-discovery.model'; import { - WorkerRegistrationCommand, - WorkerRegistrationData, + RegistrationInExchangeOracleCommand, + RegistrationInExchangeOracleData, } from '../../modules/user-worker/model/worker-registration.model'; @Injectable() @@ -94,8 +94,8 @@ export class ExchangeOracleProfile extends AutomapperProfile { ); createMap( mapper, - WorkerRegistrationCommand, - WorkerRegistrationData, + RegistrationInExchangeOracleCommand, + RegistrationInExchangeOracleData, namingConventions({ source: new CamelCaseNamingConvention(), destination: new SnakeCaseNamingConvention(), diff --git a/packages/apps/human-app/server/src/integrations/exchange-oracle/spec/exchange-oracle.gateway.mock.ts b/packages/apps/human-app/server/src/integrations/exchange-oracle/spec/exchange-oracle.gateway.mock.ts index 062828d65b..e0edb620de 100644 --- a/packages/apps/human-app/server/src/integrations/exchange-oracle/spec/exchange-oracle.gateway.mock.ts +++ b/packages/apps/human-app/server/src/integrations/exchange-oracle/spec/exchange-oracle.gateway.mock.ts @@ -4,5 +4,5 @@ export const exchangeOracleGatewayMock = { fetchAssignedJobs: jest.fn(), postNewJobAssignment: jest.fn(), fetchDiscoveredJobs: jest.fn(), - workerRegistration: jest.fn(), + sendRegistrationInExchangeOracle: jest.fn(), }; diff --git a/packages/apps/human-app/server/src/integrations/exchange-oracle/spec/exchange-oracle.gateway.spec.ts b/packages/apps/human-app/server/src/integrations/exchange-oracle/spec/exchange-oracle.gateway.spec.ts index 9828e2f6d4..f52aea4d11 100644 --- a/packages/apps/human-app/server/src/integrations/exchange-oracle/spec/exchange-oracle.gateway.spec.ts +++ b/packages/apps/human-app/server/src/integrations/exchange-oracle/spec/exchange-oracle.gateway.spec.ts @@ -33,7 +33,7 @@ import { EscrowUtilsGateway } from '../../escrow/escrow-utils-gateway.service'; import { ResignJobData } from '../../../modules/job-assignment/model/job-assignment.model'; import { JobsDiscoveryParamsData } from '../../../modules/jobs-discovery/model/jobs-discovery.model'; import { AxiosResponse } from 'axios'; -import { WorkerRegistrationData } from '../../../modules/user-worker/model/worker-registration.model'; +import { RegistrationInExchangeOracleData } from '../../../modules/user-worker/model/worker-registration.model'; import { registerWorkerCommandFixture, registerWorkerDataFixture, @@ -252,8 +252,8 @@ describe('ExchangeOracleApiGateway', () => { }); }); - describe('registerWorker', () => { - it('should successfully call register worker', async () => { + describe('register', () => { + it('should successfully call register in exchange oracle', async () => { jest.spyOn(httpService, 'request').mockReturnValue( of({ data: responseWorkerFixture, @@ -264,15 +264,15 @@ describe('ExchangeOracleApiGateway', () => { } as AxiosResponse), ); const command = registerWorkerCommandFixture; - const expectedMappedData: WorkerRegistrationData = + const expectedMappedData: RegistrationInExchangeOracleData = registerWorkerDataFixture; nock(workerRegisterUrl) - .post(`/registration`) + .post(`/register`) .reply(200, responseWorkerFixture); - await gateway.workerRegistration(command); + await gateway.sendRegistrationInExchangeOracle(command); expect(httpService.request).toHaveBeenCalledWith( expect.objectContaining({ - url: EXCHANGE_ORACLE_URL + '/registration', + url: EXCHANGE_ORACLE_URL + '/register', method: HttpMethod.POST, data: expectedMappedData, headers: { diff --git a/packages/apps/human-app/server/src/integrations/reputation-oracle/reputation-oracle.gateway.ts b/packages/apps/human-app/server/src/integrations/reputation-oracle/reputation-oracle.gateway.ts index f6a0f3d67e..ad6f09bb7b 100644 --- a/packages/apps/human-app/server/src/integrations/reputation-oracle/reputation-oracle.gateway.ts +++ b/packages/apps/human-app/server/src/integrations/reputation-oracle/reputation-oracle.gateway.ts @@ -4,12 +4,12 @@ import { lastValueFrom } from 'rxjs'; import { InjectMapper } from '@automapper/nestjs'; import { Mapper } from '@automapper/core'; import { - OraclesRegistrationResponse, - WorkerRegistrationCommand, - WorkerRegistrationData, - WorkerRegistrationResponse, + RegistrationInExchangeOraclesResponse, + RegistrationInExchangeOracleCommand, + RegistrationInExchangeOracleData, SignupWorkerCommand, SignupWorkerData, + RegistrationInExchangeOracleResponse, } from '../../modules/user-worker/model/worker-registration.model'; import { SignupOperatorCommand, @@ -174,18 +174,20 @@ export class ReputationOracleGateway { return this.handleRequestToReputationOracle(options); } - async sendWorkerRegistration(command: WorkerRegistrationCommand) { + async sendRegistrationInExchangeOracle( + command: RegistrationInExchangeOracleCommand, + ) { const data = this.mapper.map( command, - WorkerRegistrationCommand, - WorkerRegistrationData, + RegistrationInExchangeOracleCommand, + RegistrationInExchangeOracleData, ); const options = this.getEndpointOptions( - ReputationOracleEndpoints.WORKER_REGISTRATION, + ReputationOracleEndpoints.REGISTRATION_IN_EXCHANGE_ORACLE, data, command.token, ); - return this.handleRequestToReputationOracle( + return this.handleRequestToReputationOracle( options, ); } @@ -336,15 +338,15 @@ export class ReputationOracleGateway { return this.handleRequestToReputationOracle(options); } - async getRegisteredOracles( + async getRegistrationInExchangeOracles( token: string, - ): Promise { + ): Promise { const options = this.getEndpointOptions( - ReputationOracleEndpoints.GET_REGISTERED_ORACLES, + ReputationOracleEndpoints.GET_REGISTRATION_IN_EXCHANGE_ORACLES, undefined, token, ); - return this.handleRequestToReputationOracle( + return this.handleRequestToReputationOracle( options, ); } diff --git a/packages/apps/human-app/server/src/integrations/reputation-oracle/reputation-oracle.mapper.profile.ts b/packages/apps/human-app/server/src/integrations/reputation-oracle/reputation-oracle.mapper.profile.ts index dcd19db6d3..000f361747 100644 --- a/packages/apps/human-app/server/src/integrations/reputation-oracle/reputation-oracle.mapper.profile.ts +++ b/packages/apps/human-app/server/src/integrations/reputation-oracle/reputation-oracle.mapper.profile.ts @@ -12,8 +12,8 @@ import { SignupOperatorData, } from '../../modules/user-operator/model/operator-registration.model'; import { - WorkerRegistrationCommand, - WorkerRegistrationData, + RegistrationInExchangeOracleCommand, + RegistrationInExchangeOracleData, SignupWorkerCommand, SignupWorkerData, } from '../../modules/user-worker/model/worker-registration.model'; @@ -68,8 +68,8 @@ export class ReputationOracleProfile extends AutomapperProfile { return (mapper: Mapper) => { createMap( mapper, - WorkerRegistrationCommand, - WorkerRegistrationData, + RegistrationInExchangeOracleCommand, + RegistrationInExchangeOracleData, namingConventions({ source: new CamelCaseNamingConvention(), destination: new SnakeCaseNamingConvention(), diff --git a/packages/apps/human-app/server/src/integrations/reputation-oracle/spec/reputation-oracle.gateway.mock.ts b/packages/apps/human-app/server/src/integrations/reputation-oracle/spec/reputation-oracle.gateway.mock.ts index 4137579dd4..25ef51ff87 100644 --- a/packages/apps/human-app/server/src/integrations/reputation-oracle/spec/reputation-oracle.gateway.mock.ts +++ b/packages/apps/human-app/server/src/integrations/reputation-oracle/spec/reputation-oracle.gateway.mock.ts @@ -2,7 +2,7 @@ export const reputationOracleGatewayMock = { sendWorkerSignup: jest.fn(), sendOperatorSignup: jest.fn(), sendWorkerSignin: jest.fn(), - sendWorkerRegistration: jest.fn(), + sendRegistrationInExchangeOracle: jest.fn(), sendEmailVerification: jest.fn(), sendResendEmailVerification: jest.fn(), sendForgotPassword: jest.fn(), diff --git a/packages/apps/human-app/server/src/integrations/reputation-oracle/spec/reputation-oracle.gateway.spec.ts b/packages/apps/human-app/server/src/integrations/reputation-oracle/spec/reputation-oracle.gateway.spec.ts index c3d4eb7e80..6c4f214a4f 100644 --- a/packages/apps/human-app/server/src/integrations/reputation-oracle/spec/reputation-oracle.gateway.spec.ts +++ b/packages/apps/human-app/server/src/integrations/reputation-oracle/spec/reputation-oracle.gateway.spec.ts @@ -12,7 +12,7 @@ import { classes } from '@automapper/classes'; import { ReputationOracleProfile } from '../reputation-oracle.mapper.profile'; import { gatewayConfigServiceMock } from '../../../common/config/spec/gateway-config-service.mock'; import { - WorkerRegistrationCommand, + RegistrationInExchangeOracleCommand, SignupWorkerCommand, } from '../../../modules/user-worker/model/worker-registration.model'; import { SignupOperatorCommand } from '../../../modules/user-operator/model/operator-registration.model'; @@ -177,21 +177,24 @@ describe('ReputationOracleGateway', () => { }); }); - describe('sendWorkerRegistration', () => { - const command = new WorkerRegistrationCommand('0x34df642', 'hcaptchaToken'); + describe('sendRegistrationInExchangeOracle', () => { + const command = new RegistrationInExchangeOracleCommand( + '0x34df642', + 'hcaptchaToken', + ); const expectedData = { oracle_address: '0x34df642', }; - it('should successfully call the reputation oracle worker registration endpoint', async () => { + it('should successfully call the reputation oracle exchange oracle registration endpoint', async () => { nock('https://example.com') - .post('/user/registration', expectedData) + .post('/user/exchange-oracle-registration', expectedData) .reply(201, ''); httpServiceMock.request.mockReturnValue(of({})); await expect( - service.sendWorkerRegistration(command), + service.sendRegistrationInExchangeOracle(command), ).resolves.not.toThrow(); expect(httpService.request).toHaveBeenCalled(); }); @@ -209,8 +212,13 @@ describe('ReputationOracleGateway', () => { ), ); - const command = new WorkerRegistrationCommand('', 'hcaptchaToken'); - await expect(service.sendWorkerRegistration(command)).rejects.toThrow( + const command = new RegistrationInExchangeOracleCommand( + '', + 'hcaptchaToken', + ); + await expect( + service.sendRegistrationInExchangeOracle(command), + ).rejects.toThrow( new HttpException({ message: 'Bad request' }, HttpStatus.BAD_REQUEST), ); }); @@ -220,7 +228,9 @@ describe('ReputationOracleGateway', () => { .spyOn(httpService, 'request') .mockReturnValue(throwError(() => new Error('Internal Server Error'))); - await expect(service.sendWorkerRegistration(command)).rejects.toThrow( + await expect( + service.sendRegistrationInExchangeOracle(command), + ).rejects.toThrow( new HttpException( 'Internal Server Error', HttpStatus.INTERNAL_SERVER_ERROR, diff --git a/packages/apps/human-app/server/src/modules/user-worker/model/worker-registration.model.ts b/packages/apps/human-app/server/src/modules/user-worker/model/worker-registration.model.ts index e13d90bfab..1bd5911acc 100644 --- a/packages/apps/human-app/server/src/modules/user-worker/model/worker-registration.model.ts +++ b/packages/apps/human-app/server/src/modules/user-worker/model/worker-registration.model.ts @@ -42,7 +42,7 @@ export class SignupWorkerData { h_captcha_token: string; } -export class WorkerRegistrationDto { +export class RegistrationInExchangeOracleDto { @AutoMap() @ApiProperty({ example: 'string' }) @IsEthereumAddress() @@ -53,7 +53,7 @@ export class WorkerRegistrationDto { h_captcha_token: string; } -export class WorkerRegistrationCommand { +export class RegistrationInExchangeOracleCommand { @AutoMap() oracleAddress: string; @AutoMap() @@ -69,18 +69,17 @@ export class WorkerRegistrationCommand { } } -export class WorkerRegistrationData { +export class RegistrationInExchangeOracleData { @AutoMap() oracle_address: string; @AutoMap() h_captcha_token: string; } -export class WorkerRegistrationResponse { - email: string; - wallet_address: string; +export class RegistrationInExchangeOracleResponse { + oracle_address: string; } -export class OraclesRegistrationResponse { +export class RegistrationInExchangeOraclesResponse { oracle_addresses: string[]; } diff --git a/packages/apps/human-app/server/src/modules/user-worker/spec/worker.controller.spec.ts b/packages/apps/human-app/server/src/modules/user-worker/spec/worker.controller.spec.ts index bcb65c150c..1d2b71caab 100644 --- a/packages/apps/human-app/server/src/modules/user-worker/spec/worker.controller.spec.ts +++ b/packages/apps/human-app/server/src/modules/user-worker/spec/worker.controller.spec.ts @@ -1,7 +1,7 @@ import { WorkerController } from '../worker.controller'; import { WorkerService } from '../worker.service'; import { - WorkerRegistrationDto, + RegistrationInExchangeOracleDto, SignupWorkerCommand, SignupWorkerDto, } from '../model/worker-registration.model'; @@ -73,19 +73,19 @@ describe('WorkerController', () => { }); }); - describe('register', () => { - it('should service a user register method with proper fields set', async () => { - const dto: WorkerRegistrationDto = { + describe('exchange oracle registration', () => { + it('should service a user registration in exchange oracle method with proper fields set', async () => { + const dto: RegistrationInExchangeOracleDto = { oracle_address: '0x34df642', h_captcha_token: 'h_captcha_token', }; - await controller.workerRegistration(dto, workerToken); + await controller.createRegistrationInExchangeOracle(dto, workerToken); const expectedCommand = { oracleAddress: dto.oracle_address, hCaptchaToken: dto.h_captcha_token, token: workerToken, }; - expect(workerService.workerRegistration).toHaveBeenCalledWith( + expect(workerService.registrationInExchangeOracle).toHaveBeenCalledWith( expectedCommand, ); }); diff --git a/packages/apps/human-app/server/src/modules/user-worker/spec/worker.fixtures.ts b/packages/apps/human-app/server/src/modules/user-worker/spec/worker.fixtures.ts index c15c64a93b..3cba84d258 100644 --- a/packages/apps/human-app/server/src/modules/user-worker/spec/worker.fixtures.ts +++ b/packages/apps/human-app/server/src/modules/user-worker/spec/worker.fixtures.ts @@ -1,30 +1,29 @@ import { - WorkerRegistrationCommand, - WorkerRegistrationData, - WorkerRegistrationResponse, + RegistrationInExchangeOracleCommand, + RegistrationInExchangeOracleData, + RegistrationInExchangeOracleResponse, } from '../model/worker-registration.model'; const EXCHANGE_ORACLE_URL = 'https://www.test_url.org'; -const WALLER_ADDRESS = 'test_address'; -const EMAIL = 'test@email.test'; +const ORACLE_ADDRESS = 'test_address'; const TOKEN = 'test-token'; const HCAPTCHA_TOKEN = 'test-token'; const EXCHANGE_ORACLE_ADDRESS = '0x3dfa342'; export const exchangeOracleUrlFixture = EXCHANGE_ORACLE_URL; export const workerToken = TOKEN; -export const registerWorkerCommandFixture: WorkerRegistrationCommand = { - oracleAddress: EXCHANGE_ORACLE_ADDRESS, - hCaptchaToken: HCAPTCHA_TOKEN, - token: TOKEN, -}; +export const registerWorkerCommandFixture: RegistrationInExchangeOracleCommand = + { + oracleAddress: EXCHANGE_ORACLE_ADDRESS, + hCaptchaToken: HCAPTCHA_TOKEN, + token: TOKEN, + }; -export const registerWorkerDataFixture: WorkerRegistrationData = { +export const registerWorkerDataFixture: RegistrationInExchangeOracleData = { oracle_address: EXCHANGE_ORACLE_ADDRESS, h_captcha_token: HCAPTCHA_TOKEN, }; -export const responseWorkerFixture: WorkerRegistrationResponse = { - email: EMAIL, - wallet_address: WALLER_ADDRESS, +export const responseWorkerFixture: RegistrationInExchangeOracleResponse = { + oracle_address: ORACLE_ADDRESS, }; diff --git a/packages/apps/human-app/server/src/modules/user-worker/spec/worker.service.mock.ts b/packages/apps/human-app/server/src/modules/user-worker/spec/worker.service.mock.ts index d946e74ff7..d96824f1a1 100644 --- a/packages/apps/human-app/server/src/modules/user-worker/spec/worker.service.mock.ts +++ b/packages/apps/human-app/server/src/modules/user-worker/spec/worker.service.mock.ts @@ -1,5 +1,5 @@ export const workerServiceMock = { signupWorker: jest.fn(), signinWorker: jest.fn(), - workerRegistration: jest.fn(), + registrationInExchangeOracle: jest.fn(), }; diff --git a/packages/apps/human-app/server/src/modules/user-worker/spec/worker.service.spec.ts b/packages/apps/human-app/server/src/modules/user-worker/spec/worker.service.spec.ts index f9a4c5276e..1e39e5118e 100644 --- a/packages/apps/human-app/server/src/modules/user-worker/spec/worker.service.spec.ts +++ b/packages/apps/human-app/server/src/modules/user-worker/spec/worker.service.spec.ts @@ -62,16 +62,19 @@ describe('WorkerService', () => { }); }); - describe('registerWorker', () => { - it('should call reputation oracle gateway without doing anything else', async () => { + describe('registrationInExchangeOracle', () => { + it('should call exchange and reputation oracle gateway', async () => { const command = { oracleAddress: '0x34df642', hCaptchaToken: 'hcaptcha-token', token: 'test-token', }; - await service.workerRegistration(command); + await service.registrationInExchangeOracle(command); + expect( + exchangeOracleGatewayMock.sendRegistrationInExchangeOracle, + ).toHaveBeenCalledWith(command); expect( - reputationOracleGateway.sendWorkerRegistration, + reputationOracleGateway.sendRegistrationInExchangeOracle, ).toHaveBeenCalledWith(command); }); }); diff --git a/packages/apps/human-app/server/src/modules/user-worker/worker.controller.ts b/packages/apps/human-app/server/src/modules/user-worker/worker.controller.ts index e8c1f0f9c4..86ebfbebef 100644 --- a/packages/apps/human-app/server/src/modules/user-worker/worker.controller.ts +++ b/packages/apps/human-app/server/src/modules/user-worker/worker.controller.ts @@ -11,10 +11,10 @@ import { import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger'; import { Authorization } from '../../common/config/params-decorators'; import { - OraclesRegistrationResponse, - WorkerRegistrationCommand, - WorkerRegistrationDto, - WorkerRegistrationResponse, + RegistrationInExchangeOracleResponse, + RegistrationInExchangeOracleCommand, + RegistrationInExchangeOracleDto, + RegistrationInExchangeOraclesResponse, SignupWorkerCommand, SignupWorkerDto, } from './model/worker-registration.model'; @@ -59,30 +59,32 @@ export class WorkerController { } @ApiBearerAuth() - @Post('/registration') - @ApiOperation({ summary: 'Register a worker in Exchange Oracle' }) + @Post('/exchange-oracle-registration') + @ApiOperation({ summary: 'Registers a worker in Exchange Oracle' }) @UsePipes(new ValidationPipe()) - public workerRegistration( - @Body() workerRegistrationDto: WorkerRegistrationDto, + public createRegistrationInExchangeOracle( + @Body() registrationInExchangeOracleDto: RegistrationInExchangeOracleDto, @Authorization() token: string, - ): Promise { - const workerRegistrationCommand = this.mapper.map( - workerRegistrationDto, - WorkerRegistrationDto, - WorkerRegistrationCommand, + ): Promise { + const registrationInExchangeOracle = this.mapper.map( + registrationInExchangeOracleDto, + RegistrationInExchangeOracleDto, + RegistrationInExchangeOracleCommand, ); - workerRegistrationCommand.token = token; + registrationInExchangeOracle.token = token; - return this.service.workerRegistration(workerRegistrationCommand); + return this.service.registrationInExchangeOracle( + registrationInExchangeOracle, + ); } @ApiBearerAuth() - @Get('/registration') - @ApiOperation({ summary: 'Retrieve oracles registered by the worker' }) + @Get('/exchange-oracle-registration') + @ApiOperation({ summary: 'Retrieves oracles registered by the worker' }) @UsePipes(new ValidationPipe()) - public getRegisteredOracles( + public getRegistrationInExchangeOracles( @Authorization() token: string, - ): Promise { - return this.service.getRegisteredOracles(token); + ): Promise { + return this.service.getRegistrationInExchangeOracles(token); } } diff --git a/packages/apps/human-app/server/src/modules/user-worker/worker.mapper.profile.ts b/packages/apps/human-app/server/src/modules/user-worker/worker.mapper.profile.ts index 6c0078372f..e3ce1c94af 100644 --- a/packages/apps/human-app/server/src/modules/user-worker/worker.mapper.profile.ts +++ b/packages/apps/human-app/server/src/modules/user-worker/worker.mapper.profile.ts @@ -8,8 +8,8 @@ import { SnakeCaseNamingConvention, } from '@automapper/core'; import { - WorkerRegistrationCommand, - WorkerRegistrationDto, + RegistrationInExchangeOracleCommand, + RegistrationInExchangeOracleDto, SignupWorkerCommand, SignupWorkerDto, } from './model/worker-registration.model'; @@ -46,8 +46,8 @@ export class WorkerProfile extends AutomapperProfile { ); createMap( mapper, - WorkerRegistrationDto, - WorkerRegistrationCommand, + RegistrationInExchangeOracleDto, + RegistrationInExchangeOracleCommand, namingConventions({ source: new SnakeCaseNamingConvention(), destination: new CamelCaseNamingConvention(), diff --git a/packages/apps/human-app/server/src/modules/user-worker/worker.service.ts b/packages/apps/human-app/server/src/modules/user-worker/worker.service.ts index 422c43fcc2..e70996b698 100644 --- a/packages/apps/human-app/server/src/modules/user-worker/worker.service.ts +++ b/packages/apps/human-app/server/src/modules/user-worker/worker.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'; import { ReputationOracleGateway } from '../../integrations/reputation-oracle/reputation-oracle.gateway'; import { ExchangeOracleGateway } from '../../integrations/exchange-oracle/exchange-oracle.gateway'; import { - WorkerRegistrationCommand, + RegistrationInExchangeOracleCommand, SignupWorkerCommand, } from './model/worker-registration.model'; import { SigninWorkerCommand } from './model/worker-signin.model'; @@ -20,18 +20,18 @@ export class WorkerService { async signinWorker(signinWorkerCommand: SigninWorkerCommand) { return this.reputationOracleGateway.sendWorkerSignin(signinWorkerCommand); } - async workerRegistration( - workerRegistrationCommand: WorkerRegistrationCommand, + async registrationInExchangeOracle( + registrationInExchangeOracleCommand: RegistrationInExchangeOracleCommand, ) { - await this.exchangeOracleGateway.workerRegistration( - workerRegistrationCommand, + await this.exchangeOracleGateway.sendRegistrationInExchangeOracle( + registrationInExchangeOracleCommand, ); - return await this.reputationOracleGateway.sendWorkerRegistration( - workerRegistrationCommand, + return await this.reputationOracleGateway.sendRegistrationInExchangeOracle( + registrationInExchangeOracleCommand, ); } - async getRegisteredOracles(token: string) { - return this.reputationOracleGateway.getRegisteredOracles(token); + async getRegistrationInExchangeOracles(token: string) { + return this.reputationOracleGateway.getRegistrationInExchangeOracles(token); } } diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts index e586eb2f6a..4e2fe18bd0 100644 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts @@ -22,8 +22,9 @@ import { SignatureBodyDto, RegisterLabelerResponseDto, EnableOperatorDto, - OracleRegistrationDto, - RegisteredOraclesDto, + RegistrationInExchangeOracleDto, + RegistrationInExchangeOraclesDto, + RegistrationInExchangeOracleResponseDto, } from './user.dto'; import { JwtAuthGuard } from '../../common/guards'; import { RequestWithUser } from '../../common/types'; @@ -167,18 +168,18 @@ export class UserController { return await this.userService.prepareSignatureBody(data.type, data.address); } - @Post('/registration') + @Post('/exchange-oracle-registration') @HttpCode(200) @ApiOperation({ - summary: 'Register Oracle', + summary: 'Notifies registration in Exchange Oracle completed', description: - 'Initiates the registration process for an oracle with the provided details.', + 'Notifies that the registration process in a Exchange Oracle has been completed by the user.', }) - @ApiBody({ type: OracleRegistrationDto }) + @ApiBody({ type: RegistrationInExchangeOracleDto }) @ApiResponse({ status: 200, description: 'Oracle registered successfully', - type: OracleRegistrationDto, + type: RegistrationInExchangeOracleDto, }) @ApiResponse({ status: 400, @@ -188,36 +189,36 @@ export class UserController { status: 401, description: 'Unauthorized. Missing or invalid credentials.', }) - public async registerOracle( + public async registrationInExchangeOracle( @Req() request: RequestWithUser, - @Body() data: OracleRegistrationDto, - ): Promise { - await this.userService.registerOracle(request.user, data); - return data; + @Body() data: RegistrationInExchangeOracleDto, + ): Promise { + await this.userService.registrationInExchangeOracle(request.user, data); + + return { oracleAddress: data.oracleAddress }; } - @Get('/registration') + @Get('/exchange-oracle-registration') @HttpCode(200) @ApiOperation({ - summary: 'Retrieve oracles registered by the user', + summary: 'Retrieves Exchange Oracles the user is registered in', description: - 'Fetches the list of oracles where the user has completed the registration process.', + 'Fetches the list of Exchange Oracles where the user has completed the registration process.', }) @ApiResponse({ status: 200, description: 'List of registered oracles retrieved successfully', - type: RegisteredOraclesDto, + type: RegistrationInExchangeOraclesDto, }) @ApiResponse({ status: 401, description: 'Unauthorized. Missing or invalid credentials.', }) - public async getRegisteredOracles( + public async getRegistrationInExchangeOracles( @Req() request: RequestWithUser, - ): Promise { - const oracleAddresses = await this.userService.getRegisteredOracles( - request.user, - ); + ): Promise { + const oracleAddresses = + await this.userService.getRegistrationInExchangeOracles(request.user); return { oracleAddresses }; } } diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.dto.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.dto.ts index b7963583f8..8ea95615f6 100644 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.dto.ts +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.dto.ts @@ -110,7 +110,7 @@ export class PrepareSignatureDto { public type: SignatureType; } -export class OracleRegistrationDto { +export class RegistrationInExchangeOracleDto { @ApiProperty({ name: 'oracle_address', description: 'Ethereum address of the oracle', @@ -123,6 +123,10 @@ export class OracleRegistrationDto { public hCaptchaToken: string; } -export class RegisteredOraclesDto { +export class RegistrationInExchangeOracleResponseDto { + public oracleAddress: string; +} + +export class RegistrationInExchangeOraclesDto { public oracleAddresses: string[]; } diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.service.spec.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.service.spec.ts index 2839ba3a6c..8eb07b4f08 100644 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.service.spec.ts +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.service.spec.ts @@ -2,7 +2,7 @@ import { Test } from '@nestjs/testing'; import { createMock } from '@golevelup/ts-jest'; import { UserRepository } from './user.repository'; import { UserService } from './user.service'; -import { OracleRegistrationDto, UserCreateDto } from './user.dto'; +import { RegistrationInExchangeOracleDto, UserCreateDto } from './user.dto'; import { UserEntity } from './user.entity'; import { KycStatus, @@ -812,14 +812,14 @@ describe('UserService', () => { }); }); - describe('registerOracle', () => { - it('should register a new oracle for the user', async () => { + describe('registrationInExchangeOracle', () => { + it('should register a new registration in a Exchange Oracle for the user', async () => { const userEntity: DeepPartial = { id: 1, email: 'test@example.com', }; - const oracleRegistration: OracleRegistrationDto = { + const oracleRegistration: RegistrationInExchangeOracleDto = { oracleAddress: '0xOracleAddress', hCaptchaToken: 'hcaptcha-token', }; @@ -839,7 +839,7 @@ describe('UserService', () => { .spyOn(siteKeyRepository, 'createUnique') .mockResolvedValueOnce(siteKeyMock as SiteKeyEntity); - const result = await userService.registerOracle( + const result = await userService.registrationInExchangeOracle( userEntity as UserEntity, oracleRegistration, ); @@ -861,7 +861,7 @@ describe('UserService', () => { email: 'test@example.com', }; - const oracleRegistration: OracleRegistrationDto = { + const oracleRegistration: RegistrationInExchangeOracleDto = { oracleAddress: '0xOracleAddress', hCaptchaToken: 'hcaptcha-token', }; @@ -878,7 +878,7 @@ describe('UserService', () => { .spyOn(siteKeyRepository, 'findByUserSiteKeyAndType') .mockResolvedValueOnce(siteKeyMock as SiteKeyEntity); - const result = await userService.registerOracle( + const result = await userService.registrationInExchangeOracle( userEntity as UserEntity, oracleRegistration, ); @@ -894,7 +894,7 @@ describe('UserService', () => { email: 'test@example.com', }; - const oracleRegistration: OracleRegistrationDto = { + const oracleRegistration: RegistrationInExchangeOracleDto = { oracleAddress: '0xOracleAddress', hCaptchaToken: 'hcaptcha-token', }; @@ -904,7 +904,7 @@ describe('UserService', () => { .mockResolvedValueOnce({ success: false }); await expect( - userService.registerOracle( + userService.registrationInExchangeOracle( userEntity as UserEntity, oracleRegistration, ), @@ -930,7 +930,7 @@ describe('UserService', () => { .spyOn(siteKeyRepository, 'findByUserAndType') .mockResolvedValue(siteKeys); - const result = await userService.getRegisteredOracles( + const result = await userService.getRegistrationInExchangeOracles( userEntity as UserEntity, ); diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts index c442043ff4..1ab9ecd456 100644 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts @@ -19,7 +19,7 @@ import { import { generateNonce, verifySignature } from '../../common/utils/signature'; import { UserEntity } from './user.entity'; import { - OracleRegistrationDto, + RegistrationInExchangeOracleDto, RegisterAddressRequestDto, SignatureBodyDto, UserCreateDto, @@ -373,9 +373,9 @@ export class UserService { }; } - public async registerOracle( + public async registrationInExchangeOracle( user: UserEntity, - data: OracleRegistrationDto, + data: RegistrationInExchangeOracleDto, ): Promise { if ( !data.hCaptchaToken || @@ -402,7 +402,9 @@ export class UserService { return await this.siteKeyRepository.createUnique(newSiteKey); } - public async getRegisteredOracles(user: UserEntity): Promise { + public async getRegistrationInExchangeOracles( + user: UserEntity, + ): Promise { const siteKeys = await this.siteKeyRepository.findByUserAndType( user, SiteKeyType.REGISTRATION,