Skip to content
Merged
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
14 changes: 14 additions & 0 deletions src/namespace-resources/namespace-resources.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ export class NamespaceResourcesController {
});
}

@Get('recent')
async recent(
@UserId() userId: string,
@Param('namespaceId') namespaceId: string,
@Query('limit') limit?: string,
): Promise<ResourceMetaDto[]> {
const take = Number.isFinite(Number(limit)) ? Number(limit) : 10;
return await this.namespaceResourcesService.recent(
namespaceId,
userId,
take,
);
}

@Get(':resourceId')
async get(
@UserId() userId: string,
Expand Down
21 changes: 21 additions & 0 deletions src/namespace-resources/namespace-resources.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,27 @@ export class NamespaceResourcesService {
return filteredResources.map((res) => ResourceMetaDto.fromEntity(res));
}

async recent(
namespaceId: string,
userId: string,
limit: number = 10,
): Promise<ResourceMetaDto[]> {
const allVisible = await this.getUserVisibleResources(userId, namespaceId);
const sorted = allVisible
.filter((r) => r.parentId !== null)
.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
const take = Math.max(1, Math.min(100, limit));
return sorted.slice(0, take);
}

// Alias for clarity and reuse across modules
async getUserVisibleResources(
userId: string,
namespaceId: string,
): Promise<ResourceMetaDto[]> {
return await this.getAllResourcesByUser(userId, namespaceId);
}

async getSubResourcesByUser(
userId: string,
namespaceId: string,
Expand Down
1 change: 0 additions & 1 deletion src/namespaces/namespaces.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { InjectRepository } from '@nestjs/typeorm';
import { Namespace } from './entities/namespace.entity';
import { Resource } from 'omniboxd/resources/entities/resource.entity';
import { UpdateNamespaceDto } from './dto/update-namespace.dto';
import { NamespaceMemberDto } from './dto/namespace-member.dto';
import { GroupUser } from 'omniboxd/groups/entities/group-user.entity';
Expand Down