Skip to content

Commit 6949717

Browse files
authored
feat: updated resource integration - added product to the Resource model (#160)
* feat: updated resource integration - added product to the Resource model * feat: update getServiceList and getAssetList methods * feat: refactoring
1 parent fb98e38 commit 6949717

27 files changed

+717
-173
lines changed

.changeset/tricky-trams-stick.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@o2s/integrations.medusajs': minor
3+
'@o2s/integrations.mocked': minor
4+
'@o2s/api-harmonization': minor
5+
'@o2s/framework': minor
6+
---
7+
8+
feat: updated resource integration - added product to the Resource model
9+
10+
- updated service-list and service-details blocks,
11+
- added sorting and filters to mocks,

apps/api-harmonization/src/blocks/featured-service-list/featured-service-list.mapper.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ export const mapFeaturedServiceList = (
66
featuredServices: Products.Model.Products,
77
cms: CMS.Model.FeaturedServiceListBlock.FeaturedServiceListBlock,
88
): FeaturedServiceListBlock => {
9-
const services = featuredServices.data.slice(0, cms.pagination?.limit || 3).map((product) => mapProduct(product));
9+
const services = featuredServices.data
10+
.slice(0, cms.pagination?.limit || 3)
11+
.map((product) => mapProduct(product))
12+
.filter((service) => service !== undefined);
1013

1114
return {
1215
__typename: 'FeaturedServiceListBlock',
@@ -24,7 +27,11 @@ export const mapFeaturedServiceList = (
2427
};
2528
};
2629

27-
const mapProduct = (product: Products.Model.Product): FeaturedService => {
30+
const mapProduct = (product: Products.Model.Product): FeaturedService | undefined => {
31+
if (!product.id || !product.name) {
32+
return undefined;
33+
}
34+
2835
return {
2936
id: product.id,
3037
name: product.name,

apps/api-harmonization/src/blocks/featured-service-list/featured-service-list.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { HttpModule } from '@nestjs/axios';
12
import { DynamicModule, Module } from '@nestjs/common';
23

34
import { ApiConfig } from '@o2s/framework/modules';
@@ -13,6 +14,7 @@ export class FeaturedServiceListBlockModule {
1314
return {
1415
module: FeaturedServiceListBlockModule,
1516
providers: [FeaturedServiceListService, CMS.Service, Resources.Service],
17+
imports: [HttpModule],
1618
controllers: [FeaturedServiceListController],
1719
exports: [FeaturedServiceListService],
1820
};

apps/api-harmonization/src/blocks/service-details/service-details.mapper.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,47 @@
11
import { formatDateRelative } from '@o2s/api-harmonization/utils/date';
22

3-
import { CMS, Products, Resources } from '../../models';
3+
import { CMS, Resources } from '../../models';
44

55
import { Service, ServiceDetailsBlock } from './service-details.model';
66

77
export const mapServiceDetails = (
88
cms: CMS.Model.ServiceDetailsBlock.ServiceDetailsBlock,
99
service: Resources.Model.Service,
10-
product: Products.Model.Product,
1110
locale: string,
1211
timezone: string,
1312
): ServiceDetailsBlock => {
1413
return {
1514
__typename: 'ServiceDetailsBlock',
1615
id: cms.id,
17-
data: mapService(cms, service, product, locale, timezone),
16+
data: mapService(cms, service, locale, timezone),
1817
};
1918
};
2019

2120
export const mapService = (
2221
cms: CMS.Model.ServiceDetailsBlock.ServiceDetailsBlock,
2322
service: Resources.Model.Service,
24-
product: Products.Model.Product,
2523
locale: string,
2624
timezone: string,
2725
): Service => {
2826
return {
2927
price: {
3028
title: cms.properties?.price as string,
31-
value: product.price,
29+
value: service.product.price,
3230
},
3331
type: {
34-
label: cms.fields.type?.[product.type] || product.type,
32+
label: cms.fields.type?.[service.product.type] || service.product.type,
3533
title: cms.properties?.type as string,
36-
value: product.type,
34+
value: service.product.type,
3735
},
3836
status: {
3937
label: cms.fields.status?.[service.contract.status] || service.contract.status,
4038
title: cms.properties?.status as string,
4139
value: service.contract.status,
4240
},
4341
category: {
44-
label: cms.fields.category?.[product.category] || product.category,
42+
label: cms.fields.category?.[service.product.category] || service.product.category,
4543
title: cms.properties?.category as string,
46-
value: product.category,
44+
value: service.product.category,
4745
},
4846
startDate: {
4947
title: cms.properties?.startDate as string,
@@ -65,9 +63,9 @@ export const mapService = (
6563
timezone,
6664
),
6765
},
68-
name: product.name,
66+
name: service.product.name,
6967
details: cms.title,
70-
description: product.description,
68+
description: service.product.description,
7169
labels: {
7270
settings: cms.labels.settings,
7371
renew: cms.labels.renew,

apps/api-harmonization/src/blocks/service-details/service-details.model.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Products, Resources } from '../../models';
1+
import { Resources } from '../../models';
22
import { Block } from '../../utils';
33

44
export class ServiceDetailsBlock extends Block.Block {
@@ -9,12 +9,12 @@ export class ServiceDetailsBlock extends Block.Block {
99
export class Service {
1010
price!: {
1111
title: string;
12-
value: Products.Model.Product['price'];
12+
value: Resources.Model.Service['product']['price'];
1313
};
1414
type!: {
1515
label: string;
1616
title: string;
17-
value: Products.Model.Product['type'];
17+
value: Resources.Model.Service['product']['type'];
1818
};
1919
status!: {
2020
label: string;
@@ -24,7 +24,7 @@ export class Service {
2424
category!: {
2525
label: string;
2626
title: string;
27-
value: Products.Model.Product['category'];
27+
value: Resources.Model.Service['product']['category'];
2828
};
2929
startDate!: {
3030
title: string;

apps/api-harmonization/src/blocks/service-details/service-details.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DynamicModule, Module } from '@nestjs/common';
33

44
import { ApiConfig } from '@o2s/framework/modules';
55

6-
import { CMS, Products, Resources } from '../../models';
6+
import { CMS, Resources } from '../../models';
77

88
import { ServiceDetailsController } from './service-details.controller';
99
import { ServiceDetailsService } from './service-details.service';
@@ -13,7 +13,7 @@ export class ServiceDetailsBlockModule {
1313
static register(_config: ApiConfig): DynamicModule {
1414
return {
1515
module: ServiceDetailsBlockModule,
16-
providers: [ServiceDetailsService, CMS.Service, Resources.Service, Products.Service],
16+
providers: [ServiceDetailsService, CMS.Service, Resources.Service],
1717
controllers: [ServiceDetailsController],
1818
exports: [ServiceDetailsService],
1919
imports: [HttpModule],
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Injectable } from '@nestjs/common';
2-
import { Observable, concatMap, forkJoin, map } from 'rxjs';
2+
import { Observable, forkJoin, map } from 'rxjs';
33

44
import { AppHeaders } from '@o2s/api-harmonization/utils/headers';
55

6-
import { CMS, Products, Resources } from '../../models';
6+
import { CMS, Resources } from '../../models';
77

88
import { mapServiceDetails } from './service-details.mapper';
99
import { ServiceDetailsBlock } from './service-details.model';
@@ -14,7 +14,6 @@ export class ServiceDetailsService {
1414
constructor(
1515
private readonly cmsService: CMS.Service,
1616
private readonly resourceService: Resources.Service,
17-
private readonly productService: Products.Service,
1817
) {}
1918

2019
getServiceDetailsBlock(
@@ -26,21 +25,9 @@ export class ServiceDetailsService {
2625
const service = this.resourceService.getService({ ...params, locale: headers['x-locale'] });
2726

2827
return forkJoin([cms, service]).pipe(
29-
concatMap(([cms, service]) => {
30-
return this.productService
31-
.getProduct({ id: service.productId, locale: headers['x-locale'] })
32-
.pipe(
33-
map((products) =>
34-
mapServiceDetails(
35-
cms,
36-
service,
37-
products,
38-
headers['x-locale'],
39-
headers['x-client-timezone'] || '',
40-
),
41-
),
42-
);
43-
}),
28+
map(([cms, service]) =>
29+
mapServiceDetails(cms, service, headers['x-locale'], headers['x-client-timezone'] || ''),
30+
),
4431
);
4532
}
4633
}

apps/api-harmonization/src/blocks/service-list/service-list.mapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import format from 'string-template';
22

33
import { formatDateRelative } from '@o2s/api-harmonization/utils/date';
44

5-
import { CMS } from '../../models';
5+
import { CMS, Resources } from '../../models';
66

7-
import { Service, ServiceListBlock, ServiceWithProduct, ServicesList } from './service-list.model';
7+
import { Service, ServiceListBlock } from './service-list.model';
88

99
export const mapServiceList = (
10-
services: ServicesList,
10+
services: Resources.Model.Services,
1111
cms: CMS.Model.ServiceListBlock.ServiceListBlock,
1212
locale: string,
1313
timezone: string,
@@ -29,7 +29,7 @@ export const mapServiceList = (
2929
};
3030

3131
const mapService = (
32-
service: ServiceWithProduct,
32+
service: Resources.Model.Service,
3333
cms: CMS.Model.ServiceListBlock.ServiceListBlock,
3434
locale: string,
3535
timezone: string,

apps/api-harmonization/src/blocks/service-list/service-list.model.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ export class ServiceListBlock extends Block.Block {
1010
detailsLabel!: string;
1111
filters?: Models.Filters.Filters<Resources.Model.Contract & Products.Model.Product>;
1212
pagination?: Models.Pagination.Pagination;
13-
services!: Services;
13+
services!: {
14+
data: Service[];
15+
total: number;
16+
};
1417
noResults!: {
1518
title: string;
1619
description?: string;
@@ -59,9 +62,3 @@ export class Service {
5962
tags: Products.Model.Product['tags'];
6063
};
6164
}
62-
63-
export type ServiceWithProduct = Omit<Resources.Model.Service, 'productId'> & {
64-
product: Products.Model.Product;
65-
};
66-
67-
export type ServicesList = Models.Pagination.Paginated<ServiceWithProduct>;

apps/api-harmonization/src/blocks/service-list/service-list.module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DynamicModule, Module } from '@nestjs/common';
33

44
import { ApiConfig } from '@o2s/framework/modules';
55

6-
import { CMS, Products, Resources } from '../../models';
6+
import { CMS, Resources } from '../../models';
77

88
import { ServiceListController } from './service-list.controller';
99
import { ServiceListService } from './service-list.service';
@@ -13,10 +13,10 @@ export class ServiceListBlockModule {
1313
static register(_config: ApiConfig): DynamicModule {
1414
return {
1515
module: ServiceListBlockModule,
16-
providers: [ServiceListService, CMS.Service, Resources.Service, Products.Service],
16+
providers: [ServiceListService, CMS.Service, Resources.Service],
1717
controllers: [ServiceListController],
18-
exports: [ServiceListService],
1918
imports: [HttpModule],
19+
exports: [ServiceListService],
2020
};
2121
}
2222
}

0 commit comments

Comments
 (0)