Skip to content

Commit

Permalink
optimizm allocation.
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyyuan committed Dec 7, 2024
1 parent 32524cb commit f905b26
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 21 deletions.
21 changes: 17 additions & 4 deletions src/controller/allocation.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { CoreApiResponse } from '@core/api/coreApiResponse';
import {
AllocationListQuery,
CreateAllocationBody,
UpdateAllocationStatusBody,
} from '@core/type/doc/allocation';
import { Body, Controller, Inject, Param, Post, Put } from '@nestjs/common';
import {
Body,
Controller,
Get,
Inject,
Param,
Post,
Put,
Query,
} from '@nestjs/common';
import { AllocationService } from '@service/allocation.service';

@Controller('allocation')
Expand All @@ -13,12 +23,15 @@ export class AllocationController {
private readonly allocationService: AllocationService,
) {}

// @Get('list')
// async getAllocations(@Query() query: AllocationListQuery) {}
@Get('list')
async getAllocations(@Query() query: AllocationListQuery) {
const result = await this.allocationService.getAllocationList(query);
return CoreApiResponse.success(result);
}

@Post('create')
async createAllocation(@Body() body: CreateAllocationBody) {
const result = this.allocationService.create(body);
const result = await this.allocationService.create(body);
return CoreApiResponse.success(result);
}

Expand Down
4 changes: 2 additions & 2 deletions src/controller/pool.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class PoolController {

@Post('create')
async createPool(@Body() body: CreatePoolBody) {
const result = this.poolService.createPool(body);
const result = await this.poolService.createPool(body);
return CoreApiResponse.success(result);
}

Expand All @@ -35,7 +35,7 @@ export class PoolController {

@Post('claim')
async claim(@Body() body: ClaimBody) {
const result = this.poolService.contributorClaim(body);
const result = await this.poolService.contributorClaim(body);
return CoreApiResponse.success(result);
}
}
23 changes: 21 additions & 2 deletions src/core/service/allocation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,23 @@ import { PrismaService } from 'nestjs-prisma';
export class AllocationService {
constructor(private prisma: PrismaService) {}

async getAllocationList(query: AllocationListQuery) {}
async getAllocationList(query: AllocationListQuery) {
const { projectId } = query;
const project = await this.prisma.project.findFirst({
where: {
id: projectId,
},
});
if (!project) {
throw new HttpException(
Code.NOT_FOUND_ERROR.message,
Code.NOT_FOUND_ERROR.code,
);
}
return this.prisma.allocation.findMany({
where: { projectId, deleted: false },
});
}

async create(body: CreateAllocationBody) {
const { title, projectId, contributors, ratios, credits, operatorId } =
Expand Down Expand Up @@ -66,8 +82,11 @@ export class AllocationService {
}),
);
});
await this.prisma.$transaction(fns);

return this.prisma.$transaction(fns);
return {
id,
};
}

async updateAllocationState(
Expand Down
22 changes: 9 additions & 13 deletions src/core/type/doc/allocation.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { AuthBody } from '@core/type/doc/auth';
import { PaginateQuery } from '@core/type/doc/common';
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
ArrayNotEmpty,
IsArray,
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
} from 'class-validator';
Expand All @@ -17,17 +15,15 @@ export class AllocationListQuery extends PaginateQuery {
@ApiProperty({ type: 'string' })
projectId: string;

@IsOptional()
@IsNumber()
@Type(() => Number)
@ApiProperty({ type: 'number' })
dateFrom?: number;

@IsOptional()
@IsNumber()
@Type(() => Number)
@ApiProperty({ type: 'number' })
dateTo?: number;
// @IsOptional()
// @Type(() => Number)
// @ApiProperty({ type: 'number' })
// dateFrom?: number;
//
// @IsOptional()
// @Type(() => Number)
// @ApiProperty({ type: 'number' })
// dateTo?: number;
}

export class UpdateAllocationStatusBody extends AuthBody {
Expand Down

0 comments on commit f905b26

Please sign in to comment.