All files / src/app/extensions/order-templates/store/order-template order-template.selectors.ts

87.5% Statements 21/24
25% Branches 1/4
70% Functions 7/10
93.75% Lines 15/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 3612x   12x   12x   12x   12x 31x     12x   12x   13x   12x   12x   12x     2x     12x           12x  
import { createSelector } from '@ngrx/store';
 
import { getProductEntities } from 'ish-core/store/shopping/products';
 
import { getOrderTemplatesState } from '../order-templates-store';
 
import { initialState, orderTemplateAdapter } from './order-template.reducer';
 
const getOrderTemplateState = createSelector(getOrderTemplatesState, state =>
  state ? state.orderTemplates : initialState
);
 
const { selectEntities, selectAll } = orderTemplateAdapter.getSelectors(getOrderTemplateState);
 
export const getAllOrderTemplates = selectAll;
 
export const getOrderTemplateLoading = createSelector(getOrderTemplateState, state => state.loading);
 
export const getOrderTemplateError = createSelector(getOrderTemplateState, state => state.error);
 
export const getSelectedOrderTemplateId = createSelector(getOrderTemplateState, state => state.selected);
 
export const getSelectedOrderTemplateDetails = createSelector(
  selectEntities,
  getSelectedOrderTemplateId,
  (entities, id) => entities[id]
);
 
export const getSelectedOrderTemplateOutOfStockItems = createSelector(
  getSelectedOrderTemplateDetails,
  getProductEntities,
  (template, products) => template?.items?.map(i => i.sku)?.filter(sku => products[sku] && !products[sku].available)
);
 
export const getOrderTemplateDetails = (id: string) => createSelector(selectEntities, entities => entities[id]);