Skip to content

Commit 98dcb51

Browse files
committed
refactor(share): add namespace name
1 parent a93ac00 commit 98dcb51

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/shared-resources/dto/public-share-info.dto.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
1-
import { Share } from 'omniboxd/shares/entities/share.entity';
1+
import { Expose } from 'class-transformer';
2+
import { Share, ShareType } from 'omniboxd/shares/entities/share.entity';
23
import { SharedResourceMetaDto } from './shared-resource-meta.dto';
34

45
export class PublicShareInfoDto {
6+
@Expose()
57
id: string;
8+
9+
@Expose({ name: 'all_resources' })
610
allResources: boolean;
11+
12+
@Expose({ name: 'share_type' })
13+
shareType: ShareType;
14+
15+
@Expose({ name: 'namespace_name' })
16+
namespaceName: string;
17+
18+
@Expose()
719
resource: SharedResourceMetaDto;
820

921
static fromResourceMeta(
1022
share: Share,
1123
resource: SharedResourceMetaDto,
24+
namespaceName: string,
1225
): PublicShareInfoDto {
1326
const dto = new PublicShareInfoDto();
1427
dto.id = share.id;
1528
dto.allResources = share.allResources;
29+
dto.shareType = share.shareType;
30+
dto.namespaceName = namespaceName;
1631
dto.resource = resource;
1732
return dto;
1833
}

src/shares/shares.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import {
77
ResourceSharesController,
88
} from './shares.controller';
99
import { ResourcesModule } from 'omniboxd/resources/resources.module';
10+
import { NamespacesModule } from 'omniboxd/namespaces/namespaces.module';
1011

1112
@Module({
12-
imports: [TypeOrmModule.forFeature([Share]), ResourcesModule],
13+
imports: [TypeOrmModule.forFeature([Share]), ResourcesModule, NamespacesModule],
1314
providers: [SharesService],
1415
exports: [SharesService],
1516
controllers: [ResourceSharesController, PublicSharesController],

src/shares/shares.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ import { UpdateShareInfoReqDto } from './dto/update-share-info-req.dto';
1313
import { PublicShareInfoDto } from 'omniboxd/shared-resources/dto/public-share-info.dto';
1414
import { ResourcesService } from 'omniboxd/resources/resources.service';
1515
import { SharedResourceMetaDto } from 'omniboxd/shared-resources/dto/shared-resource-meta.dto';
16+
import { NamespacesService } from 'omniboxd/namespaces/namespaces.service';
1617

1718
@Injectable()
1819
export class SharesService {
1920
constructor(
2021
@InjectRepository(Share)
2122
private readonly shareRepo: Repository<Share>,
2223
private readonly resourcesService: ResourcesService,
24+
private readonly namespacesService: NamespacesService,
2325
) {}
2426

2527
async getShareById(shareId: string): Promise<Share | null> {
@@ -69,6 +71,7 @@ export class SharesService {
6971
if (!resource) {
7072
throw new NotFoundException(`No share found with id ${share.id}`);
7173
}
74+
const namespace = await this.namespacesService.get(share.namespaceId);
7275
const subResources = await this.resourcesService.getSubResources(
7376
share.namespaceId,
7477
share.resourceId,
@@ -77,7 +80,7 @@ export class SharesService {
7780
resource,
7881
subResources.length > 0,
7982
);
80-
return PublicShareInfoDto.fromResourceMeta(share, resourceMeta);
83+
return PublicShareInfoDto.fromResourceMeta(share, resourceMeta, namespace.name);
8184
}
8285

8386
async getShareInfo(

0 commit comments

Comments
 (0)