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
9 changes: 9 additions & 0 deletions .changeset/breezy-humans-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@o2s/blocks.ticket-details': minor
'@o2s/blocks.ticket-summary': minor
'@o2s/blocks.ticket-recent': minor
'@o2s/blocks.ticket-list': minor
'@o2s/integrations.mocked': minor
---

feat: enhance ticket services to include authorization parameter
12 changes: 12 additions & 0 deletions .changeset/tough-aliens-throw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@o2s/blocks.notification-details': minor
'@o2s/blocks.notification-summary': minor
'@o2s/blocks.notification-list': minor
'@o2s/blocks.recommended-products': minor
'@o2s/blocks.payments-history': minor
'@o2s/blocks.payments-summary': minor
'@o2s/blocks.service-details': minor
'@o2s/integrations.mocked': minor
---

refactor: update API harmonization services to include authorization headers
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class InvoiceListController {

@Get(':id/pdf')
@Auth.Decorators.Permissions({ resource: 'invoices', actions: ['view'] })
getInvoicePdf(@Param('id') id: string, @Res() res: Response): Observable<void> {
return this.service.getInvoicePdf(id).pipe(
getInvoicePdf(@Headers() headers: AppHeaders, @Param('id') id: string, @Res() res: Response): Observable<void> {
return this.service.getInvoicePdf(id, headers).pipe(
map((pdf) => {
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', `attachment; filename="invoice-${id}.pdf"`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@ export class InvoiceListService {
) {}

getInvoiceListBlock(query: GetInvoiceListBlockQuery, headers: AppHeaders): Observable<InvoiceListBlock> {
const authorization = headers[H.Authorization];
const cms = this.cmsService.getInvoiceListBlock({ ...query, locale: headers[H.Locale] });

return forkJoin([cms]).pipe(
concatMap(([cms]) => {
return this.invoiceService
.getInvoiceList({
...(cms.initialFilters || {}),
...query,
limit: query.limit || cms.pagination?.limit || 1,
offset: query.offset || 0,
locale: headers[H.Locale],
})
.getInvoiceList(
{
...(cms.initialFilters || {}),
...query,
limit: query.limit || cms.pagination?.limit || 1,
offset: query.offset || 0,
locale: headers[H.Locale],
},
authorization,
)
.pipe(
map((invoices) => {
const result = mapInvoiceList(
Expand All @@ -42,7 +46,6 @@ export class InvoiceListService {
);

// Extract permissions using ACL service
const authorization = headers[H.Authorization];
if (authorization) {
const permissions = this.authService.canPerformActions(authorization, 'invoices', [
'view',
Expand All @@ -66,7 +69,8 @@ export class InvoiceListService {
);
}

getInvoicePdf(id: string): Observable<Buffer> {
return this.invoiceService.getInvoicePdf({ id });
getInvoicePdf(id: string, headers: AppHeaders): Observable<Buffer> {
const authorization = headers[H.Authorization];
return this.invoiceService.getInvoicePdf({ id }, authorization);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export class PaymentsHistoryService {
query: GetPaymentsHistoryBlockQuery,
headers: AppHeaders,
): Observable<PaymentsHistoryBlock> {
const authorization = headers[H.Authorization];
const cms = this.cmsService.getPaymentsHistoryBlock({ ...query, locale: headers[H.Locale] });
const invoices = this.invoiceService.getInvoiceList(query);
const invoices = this.invoiceService.getInvoiceList(query, authorization);

return forkJoin([cms, invoices]).pipe(
map(([cms, invoices]) => {
const result = mapPaymentsHistory(cms, invoices, headers[H.Locale]);
const authorization = headers[H.Authorization];

// Extract permissions using ACL service
if (authorization) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export class PaymentsSummaryService {
query: GetPaymentsSummaryBlockQuery,
headers: AppHeaders,
): Observable<PaymentsSummaryBlock> {
const authorization = headers[H.Authorization];
const cms = this.cmsService.getPaymentsSummaryBlock({ ...query, locale: headers[H.Locale] });
const invoices = this.invoiceService.getInvoiceList(query);
const invoices = this.invoiceService.getInvoiceList(query, authorization);

return forkJoin([invoices, cms]).pipe(
map(([invoices, cms]) => {
const result = mapPaymentsSummary(cms, invoices, headers[H.Locale], this.defaultCurrency);
const authorization = headers[H.Authorization];

// Extract permissions using ACL service
if (authorization) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class NotificationDetailsController {

@Post()
@Auth.Decorators.Permissions({ resource: 'notifications', actions: ['mark_read'] })
markNotificationAs(@Body() body: MarkNotificationAsBlockBody) {
return this.service.markNotificationAs(body);
markNotificationAs(@Headers() headers: AppHeaders, @Body() body: MarkNotificationAsBlockBody) {
return this.service.markNotificationAs(body, headers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ export class NotificationDetailsService {
query: GetNotificationDetailsBlockQuery,
headers: AppHeaders,
): Observable<NotificationDetailsBlock> {
const authorization = headers[H.Authorization];
const cms = this.cmsService.getNotificationDetailsBlock({ ...query, locale: headers[H.Locale] });
const notification = this.notificationService.getNotification({ ...params, locale: headers[H.Locale] });
const notification = this.notificationService.getNotification(
{ ...params, locale: headers[H.Locale] },
authorization,
);

return forkJoin([notification, cms]).pipe(
map(([notification, cms]) => {
Expand All @@ -45,7 +49,6 @@ export class NotificationDetailsService {
);

// Extract permissions using ACL service
const authorization = headers[H.Authorization];
if (authorization) {
const permissions = this.authService.canPerformActions(authorization, 'notifications', [
'view',
Expand All @@ -65,7 +68,8 @@ export class NotificationDetailsService {
);
}

markNotificationAs(body: MarkNotificationAsBlockBody): Observable<void> {
return this.notificationService.markAs(body);
markNotificationAs(body: MarkNotificationAsBlockBody, headers: AppHeaders): Observable<void> {
const authorization = headers[H.Authorization];
return this.notificationService.markAs(body, authorization);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ export class NotificationListService {
return forkJoin([cms]).pipe(
concatMap(([cms]) => {
return this.notificationService
.getNotificationList({
...(cms.initialFilters || {}),
...query,
limit: query.limit || cms.pagination?.limit || 1,
offset: query.offset || 0,
locale: headers[H.Locale],
})
.getNotificationList(
{
...(cms.initialFilters || {}),
...query,
limit: query.limit || cms.pagination?.limit || 1,
offset: query.offset || 0,
locale: headers[H.Locale],
},
authorization,
)
.pipe(
map((notifications) => {
const result = mapNotificationList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ export class NotificationSummaryService {
query: GetNotificationSummaryBlockQuery,
headers: AppHeaders,
): Observable<NotificationSummaryBlock> {
const authorization = headers[H.Authorization];
const cms = this.cmsService.getNotificationSummaryBlock({ ...query, locale: headers[H.Locale] });
const notifications = this.notificationService.getNotificationList({
limit: 1000,
offset: 0,
locale: headers[H.Locale],
});
const notifications = this.notificationService.getNotificationList(
{
limit: 1000,
offset: 0,
locale: headers[H.Locale],
},
authorization,
);

return forkJoin([notifications, cms]).pipe(
map(([notifications, cms]) => {
const result = mapNotificationSummary(cms, notifications, headers[H.Locale]);
const authorization = headers[H.Authorization];

// Extract permissions using ACL service
if (authorization) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class RecommendedProductsService {
query: GetRecommendedProductsBlockQuery,
headers: AppHeaders,
): Observable<Model.RecommendedProductsBlock> {
const authorization = headers[H.Authorization];
const locale = headers[H.Locale] || 'en';
const cmsBlock$ = this.cmsService.getRecommendedProductsBlock({
id: query.id,
Expand All @@ -30,12 +31,15 @@ export class RecommendedProductsService {
return cmsBlock$.pipe(
switchMap((cmsBlock) => {
return this.productsService
.getProductList({
basePath: cmsBlock.basePath || '',
offset: 0,
limit: 7, // Fetch 7 to have 6 after excluding current product
locale,
})
.getProductList(
{
basePath: cmsBlock.basePath || '',
offset: 0,
limit: 7, // Fetch 7 to have 6 after excluding current product
locale,
},
authorization,
)
.pipe(
map((products) => {
// Filter out excluded product and products without images
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export class ServiceDetailsService {
query: GetServiceDetailsBlockQuery,
headers: AppHeaders,
): Observable<ServiceDetailsBlock> {
const authorization = headers[H.Authorization];
const cms = this.cmsService.getServiceDetailsBlock({ ...query, locale: headers[H.Locale] });
const service = this.resourceService.getService({ ...params, locale: headers[H.Locale] });
const service = this.resourceService.getService({ ...params, locale: headers[H.Locale] }, authorization);

return forkJoin([cms, service]).pipe(
map(([cms, service]) => {
const result = mapServiceDetails(cms, service, headers[H.Locale], headers[H.ClientTimezone] || '');

// Extract permissions using ACL service
const authorization = headers[H.Authorization];
if (authorization) {
const permissions = this.authService.canPerformActions(authorization, 'services', ['view']);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ export class TicketDetailsService {
query: GetTicketDetailsBlockQuery,
headers: AppHeaders,
): Observable<TicketDetailsBlock> {
const authorization = headers[H.Authorization];
const cms = this.cmsService.getTicketDetailsBlock({ ...query, locale: headers[H.Locale] });
const ticket = this.ticketService.getTicket({ ...params, locale: headers[H.Locale] });
const ticket = this.ticketService.getTicket({ ...params, locale: headers[H.Locale] }, authorization);

return forkJoin([ticket, cms]).pipe(
map(([ticket, cms]) => {
Expand All @@ -36,7 +37,6 @@ export class TicketDetailsService {
const result = mapTicketDetails(ticket, cms, headers[H.Locale], headers[H.ClientTimezone] || '');

// Extract permissions using ACL service
const authorization = headers[H.Authorization];
if (authorization) {
const permissions = this.authService.canPerformActions(authorization, 'tickets', [
'view',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ export class TicketListService {
return forkJoin([cms]).pipe(
concatMap(([cms]) => {
return this.ticketService
.getTicketList({
...(cms.initialFilters || {}),
...query,
limit: query.limit || cms.pagination?.limit || 1,
offset: query.offset || 0,
locale: headers[H.Locale],
})
.getTicketList(
{
...(cms.initialFilters || {}),
...query,
limit: query.limit || cms.pagination?.limit || 1,
offset: query.offset || 0,
locale: headers[H.Locale],
},
authorization,
)
.pipe(
map((tickets) => {
const result = mapTicketList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class TicketRecentService {
return forkJoin([cms]).pipe(
concatMap(([cms]) => {
return this.ticketsService
.getTicketList({ ...query, limit: cms.limit, locale: headers[H.Locale] })
.getTicketList({ ...query, limit: cms.limit, locale: headers[H.Locale] }, authorization)
.pipe(
map((tickets) => {
const result = mapTicketRecent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ export class TicketSummaryService {
) {}

getTicketSummaryBlock(query: GetTicketSummaryBlockQuery, headers: AppHeaders): Observable<TicketSummaryBlock> {
const authorization = headers[H.Authorization];
const cms = this.cmsService.getTicketSummaryBlock({ ...query, locale: headers[H.Locale] });
const tickets = this.ticketService.getTicketList({
limit: 1000,
offset: 0,
locale: headers[H.Locale],
});
const tickets = this.ticketService.getTicketList(
{
limit: 1000,
offset: 0,
locale: headers[H.Locale],
},
authorization,
);

return forkJoin([tickets, cms]).pipe(
map(([tickets, cms]) => {
const result = mapTicketSummary(cms, tickets, headers[H.Locale]);
const authorization = headers[H.Authorization];

// Extract permissions using ACL service
if (authorization) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ export class InvoicesService extends Invoices.Service {
super();
}

getInvoiceList(query: Invoices.Request.GetInvoiceListQuery): Observable<Invoices.Model.Invoices> {
getInvoiceList(
query: Invoices.Request.GetInvoiceListQuery,
_authorization?: string,
): Observable<Invoices.Model.Invoices> {
return of(mapInvoices(query)).pipe(responseDelay());
}

getInvoice(params: Invoices.Request.GetInvoiceParams): Observable<Invoices.Model.Invoice> {
getInvoice(params: Invoices.Request.GetInvoiceParams, _authorization?: string): Observable<Invoices.Model.Invoice> {
return of(mapInvoice(params.id)).pipe(responseDelay());
}

getInvoicePdf(_params: Invoices.Request.GetInvoiceParams): Observable<Buffer> {
getInvoicePdf(_params: Invoices.Request.GetInvoiceParams, _authorization?: string): Observable<Buffer> {
const pdfPath = join(__dirname, 'resources', 'invoice-sample.pdf');
const pdf = readFileSync(pdfPath);
return of(pdf).pipe(responseDelay());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ export class NotificationsService extends Notifications.Service {

getNotification(
params: Notifications.Request.GetNotificationParams,
_authorization?: string,
): Observable<CustomNotifications.Notification | undefined> {
return of(mapNotification(params.id, params.locale)).pipe(responseDelay());
}

getNotificationList(
options: Notifications.Request.GetNotificationListQuery,
_authorization?: string,
): Observable<CustomNotifications.Notifications> {
return of(mapNotifications(options)).pipe(responseDelay());
}

markAs(_request: Notifications.Request.MarkNotificationAsRequest): Observable<void> {
markAs(_request: Notifications.Request.MarkNotificationAsRequest, _authorization?: string): Observable<void> {
throw new NotImplementedException('The method is not implemented');
}
}
Loading
Loading