Skip to content
Open
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
9 changes: 5 additions & 4 deletions src/escrow/dto/fund-escrow.dto.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
IsDateString,
IsISO8601,
IsOptional,
IsString,
IsUUID,
Matches,
MaxLength,
} from 'class-validator';
import { AssetType } from '../../common/enums';
import { IsFutureDate } from '../../common/validators/date.validator';
import {
IsMoneyAmount,
IsSupportedEscrowAsset,
Expand Down Expand Up @@ -89,7 +90,7 @@ export class FundEscrowDto {
'ISO 8601 refund-deadline passed to escrow::fund (defaults to the configured window)',
})
@IsOptional()
@IsDateString()
@Type(() => Date)
deadline?: Date;
@IsISO8601()
@IsFutureDate()
deadline?: string;
}
7 changes: 6 additions & 1 deletion src/escrow/escrow.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ export class EscrowController {
@Idempotent('escrow.fund')
@Post('fund')
async fund(@Body() dto: FundEscrowDto) {
return toPublicEscrow(await this.escrowService.fund(dto));
return toPublicEscrow(
await this.escrowService.fund({
...dto,
deadline: dto.deadline ? new Date(dto.deadline) : null,
}),
);
}

@ApiOperation({ summary: 'Get an escrow by id' })
Expand Down
11 changes: 10 additions & 1 deletion src/milestones/milestones.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,14 @@ export class MilestonesService {
throw new BadRequestException(
`Milestone ${milestoneId} has not been funded yet`,
);
if (
milestone.status !== MilestoneStatus.FUNDED &&
milestone.status !== MilestoneStatus.IN_PROGRESS
) {
throw new BadRequestException(
`Milestone ${milestoneId} is not accepting distributions (status: ${milestone.status})`,
);
}
assertTransition(milestone.status, MilestoneStatus.IN_PROGRESS);

// Verify the issue belongs to this milestone (#114).
const issue = milestone.issues.find((i) => i.id === issueId);
Expand Down Expand Up @@ -224,6 +230,9 @@ export class MilestonesService {
Number(newDistributed) >= Number(locked.budget) - 1e-7
? MilestoneStatus.COMPLETED
: MilestoneStatus.IN_PROGRESS;
if (newStatus !== locked.status) {
assertTransition(locked.status, newStatus);
}
await mgr.update(Milestone, milestoneId, {
distributed: newDistributed,
status: newStatus,
Expand Down
4 changes: 0 additions & 4 deletions src/reputation/reputation.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ export class ReputationController {
@Get(':userId')
latest(
@Param('userId', new ParseUUIDPipe()) userId: string,
@CurrentUser() user: AuthenticatedUser,
) {
this.assertOwner(user, userId);
return this.reputationService.getLatest(userId);
}

Expand All @@ -66,11 +64,9 @@ export class ReputationController {
@ApiQuery({ name: 'offset', required: false })
history(
@Param('userId', new ParseUUIDPipe()) userId: string,
@CurrentUser() user: AuthenticatedUser,
@Query('limit') limit?: string,
@Query('offset') offset?: string,
) {
this.assertOwner(user, userId);
return this.reputationService.history(userId, {
limit: parseOptionalInt(limit),
offset: parseOptionalInt(offset),
Expand Down
14 changes: 11 additions & 3 deletions src/reputation/reputation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export const REPUTATION_HISTORY_MAX_LIMIT = 100;
export interface ReputationHistoryOptions {
limit?: number;
offset?: number;
order?: 'ASC' | 'DESC';
}

export interface ReputationHistoryResult {
items: ReputationSnapshot[];
total: number;
}

@Injectable()
Expand Down Expand Up @@ -57,17 +63,19 @@ export class ReputationService {
async history(
userId: string,
options: ReputationHistoryOptions = {},
): Promise<ReputationSnapshot[]> {
): Promise<ReputationHistoryResult> {
const limit = Math.min(
Math.max(options.limit ?? REPUTATION_HISTORY_DEFAULT_LIMIT, 1),
REPUTATION_HISTORY_MAX_LIMIT,
);
const offset = Math.max(options.offset ?? 0, 0);
return this.snapshotRepo.find({
const order = options.order ?? 'DESC';
const [items, total] = await this.snapshotRepo.findAndCount({
where: { userId },
order: { computedAt: 'ASC' },
order: { computedAt: order },
take: limit,
skip: offset,
});
return { items, total };
}
}