forked from humanprotocol/human-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…Oracles-discovery
- Loading branch information
Showing
13 changed files
with
582 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/apps/human-app/server/src/common/enums/job-assignment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export enum StatusEnum { | ||
ACTIVE = 'ACTIVE', | ||
VALIDATION = 'VALIDATION', | ||
COMPLETED = 'COMPLETED', | ||
EXPIRED = 'EXPIRED', | ||
CANCELED = 'CANCELED', | ||
REJECTED = 'REJECTED', | ||
} | ||
|
||
export enum SortOrder { | ||
ASC = 'ASC', | ||
DESC = 'DESC', | ||
} | ||
|
||
export enum SortField { | ||
CHAIN_ID = 'chain_id', | ||
JOB_TYPE = 'job_type', | ||
STATUS = 'status', | ||
REWARD_AMOUNT = 'reward_amount', | ||
CREATED_AT = 'created_at', | ||
EXPIRES_AT = 'expires_at', | ||
} |
159 changes: 159 additions & 0 deletions
159
...s/apps/human-app/server/src/modules/job-assignment/interfaces/job-assignment.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { AutoMap } from '@automapper/classes'; | ||
import { | ||
SortField, | ||
SortOrder, | ||
StatusEnum, | ||
} from '../../../common/enums/job-assignment'; | ||
|
||
export class JobAssignmentDto { | ||
@AutoMap() | ||
@ApiProperty({ example: 'string' }) | ||
exchange_oracle_url: string; | ||
|
||
@AutoMap() | ||
@ApiProperty({ example: 'string' }) | ||
escrow_address: string; | ||
|
||
@AutoMap() | ||
@ApiProperty({ example: 0 }) | ||
chain_id: number; | ||
} | ||
|
||
export class JobAssignmentCommand { | ||
@AutoMap() | ||
exchange_oracle_url: string; | ||
@AutoMap() | ||
escrow_address: string; | ||
@AutoMap() | ||
chain_id: number; | ||
} | ||
|
||
export class JobAssignmentData { | ||
@AutoMap() | ||
exchange_oracle_url: string; | ||
@AutoMap() | ||
escrow_address: string; | ||
@AutoMap() | ||
chain_id: number; | ||
} | ||
|
||
export class JobAssignmentResponse { | ||
assignment_id: string; | ||
escrow_address: string; | ||
chain_id: number; | ||
job_type: string; | ||
url?: string; //Only for ACTIVE status | ||
status: string; | ||
reward_amount: string; | ||
reward_token: string; | ||
created_at: string; | ||
updated_at?: string; //Only for COMPLETED, EXPIRED, CANCELED and REJECTED status | ||
expires_at: string; | ||
} | ||
|
||
export class JobsFetchParamsDto { | ||
@AutoMap() | ||
@ApiProperty({ example: 'string' }) | ||
exchange_oracle_url: string; | ||
|
||
@AutoMap() | ||
@ApiProperty({ example: 'string', required: false }) | ||
assignment_id: string; | ||
|
||
@AutoMap() | ||
@ApiProperty({ example: 'string', required: false }) | ||
escrow_address: string; | ||
|
||
@AutoMap() | ||
@ApiProperty({ example: 0, required: false }) | ||
chain_id: number; | ||
|
||
@AutoMap() | ||
@ApiProperty({ example: 'job type', required: false }) | ||
job_type: string; | ||
|
||
@AutoMap() | ||
@ApiProperty({ example: 'ACTIVE', required: false }) | ||
status: StatusEnum; | ||
|
||
@AutoMap() | ||
@ApiProperty({ example: 5, default: 5, maximum: 10, required: false }) | ||
page_size: number; | ||
|
||
@AutoMap() | ||
@ApiProperty({ example: 0, default: 0, required: false }) | ||
page: number; | ||
|
||
@AutoMap() | ||
@ApiProperty({ example: 'ASC', default: 'ASC', required: false }) | ||
sort: SortOrder; | ||
|
||
@AutoMap() | ||
@ApiProperty({ example: 'created_at', default: 'created_at', required: false }) | ||
sort_field: SortField; | ||
} | ||
|
||
export class JobsFetchParamsCommand { | ||
@AutoMap() | ||
exchange_oracle_url: string; | ||
@AutoMap() | ||
assignment_id: string; | ||
@AutoMap() | ||
escrow_address: string; | ||
@AutoMap() | ||
chain_id: number; | ||
@AutoMap() | ||
job_type: string; | ||
@AutoMap() | ||
status: StatusEnum; | ||
@AutoMap() | ||
page_size: number; | ||
@AutoMap() | ||
page: number; | ||
@AutoMap() | ||
sort: SortOrder; | ||
@AutoMap() | ||
sort_field: SortField; | ||
} | ||
|
||
export class JobsFetchParamsData { | ||
@AutoMap() | ||
exchange_oracle_url: string; | ||
@AutoMap() | ||
assignment_id: string; | ||
@AutoMap() | ||
escrow_address: string; | ||
@AutoMap() | ||
chain_id: number; | ||
@AutoMap() | ||
job_type: string; | ||
@AutoMap() | ||
status: StatusEnum; | ||
@AutoMap() | ||
page_size: number; | ||
@AutoMap() | ||
page: number; | ||
@AutoMap() | ||
sort: SortOrder; | ||
@AutoMap() | ||
sort_field: SortField; | ||
} | ||
|
||
export class JobsFetchResponseItem { | ||
assignment_id: string; | ||
escrow_address: string; | ||
chain_id: number; | ||
job_type: string; | ||
url?: string; //Only for ACTIVE status | ||
status: string; | ||
reward_amount: string; | ||
reward_token: string; | ||
created_at: string; | ||
updated_at: string; //Only for VALIDATION, COMPLETED, EXPIRED, CANCELED and REJECTED status | ||
expires_at: string; | ||
} | ||
|
||
export class JobsFetchResponse { | ||
data: JobsFetchResponseItem[]; | ||
} |
64 changes: 64 additions & 0 deletions
64
packages/apps/human-app/server/src/modules/job-assignment/job-assignment.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Get, | ||
Post, | ||
Query, | ||
UsePipes, | ||
ValidationPipe, | ||
} from '@nestjs/common'; | ||
import { ApiOperation, ApiTags } from '@nestjs/swagger'; | ||
import { InjectMapper } from '@automapper/nestjs'; | ||
import { Mapper } from '@automapper/core'; | ||
import { JobAssignmentService } from './job-assignment.service'; | ||
import { | ||
JobAssignmentDto, | ||
JobAssignmentCommand, | ||
JobAssignmentResponse, | ||
JobsFetchParamsDto, | ||
JobsFetchParamsCommand, | ||
JobsFetchResponse, | ||
} from './interfaces/job-assignment.interface'; | ||
|
||
@Controller() | ||
export class JobAssignmentController { | ||
constructor( | ||
private readonly jobAssignmentService: JobAssignmentService, | ||
@InjectMapper() private readonly mapper: Mapper, | ||
) {} | ||
|
||
@ApiTags('Job-Assignment') | ||
@Post('/assignment/job') | ||
@ApiOperation({ | ||
summary: 'Request to assign a job to a logged user', | ||
}) | ||
@UsePipes(new ValidationPipe()) | ||
public async assignJob( | ||
@Body() jobAssignmentDto: JobAssignmentDto, | ||
): Promise<JobAssignmentResponse> { | ||
const jobAssignmentCommand = this.mapper.map( | ||
jobAssignmentDto, | ||
JobAssignmentDto, | ||
JobAssignmentCommand, | ||
); | ||
return this.jobAssignmentService.processJobAssignment(jobAssignmentCommand); | ||
} | ||
|
||
@ApiTags('Job-Assignment') | ||
@Get('/assignment/job') | ||
@ApiOperation({ | ||
summary: 'Request to get a jobs assigned to a logged user', | ||
}) | ||
public async getAssignedJobs( | ||
@Query() jobsAssignmentParamsDto: JobsFetchParamsDto, | ||
): Promise<JobsFetchResponse> { | ||
const jobsAssignmentParamsCommand = this.mapper.map( | ||
jobsAssignmentParamsDto, | ||
JobsFetchParamsDto, | ||
JobsFetchParamsCommand, | ||
); | ||
return this.jobAssignmentService.processGetAssignedJobs( | ||
jobsAssignmentParamsCommand, | ||
); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/apps/human-app/server/src/modules/job-assignment/job-assignment.mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { AutomapperProfile, InjectMapper } from '@automapper/nestjs'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { createMap, Mapper } from '@automapper/core'; | ||
import { | ||
JobAssignmentCommand, | ||
JobAssignmentData, | ||
JobAssignmentDto, | ||
JobsFetchParamsCommand, | ||
JobsFetchParamsData, | ||
JobsFetchParamsDto, | ||
} from './interfaces/job-assignment.interface'; | ||
|
||
@Injectable() | ||
export class JobAssignmentProfile extends AutomapperProfile { | ||
constructor(@InjectMapper() mapper: Mapper) { | ||
super(mapper); | ||
} | ||
|
||
override get profile() { | ||
return (mapper: Mapper) => { | ||
createMap(mapper, JobAssignmentDto, JobAssignmentCommand); | ||
createMap(mapper, JobAssignmentCommand, JobAssignmentData); | ||
createMap(mapper, JobsFetchParamsDto, JobsFetchParamsCommand); | ||
createMap(mapper, JobsFetchParamsCommand, JobsFetchParamsData); | ||
}; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/apps/human-app/server/src/modules/job-assignment/job-assignment.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { JobAssignmentService } from './job-assignment.service'; | ||
import { JobAssignmentProfile } from './job-assignment.mapper'; | ||
import { HttpModule } from '@nestjs/axios'; | ||
|
||
@Module({ | ||
imports: [HttpModule], | ||
providers: [JobAssignmentService, JobAssignmentProfile], | ||
exports: [JobAssignmentService], | ||
}) | ||
export class JobAssignmentModule {} |
Oops, something went wrong.